mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-25 19:10:42 +00:00
Merge "Remove all set functions from the schema" from Glauber
"In the beginning, we needed to set fields in the schema, so we had set_ functions. Then the schema_builder came, and it acquired a lot of set_ functions. Because its role is actually to build the schema, it is obvious that those functions are much better placed if they are there. In this sense, having them to stay in schema as well, is just duplication. Some of the functions were already orphans in this sense. No callers left. But some others had callers. This patchset fixes them so they build through the builder. And once this is done, schema will now consistently have getters only. This will become more pressing once I introduce the compact storage changes - which is the reason I am doing this now. For those, the process of computing the right value is a bit complicated - definitely not just val = x, and we definitely don't need the code living in two places. It would be much better if the existing users - specially the system tables, would be already fixed."
This commit is contained in:
@@ -58,7 +58,8 @@ using days = std::chrono::duration<int, std::ratio<24 * 3600>>;
|
||||
#endif
|
||||
|
||||
/* static */ schema_ptr keyspaces() {
|
||||
static thread_local auto keyspaces = make_lw_shared(schema(generate_legacy_id(NAME, KEYSPACES), NAME, KEYSPACES,
|
||||
static thread_local auto keyspaces = [] {
|
||||
schema_builder builder(make_lw_shared(schema(generate_legacy_id(NAME, KEYSPACES), NAME, KEYSPACES,
|
||||
// partition key
|
||||
{{"keyspace_name", utf8_type}},
|
||||
// clustering key
|
||||
@@ -78,13 +79,16 @@ using days = std::chrono::duration<int, std::ratio<24 * 3600>>;
|
||||
// FIXME: the original Java code also had:
|
||||
// in CQL statement creating the table:
|
||||
// "WITH COMPACT STORAGE"
|
||||
));
|
||||
keyspaces->set_gc_grace_seconds(std::chrono::duration_cast<std::chrono::seconds>(days(7)).count());
|
||||
)));
|
||||
builder.set_gc_grace_seconds(std::chrono::duration_cast<std::chrono::seconds>(days(7)).count());
|
||||
return builder.build();
|
||||
}();
|
||||
return keyspaces;
|
||||
}
|
||||
|
||||
/* static */ schema_ptr columnfamilies() {
|
||||
static thread_local auto columnfamilies = make_lw_shared(schema(generate_legacy_id(NAME, COLUMNFAMILIES), NAME, COLUMNFAMILIES,
|
||||
static thread_local auto columnfamilies = [] {
|
||||
schema_builder builder(make_lw_shared(schema(generate_legacy_id(NAME, COLUMNFAMILIES), NAME, COLUMNFAMILIES,
|
||||
// partition key
|
||||
{{"keyspace_name", utf8_type}},
|
||||
// clustering key
|
||||
@@ -122,13 +126,16 @@ using days = std::chrono::duration<int, std::ratio<24 * 3600>>;
|
||||
utf8_type,
|
||||
// comment
|
||||
"table definitions"
|
||||
));
|
||||
columnfamilies->set_gc_grace_seconds(std::chrono::duration_cast<std::chrono::seconds>(days(7)).count());
|
||||
)));
|
||||
builder.set_gc_grace_seconds(std::chrono::duration_cast<std::chrono::seconds>(days(7)).count());
|
||||
return builder.build();
|
||||
}();
|
||||
return columnfamilies;
|
||||
}
|
||||
|
||||
/* static */ schema_ptr columns() {
|
||||
static thread_local auto columns = make_lw_shared(schema(generate_legacy_id(NAME, COLUMNS), NAME, COLUMNS,
|
||||
static thread_local auto columns = [] {
|
||||
schema_builder builder(make_lw_shared(schema(generate_legacy_id(NAME, COLUMNS), NAME, COLUMNS,
|
||||
// partition key
|
||||
{{"keyspace_name", utf8_type}},
|
||||
// clustering key
|
||||
@@ -148,13 +155,16 @@ using days = std::chrono::duration<int, std::ratio<24 * 3600>>;
|
||||
utf8_type,
|
||||
// comment
|
||||
"column definitions"
|
||||
));
|
||||
columns->set_gc_grace_seconds(std::chrono::duration_cast<std::chrono::seconds>(days(7)).count());
|
||||
)));
|
||||
builder.set_gc_grace_seconds(std::chrono::duration_cast<std::chrono::seconds>(days(7)).count());
|
||||
return builder.build();
|
||||
}();
|
||||
return columns;
|
||||
}
|
||||
|
||||
/* static */ schema_ptr triggers() {
|
||||
static thread_local auto triggers = make_lw_shared(schema(generate_legacy_id(NAME, TRIGGERS), NAME, TRIGGERS,
|
||||
static thread_local auto triggers = [] {
|
||||
schema_builder builder(make_lw_shared(schema(generate_legacy_id(NAME, TRIGGERS), NAME, TRIGGERS,
|
||||
// partition key
|
||||
{{"keyspace_name", utf8_type}},
|
||||
// clustering key
|
||||
@@ -169,13 +179,16 @@ using days = std::chrono::duration<int, std::ratio<24 * 3600>>;
|
||||
utf8_type,
|
||||
// comment
|
||||
"trigger definitions"
|
||||
));
|
||||
triggers->set_gc_grace_seconds(std::chrono::duration_cast<std::chrono::seconds>(days(7)).count());
|
||||
)));
|
||||
builder.set_gc_grace_seconds(std::chrono::duration_cast<std::chrono::seconds>(days(7)).count());
|
||||
return builder.build();
|
||||
}();
|
||||
return triggers;
|
||||
}
|
||||
|
||||
/* static */ schema_ptr usertypes() {
|
||||
static thread_local auto usertypes = make_lw_shared(schema(generate_legacy_id(NAME, USERTYPES), NAME, USERTYPES,
|
||||
static thread_local auto usertypes = [] {
|
||||
schema_builder builder(make_lw_shared(schema(generate_legacy_id(NAME, USERTYPES), NAME, USERTYPES,
|
||||
// partition key
|
||||
{{"keyspace_name", utf8_type}},
|
||||
// clustering key
|
||||
@@ -191,13 +204,16 @@ using days = std::chrono::duration<int, std::ratio<24 * 3600>>;
|
||||
utf8_type,
|
||||
// comment
|
||||
"user defined type definitions"
|
||||
));
|
||||
usertypes->set_gc_grace_seconds(std::chrono::duration_cast<std::chrono::seconds>(days(7)).count());
|
||||
)));
|
||||
builder.set_gc_grace_seconds(std::chrono::duration_cast<std::chrono::seconds>(days(7)).count());
|
||||
return builder.build();
|
||||
}();
|
||||
return usertypes;
|
||||
}
|
||||
|
||||
/* static */ schema_ptr functions() {
|
||||
static thread_local auto functions = make_lw_shared(schema(generate_legacy_id(NAME, FUNCTIONS), NAME, FUNCTIONS,
|
||||
static thread_local auto functions = [] {
|
||||
schema_builder builder(make_lw_shared(schema(generate_legacy_id(NAME, FUNCTIONS), NAME, FUNCTIONS,
|
||||
// partition key
|
||||
{{"keyspace_name", utf8_type}},
|
||||
// clustering key
|
||||
@@ -217,13 +233,16 @@ using days = std::chrono::duration<int, std::ratio<24 * 3600>>;
|
||||
utf8_type,
|
||||
// comment
|
||||
"user defined type definitions"
|
||||
));
|
||||
functions->set_gc_grace_seconds(std::chrono::duration_cast<std::chrono::seconds>(days(7)).count());
|
||||
)));
|
||||
builder.set_gc_grace_seconds(std::chrono::duration_cast<std::chrono::seconds>(days(7)).count());
|
||||
return builder.build();
|
||||
}();
|
||||
return functions;
|
||||
}
|
||||
|
||||
/* static */ schema_ptr aggregates() {
|
||||
static thread_local auto aggregates = make_lw_shared(schema(generate_legacy_id(NAME, AGGREGATES), NAME, AGGREGATES,
|
||||
static thread_local auto aggregates = [] {
|
||||
schema_builder builder(make_lw_shared(schema(generate_legacy_id(NAME, AGGREGATES), NAME, AGGREGATES,
|
||||
// partition key
|
||||
{{"keyspace_name", utf8_type}},
|
||||
// clustering key
|
||||
@@ -243,8 +262,10 @@ using days = std::chrono::duration<int, std::ratio<24 * 3600>>;
|
||||
utf8_type,
|
||||
// comment
|
||||
"user defined aggregate definitions"
|
||||
));
|
||||
aggregates->set_gc_grace_seconds(std::chrono::duration_cast<std::chrono::seconds>(days(7)).count());
|
||||
)));
|
||||
builder.set_gc_grace_seconds(std::chrono::duration_cast<std::chrono::seconds>(days(7)).count());
|
||||
return builder.build();
|
||||
}();
|
||||
return aggregates;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "query_context.hh"
|
||||
#include "partition_slice_builder.hh"
|
||||
#include "db/config.hh"
|
||||
#include "schema_builder.hh"
|
||||
|
||||
using days = std::chrono::duration<int, std::ratio<24 * 3600>>;
|
||||
|
||||
@@ -62,7 +63,8 @@ namespace system_keyspace {
|
||||
// functions will solve this problem. So we use functions right now.
|
||||
|
||||
schema_ptr hints() {
|
||||
static thread_local auto hints = make_lw_shared(schema(generate_legacy_id(NAME, HINTS), NAME, HINTS,
|
||||
static thread_local auto hints = [] {
|
||||
schema_builder builder(make_lw_shared(schema(generate_legacy_id(NAME, HINTS), NAME, HINTS,
|
||||
// partition key
|
||||
{{"target_id", uuid_type}},
|
||||
// clustering key
|
||||
@@ -80,13 +82,16 @@ schema_ptr hints() {
|
||||
// "WITH COMPACT STORAGE"
|
||||
// operations on resulting CFMetaData:
|
||||
// .compactionStrategyOptions(Collections.singletonMap("enabled", "false"))
|
||||
));
|
||||
hints->set_gc_grace_seconds(0);
|
||||
)));
|
||||
builder.set_gc_grace_seconds(0);
|
||||
return builder.build();
|
||||
}();
|
||||
return hints;
|
||||
}
|
||||
|
||||
schema_ptr batchlog() {
|
||||
static thread_local auto batchlog = make_lw_shared(schema(generate_legacy_id(NAME, BATCHLOG), NAME, BATCHLOG,
|
||||
static thread_local auto batchlog = [] {
|
||||
schema_builder builder(make_lw_shared(schema(generate_legacy_id(NAME, BATCHLOG), NAME, BATCHLOG,
|
||||
// partition key
|
||||
{{"id", uuid_type}},
|
||||
// clustering key
|
||||
@@ -102,8 +107,10 @@ schema_ptr batchlog() {
|
||||
// FIXME: the original Java code also had:
|
||||
// operations on resulting CFMetaData:
|
||||
// .compactionStrategyOptions(Collections.singletonMap("min_threshold", "2"))
|
||||
));
|
||||
batchlog->set_gc_grace_seconds(0);
|
||||
)));
|
||||
builder.set_gc_grace_seconds(0);
|
||||
return builder.build();
|
||||
}();
|
||||
return batchlog;
|
||||
}
|
||||
|
||||
@@ -270,7 +277,8 @@ schema_ptr built_indexes() {
|
||||
}
|
||||
|
||||
/*static*/ schema_ptr compaction_history() {
|
||||
static thread_local auto compaction_history = make_lw_shared(schema(generate_legacy_id(NAME, COMPACTION_HISTORY), NAME, COMPACTION_HISTORY,
|
||||
static thread_local auto compaction_history = [] {
|
||||
schema_builder builder(make_lw_shared(schema(generate_legacy_id(NAME, COMPACTION_HISTORY), NAME, COMPACTION_HISTORY,
|
||||
// partition key
|
||||
{{"id", uuid_type}},
|
||||
// clustering key
|
||||
@@ -290,8 +298,10 @@ schema_ptr built_indexes() {
|
||||
utf8_type,
|
||||
// comment
|
||||
"week-long compaction history"
|
||||
));
|
||||
compaction_history->set_default_time_to_live(std::chrono::duration_cast<std::chrono::seconds>(days(7)));
|
||||
)));
|
||||
builder.set_default_time_to_live(std::chrono::duration_cast<std::chrono::seconds>(days(7)));
|
||||
return builder.build();
|
||||
}();
|
||||
return compaction_history;
|
||||
}
|
||||
|
||||
|
||||
21
schema.hh
21
schema.hh
@@ -230,14 +230,7 @@ public:
|
||||
double bloom_filter_fp_chance() const {
|
||||
return _raw._bloom_filter_fp_chance;
|
||||
}
|
||||
schema& set_bloom_filter_fp_chance(double fp) {
|
||||
_raw._bloom_filter_fp_chance = fp;
|
||||
return *this;
|
||||
}
|
||||
sstring thrift_key_validator() const;
|
||||
void set_compressor_params(compression_parameters c) {
|
||||
_raw._compressor_params = c;
|
||||
}
|
||||
const compression_parameters& get_compressor_params() const {
|
||||
return _raw._compressor_params;
|
||||
}
|
||||
@@ -256,12 +249,6 @@ public:
|
||||
const sstring& comment() const {
|
||||
return _raw._comment;
|
||||
}
|
||||
void set_comment(const sstring& comment) {
|
||||
_raw._comment = comment;
|
||||
}
|
||||
void set_id(utils::UUID new_id) {
|
||||
_raw._id = new_id;
|
||||
}
|
||||
bool is_counter() const {
|
||||
return false;
|
||||
}
|
||||
@@ -278,10 +265,6 @@ public:
|
||||
return _raw._gc_grace_seconds;
|
||||
}
|
||||
|
||||
void set_gc_grace_seconds(int32_t gc) {
|
||||
_raw._gc_grace_seconds = gc;
|
||||
}
|
||||
|
||||
double dc_local_read_repair_chance() const {
|
||||
return _raw._dc_local_read_repair_chance;
|
||||
}
|
||||
@@ -399,10 +382,6 @@ public:
|
||||
return _raw._default_time_to_live;
|
||||
}
|
||||
|
||||
void set_default_time_to_live(gc_clock::duration ttl) {
|
||||
_raw._default_time_to_live = ttl;
|
||||
}
|
||||
|
||||
const data_type& default_validator() const {
|
||||
return _raw._default_validator;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "message/messaging_service.hh"
|
||||
#include "service/storage_service.hh"
|
||||
#include "db/config.hh"
|
||||
#include "schema_builder.hh"
|
||||
|
||||
class in_memory_cql_env : public cql_test_env {
|
||||
public:
|
||||
@@ -93,8 +94,9 @@ public:
|
||||
virtual future<> create_table(std::function<schema(const sstring&)> schema_maker) override {
|
||||
auto id = utils::UUID_gen::get_time_UUID();
|
||||
return _db->invoke_on_all([schema_maker, id, this] (database& db) {
|
||||
auto cf_schema = make_lw_shared(schema_maker(ks_name));
|
||||
cf_schema->set_id(id);
|
||||
schema_builder builder(make_lw_shared(schema_maker(ks_name)));
|
||||
builder.set_uuid(id);
|
||||
auto cf_schema = builder.build();
|
||||
auto& ks = db.find_keyspace(ks_name);
|
||||
auto cfg = ks.make_column_family_config(*cf_schema);
|
||||
db.add_column_family(std::move(cf_schema), std::move(cfg));
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "sstables/compaction.hh"
|
||||
#include "tests/test-utils.hh"
|
||||
#include "schema.hh"
|
||||
#include "schema_builder.hh"
|
||||
#include "database.hh"
|
||||
#include <memory>
|
||||
#include "sstable_test.hh"
|
||||
@@ -883,10 +884,10 @@ SEASTAR_TEST_CASE(datafile_generation_12) {
|
||||
|
||||
static future<> sstable_compression_test(compressor c, unsigned generation) {
|
||||
return test_setup::do_with_test_directory([c, generation] {
|
||||
auto& cs = *complex_schema();
|
||||
auto s = make_lw_shared(schema(cs));
|
||||
// NOTE: set a given compressor algorithm to schema.
|
||||
s->set_compressor_params(c);
|
||||
schema_builder builder(complex_schema());
|
||||
builder.set_compressor_params(c);
|
||||
auto s = builder.build();
|
||||
|
||||
auto mtp = make_lw_shared<memtable>(s);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user