diff --git a/cql3/statements/cf_prop_defs.hh b/cql3/statements/cf_prop_defs.hh index 3843e57f27..4be276fbfe 100644 --- a/cql3/statements/cf_prop_defs.hh +++ b/cql3/statements/cf_prop_defs.hh @@ -165,22 +165,54 @@ public: if (has_property(KW_COMMENT)) { builder.set_comment(get_string(KW_COMMENT, "")); } + + if (has_property(KW_READREPAIRCHANCE)) { + builder.set_read_repair_chance(get_double(KW_READREPAIRCHANCE, builder.get_read_repair_chance())); + } + + if (has_property(KW_DCLOCALREADREPAIRCHANCE)) { + builder.set_dc_local_read_repair_chance(get_double(KW_DCLOCALREADREPAIRCHANCE, builder.get_dc_local_read_repair_chance())); + } + + if (has_property(KW_GCGRACESECONDS)) { + builder.set_gc_grace_seconds(get_int(KW_GCGRACESECONDS, builder.get_gc_grace_seconds())); + } + + std::experimental::optional tmp_value = {}; + if (has_property(KW_MINCOMPACTIONTHRESHOLD)) { + if (get_compaction_options().count(KW_MINCOMPACTIONTHRESHOLD)) { + tmp_value = get_compaction_options().at(KW_MINCOMPACTIONTHRESHOLD); + } + } + int min_compaction_threshold = to_int(KW_MINCOMPACTIONTHRESHOLD, tmp_value, builder.get_min_compaction_threshold()); + + tmp_value = {}; + if (has_property(KW_MAXCOMPACTIONTHRESHOLD)) { + if (get_compaction_options().count(KW_MAXCOMPACTIONTHRESHOLD)) { + tmp_value = get_compaction_options().at(KW_MAXCOMPACTIONTHRESHOLD); + } + } + int max_compaction_threshold = to_int(KW_MAXCOMPACTIONTHRESHOLD, tmp_value, builder.get_max_compaction_threshold()); + + if (min_compaction_threshold <= 0 || max_compaction_threshold <= 0) + throw exceptions::configuration_exception("Disabling compaction by setting compaction thresholds to 0 has been deprecated, set the compaction option 'enabled' to false instead."); + builder.set_min_compaction_threshold(min_compaction_threshold); + builder.set_max_compaction_threshold(max_compaction_threshold); + #if 0 - cfm.readRepairChance(getDouble(KW_READREPAIRCHANCE, cfm.getReadRepairChance())); - cfm.dcLocalReadRepairChance(getDouble(KW_DCLOCALREADREPAIRCHANCE, cfm.getDcLocalReadRepairChance())); - cfm.gcGraceSeconds(getInt(KW_GCGRACESECONDS, cfm.getGcGraceSeconds())); - int minCompactionThreshold = toInt(KW_MINCOMPACTIONTHRESHOLD, getCompactionOptions().get(KW_MINCOMPACTIONTHRESHOLD), cfm.getMinCompactionThreshold()); - int maxCompactionThreshold = toInt(KW_MAXCOMPACTIONTHRESHOLD, getCompactionOptions().get(KW_MAXCOMPACTIONTHRESHOLD), cfm.getMaxCompactionThreshold()); - if (minCompactionThreshold <= 0 || maxCompactionThreshold <= 0) - throw new ConfigurationException("Disabling compaction by setting compaction thresholds to 0 has been deprecated, set the compaction option 'enabled' to false instead."); - cfm.minCompactionThreshold(minCompactionThreshold); - cfm.maxCompactionThreshold(maxCompactionThreshold); cfm.defaultTimeToLive(getInt(KW_DEFAULT_TIME_TO_LIVE, cfm.getDefaultTimeToLive())); cfm.speculativeRetry(CFMetaData.SpeculativeRetry.fromString(getString(KW_SPECULATIVE_RETRY, cfm.getSpeculativeRetry().toString()))); cfm.memtableFlushPeriod(getInt(KW_MEMTABLE_FLUSH_PERIOD, cfm.getMemtableFlushPeriod())); - cfm.minIndexInterval(getInt(KW_MIN_INDEX_INTERVAL, cfm.getMinIndexInterval())); - cfm.maxIndexInterval(getInt(KW_MAX_INDEX_INTERVAL, cfm.getMaxIndexInterval())); +#endif + if (has_property(KW_MIN_INDEX_INTERVAL)) { + builder.set_min_index_interval(get_int(KW_MIN_INDEX_INTERVAL, builder.get_min_index_interval())); + } + if (has_property(KW_MAX_INDEX_INTERVAL)) { + builder.set_max_index_interval(get_int(KW_MAX_INDEX_INTERVAL, builder.get_max_index_interval())); + } + +#if 0 if (compactionStrategyClass != null) { cfm.compactionStrategyClass(compactionStrategyClass); diff --git a/db/legacy_schema_tables.cc b/db/legacy_schema_tables.cc index 6ba5ce8382..0a82e9a1a2 100644 --- a/db/legacy_schema_tables.cc +++ b/db/legacy_schema_tables.cc @@ -1001,25 +1001,20 @@ future<> save_system_keyspace_schema() { mutation m{pkey, s}; auto ckey = clustering_key::from_single_value(*s, to_bytes(table->cf_name())); m.set_clustered_cell(ckey, "cf_id", table->id(), timestamp); + m.set_clustered_cell(ckey, "type", cf_type_to_sstring(table->type()), timestamp); + + if (table->is_super()) { + warn(unimplemented::cause::SUPER); #if 0 - m.set_clustered_cell(ckey, "type", table.cfType.toString(), timestamp); -#endif -#if 0 - if (table.isSuper()) - { // We need to continue saving the comparator and subcomparator separatly, otherwise // we won't know at deserialization if the subcomparator should be taken into account // TODO: we should implement an on-start migration if we want to get rid of that. adder.add("comparator", table.comparator.subtype(0).toString()); adder.add("subcomparator", table.comparator.subtype(1).toString()); - } - else - { #endif + } else { m.set_clustered_cell(ckey, "comparator", table->regular_column_name_type()->name(), timestamp); -#if 0 } -#endif m.set_clustered_cell(ckey, "bloom_filter_fp_chance", table->bloom_filter_fp_chance(), timestamp); #if 0 @@ -1034,18 +1029,18 @@ future<> save_system_keyspace_schema() { m.set_clustered_cell(ckey, "compression_parameters", json::to_json(compression_options.get_options()), timestamp); m.set_clustered_cell(ckey, "default_time_to_live", table->default_time_to_live().count(), timestamp); m.set_clustered_cell(ckey, "default_validator", table->default_validator()->name(), timestamp); -#if 0 - adder.add("gc_grace_seconds", table.getGcGraceSeconds()); -#endif + m.set_clustered_cell(ckey, "gc_grace_seconds", table->gc_grace_seconds(), timestamp); m.set_clustered_cell(ckey, "key_validator", table->thrift_key_validator(), timestamp); + m.set_clustered_cell(ckey, "local_read_repair_chance", table->dc_local_read_repair_chance(), timestamp); + m.set_clustered_cell(ckey, "min_compaction_threshold", table->min_compaction_threshold(), timestamp); + m.set_clustered_cell(ckey, "max_compaction_threshold", table->max_compaction_threshold(), timestamp); + m.set_clustered_cell(ckey, "min_index_interval", table->min_index_interval(), timestamp); + m.set_clustered_cell(ckey, "max_index_interval", table->max_index_interval(), timestamp); #if 0 - adder.add("local_read_repair_chance", table.getDcLocalReadRepairChance()); - adder.add("max_compaction_threshold", table.getMaxCompactionThreshold()); - adder.add("max_index_interval", table.getMaxIndexInterval()); adder.add("memtable_flush_period_in_ms", table.getMemtableFlushPeriod()); - adder.add("min_compaction_threshold", table.getMinCompactionThreshold()); - adder.add("min_index_interval", table.getMinIndexInterval()); - adder.add("read_repair_chance", table.getReadRepairChance()); +#endif + m.set_clustered_cell(ckey, "read_repair_chance", table->read_repair_chance(), timestamp); +#if 0 adder.add("speculative_retry", table.getSpeculativeRetry().toString()); for (Map.Entry entry : table.getDroppedColumns().entrySet()) @@ -1225,16 +1220,24 @@ future<> save_system_keyspace_schema() { #if 0 AbstractType rawComparator = TypeParser.parse(result.getString("comparator")); AbstractType subComparator = result.has("subcomparator") ? TypeParser.parse(result.getString("subcomparator")) : null; - ColumnFamilyType cfType = ColumnFamilyType.valueOf(result.getString("type")); +#endif + cf_type cf = cf_type::standard; + if (table_row.has("type")) { + cf = sstring_to_cf_type(table_row.get_nonnull("type")); + if (cf == cf_type::super) { + fail(unimplemented::cause::SUPER); + } + } +#if 0 AbstractType fullRawComparator = CFMetaData.makeRawAbstractType(rawComparator, subComparator); #endif std::vector column_defs = create_columns_from_column_rows(serialized_column_definitions, ks_name, - cf_name/*, - fullRawComparator, - cfType == ColumnFamilyType.Super*/); + cf_name,/*, + fullRawComparator, */ + cf == cf_type::super); bool is_dense; if (table_row.has("is_dense")) { @@ -1257,18 +1260,31 @@ future<> save_system_keyspace_schema() { #endif builder.set_is_dense(is_dense); -#if 0 - cfm.readRepairChance(result.getDouble("read_repair_chance")); - cfm.dcLocalReadRepairChance(result.getDouble("local_read_repair_chance")); - cfm.gcGraceSeconds(result.getInt("gc_grace_seconds")); -#endif + if (table_row.has("read_repair_chance")) { + builder.set_read_repair_chance(table_row.get_nonnull("read_repair_chance")); + } + + if (table_row.has("local_read_repair_chance")) { + builder.set_dc_local_read_repair_chance(table_row.get_nonnull("local_read_repair_chance")); + } + + if (table_row.has("gc_grace_seconds")) { + builder.set_gc_grace_seconds(table_row.get_nonnull("gc_grace_seconds")); + } + if (table_row.has("default_validator")) { builder.set_default_validator(parse_type(table_row.get_nonnull("default_validator"))); } + if (table_row.has("min_compaction_threshold")) { + builder.set_min_compaction_threshold(table_row.get_nonnull("min_compaction_threshold")); + } + + if (table_row.has("max_compaction_threshold")) { + builder.set_max_compaction_threshold(table_row.get_nonnull("max_compaction_threshold")); + } + #if 0 - cfm.minCompactionThreshold(result.getInt("min_compaction_threshold")); - cfm.maxCompactionThreshold(result.getInt("max_compaction_threshold")); if (result.has("comment")) cfm.comment(result.getString("comment")); if (result.has("memtable_flush_period_in_ms")) @@ -1285,14 +1301,16 @@ future<> save_system_keyspace_schema() { builder.set_compressor_params(cp); #if 0 cfm.compactionStrategyOptions(fromJsonMap(result.getString("compaction_strategy_options"))); - - if (result.has("min_index_interval")) - cfm.minIndexInterval(result.getInt("min_index_interval")); - - if (result.has("max_index_interval")) - cfm.maxIndexInterval(result.getInt("max_index_interval")); #endif + if (table_row.has("min_index_interval")) { + builder.set_min_index_interval(table_row.get_nonnull("min_index_interval")); + } + + if (table_row.has("max_index_interval")) { + builder.set_max_index_interval(table_row.get_nonnull("max_index_interval")); + } + if (table_row.has("bloom_filter_fp_chance")) { builder.set_bloom_filter_fp_chance(table_row.get_nonnull("bloom_filter_fp_chance")); } else { @@ -1383,22 +1401,22 @@ future<> save_system_keyspace_schema() { std::vector create_columns_from_column_rows(const schema_result::mapped_type& rows, const sstring& keyspace, - const sstring& table/*, - AbstractType rawComparator, - boolean isSuper*/) + const sstring& table, /*, + AbstractType rawComparator, */ + bool is_super) { std::vector columns; for (auto&& row : rows->rows()) { - columns.emplace_back(std::move(create_column_from_column_row(row, keyspace, table/*, rawComparator, isSuper*/))); + columns.emplace_back(std::move(create_column_from_column_row(row, keyspace, table, /*, rawComparator, */ is_super))); } return columns; } column_definition create_column_from_column_row(const query::result_set_row& row, sstring keyspace, - sstring table/*, - AbstractType rawComparator, - boolean isSuper*/) + sstring table, /*, + AbstractType rawComparator, */ + bool is_super) { auto kind = deserialize_kind(row.get_nonnull("type")); diff --git a/db/legacy_schema_tables.hh b/db/legacy_schema_tables.hh index bc81ddc46c..c83074f9d7 100644 --- a/db/legacy_schema_tables.hh +++ b/db/legacy_schema_tables.hh @@ -85,15 +85,15 @@ void create_table_from_table_row_and_column_rows(schema_builder& builder, const std::vector create_columns_from_column_rows(const schema_result::mapped_type& rows, const sstring& keyspace, - const sstring& table/*, - AbstractType rawComparator, - boolean isSuper*/); + const sstring& table,/*, + AbstractType rawComparator, */ + bool is_super); column_definition create_column_from_column_row(const query::result_set_row& row, sstring keyspace, - sstring table/*, - AbstractType rawComparator, - boolean isSuper*/); + sstring table, /*, + AbstractType rawComparator, */ + bool is_super); void add_column_to_schema_mutation(schema_ptr table, const column_definition& column, api::timestamp_type timestamp, const partition_key& pkey, std::vector& mutations); diff --git a/schema.hh b/schema.hh index 0d92b2fb2d..23fe65b915 100644 --- a/schema.hh +++ b/schema.hh @@ -31,6 +31,29 @@ enum class index_type { none, // cwi: added none to avoid "optional" bs. }; +enum class cf_type : uint8_t { + standard, + super, +}; + +inline sstring cf_type_to_sstring(cf_type t) { + if (t == cf_type::standard) { + return "Standard"; + } else if (t == cf_type::super) { + return "Super"; + } + throw std::invalid_argument(sprint("unknown type: %d\n", uint8_t(t))); +} + +inline cf_type sstring_to_cf_type(sstring name) { + if (name == "Standard") { + return cf_type::standard; + } else if (name == "Super") { + return cf_type::super; + } + throw std::invalid_argument(sprint("unknown type: %s\n", name)); +} + typedef std::unordered_map index_options_map; class schema; @@ -149,6 +172,14 @@ private: double _bloom_filter_fp_chance = 0.01; compression_parameters _compressor_params; bool _is_dense = false; + cf_type _type = cf_type::standard; + int32_t _gc_grace_seconds = 864000; + double _dc_local_read_repair_chance = 0.1; + double _read_repair_chance = 0.0; + int32_t _min_compaction_threshold = 4; + int32_t _max_compaction_threshold = 32; + int32_t _min_index_interval = 128; + int32_t _max_index_interval = 2048; }; raw_schema _raw; thrift_schema _thrift; @@ -235,6 +266,43 @@ public: bool is_counter() const { return false; } + + const cf_type type() const { + return _raw._type; + } + + bool is_super() const { + return _raw._type == cf_type::super; + } + + int32_t gc_grace_seconds() const { + return _raw._gc_grace_seconds; + } + + double dc_local_read_repair_chance() const { + return _raw._dc_local_read_repair_chance; + } + + double read_repair_chance() const { + return _raw._read_repair_chance; + } + + int32_t min_compaction_threshold() const { + return _raw._min_compaction_threshold; + } + + int32_t max_compaction_threshold() const { + return _raw._max_compaction_threshold; + } + + int32_t min_index_interval() const { + return _raw._min_index_interval; + } + + int32_t max_index_interval() const { + return _raw._max_index_interval; + } + const column_definition* get_column_definition(const bytes& name) const; const_iterator regular_begin() const { return regular_columns().begin(); diff --git a/schema_builder.hh b/schema_builder.hh index 6711b396f6..ac3b2953b8 100644 --- a/schema_builder.hh +++ b/schema_builder.hh @@ -52,6 +52,62 @@ public: _raw._default_validator = validator; } + void set_gc_grace_seconds(int32_t gc_grace_seconds) { + _raw._gc_grace_seconds = gc_grace_seconds; + } + + int32_t get_gc_grace_seconds() { + return _raw._gc_grace_seconds; + } + + void set_dc_local_read_repair_chance(double chance) { + _raw._dc_local_read_repair_chance = chance; + } + + double get_dc_local_read_repair_chance() { + return _raw._dc_local_read_repair_chance; + } + + void set_read_repair_chance(double chance) { + _raw._read_repair_chance = chance; + } + + double get_read_repair_chance() { + return _raw._read_repair_chance; + } + + void set_min_compaction_threshold(int32_t t) { + _raw._min_compaction_threshold = t; + } + + int32_t get_min_compaction_threshold() { + return _raw._min_compaction_threshold; + } + + void set_max_compaction_threshold(int32_t t) { + _raw._max_compaction_threshold = t; + } + + int32_t get_max_compaction_threshold() { + return _raw._max_compaction_threshold; + } + + void set_min_index_interval(int32_t t) { + _raw._min_index_interval = t; + } + + int32_t get_min_index_interval() { + return _raw._min_index_interval; + } + + void set_max_index_interval(int32_t t) { + _raw._max_index_interval = t; + } + + int32_t get_max_index_interval() { + return _raw._max_index_interval; + } + void set_bloom_filter_fp_chance(double fp) { _raw._bloom_filter_fp_chance = fp; } diff --git a/unimplemented.cc b/unimplemented.cc index 2454db096d..83b0ec869b 100644 --- a/unimplemented.cc +++ b/unimplemented.cc @@ -36,6 +36,7 @@ std::ostream& operator<<(std::ostream& out, cause c) { case cause::NONATOMIC: return out << "NONATOMIC"; case cause::CONSISTENCY: return out << "CONSISTENCY"; case cause::HINT: return out << "HINT"; + case cause::SUPER: return out << "SUPER"; } assert(0); } diff --git a/unimplemented.hh b/unimplemented.hh index c7d0aeeb70..c707d41666 100644 --- a/unimplemented.hh +++ b/unimplemented.hh @@ -35,6 +35,7 @@ enum class cause { NONATOMIC, CONSISTENCY, HINT, + SUPER, }; void fail(cause what) __attribute__((noreturn));