test/lib/simple_schema: add ctor for customizing ks.cf

some low level tests, like the ones exercising sstables, creates
multiple tables. and we are going to add per-table metrics and
the new metrics uses the ks.cf as part of its unique id. so,
once the per-table metrics is enabled, the sstable tests would fail.
as the metrics subsystem does not allow registering multiple
metric groups with the same name.

so, in this change, we add a new constructor for `simple_schema`,
so that we can customize the the schema's ks and cf when creating
the `simple_schema`. in the next commit, we will use this new
constructor in a sstable test which creates multiple tables.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
This commit is contained in:
Kefu Chai
2023-07-21 18:54:09 +08:00
parent 306439d3aa
commit 1f596e4669

View File

@@ -27,6 +27,11 @@
//
// CREATE TABLE ks.cf (pk text, ck text, v text, s1 text static, PRIMARY KEY (pk, ck));
//
// or
//
// CREATE TABLE ${ks}.${cf} (pk text, ck text, v text, s1 text static, PRIMARY KEY (pk, ck));
//
// where ks and cf are specified by the contructor.
class simple_schema {
public:
using with_static = bool_class<class static_tag>;
@@ -57,6 +62,22 @@ private:
static auto get_collection_type() {
return map_type_impl::get_instance(utf8_type, utf8_type, true);
}
simple_schema(std::string_view ks_name, std::string_view cf_name,
with_static ws, with_collection wc)
: _ws(ws)
, _wc(wc)
{
auto sb = schema_builder(ks_name, cf_name)
.with_column("pk", utf8_type, column_kind::partition_key)
.with_column("ck", utf8_type, column_kind::clustering_key)
.with_column("s1", utf8_type, ws ? column_kind::static_column : column_kind::regular_column)
.with_column("v", utf8_type);
if (wc) {
sb.with_column("c1", get_collection_type());
}
_s = sb.build();
}
public:
api::timestamp_type current_timestamp() {
return _timestamp;
@@ -69,19 +90,10 @@ public:
}
public:
simple_schema(with_static ws = with_static::yes, with_collection wc = with_collection::no)
: _ws(ws)
, _wc(wc)
{
auto sb = schema_builder("ks", "cf")
.with_column("pk", utf8_type, column_kind::partition_key)
.with_column("ck", utf8_type, column_kind::clustering_key)
.with_column("s1", utf8_type, ws ? column_kind::static_column : column_kind::regular_column)
.with_column("v", utf8_type);
if (wc) {
sb.with_column("c1", get_collection_type());
}
_s = sb.build();
}
: simple_schema("ks", "cf", ws, wc) {}
simple_schema(std::string_view ks_name, std::string_view cf_name)
: simple_schema(ks_name, cf_name, with_static::yes, with_collection::no) {}
sstring cql() const {
return format("CREATE TABLE {}.{} (pk text, ck text, v text, s1 text{}{}, PRIMARY KEY (pk, ck))",