From 675fe7d4c5dc4bd4d0968107d3f459fcf2156df7 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Thu, 27 Aug 2015 17:17:42 +0300 Subject: [PATCH] cql3: Move cf_prop_defs implementation to source file Signed-off-by: Pekka Enberg --- cql3/statements/cf_prop_defs.cc | 156 ++++++++++++++++++++++++++++++++ cql3/statements/cf_prop_defs.hh | 156 +------------------------------- 2 files changed, 161 insertions(+), 151 deletions(-) diff --git a/cql3/statements/cf_prop_defs.cc b/cql3/statements/cf_prop_defs.cc index afc580af2b..3226ebfa24 100644 --- a/cql3/statements/cf_prop_defs.cc +++ b/cql3/statements/cf_prop_defs.cc @@ -47,6 +47,162 @@ const sstring cf_prop_defs::KW_COMPRESSION = "compression"; const sstring cf_prop_defs::COMPACTION_STRATEGY_CLASS_KEY = "class"; +void cf_prop_defs::validate() { + // Skip validation if the comapction strategy class is already set as it means we've alreayd + // prepared (and redoing it would set strategyClass back to null, which we don't want) + if (_compaction_strategy_class) { + return; + } + + static std::set keywords({ + KW_COMMENT, KW_READREPAIRCHANCE, KW_DCLOCALREADREPAIRCHANCE, + KW_GCGRACESECONDS, KW_CACHING, KW_DEFAULT_TIME_TO_LIVE, + KW_MIN_INDEX_INTERVAL, KW_MAX_INDEX_INTERVAL, KW_SPECULATIVE_RETRY, + KW_BF_FP_CHANCE, KW_MEMTABLE_FLUSH_PERIOD, KW_COMPACTION, + KW_COMPRESSION, + }); + static std::set obsolete_keywords({ + sstring("index_interval"), + sstring("replicate_on_write"), + sstring("populate_io_cache_on_flush"), + }); + property_definitions::validate(keywords, obsolete_keywords); + + auto compaction_options = get_compaction_options(); + if (!compaction_options.empty()) { + auto strategy = compaction_options.find(COMPACTION_STRATEGY_CLASS_KEY); + if (strategy == compaction_options.end()) { + throw exceptions::configuration_exception(sstring("Missing sub-option '") + COMPACTION_STRATEGY_CLASS_KEY + "' for the '" + KW_COMPACTION + "' option."); + } + _compaction_strategy_class = sstables::compaction_strategy::type(strategy->second); +#if 0 + compactionOptions.remove(COMPACTION_STRATEGY_CLASS_KEY); + + CFMetaData.validateCompactionOptions(compactionStrategyClass, compactionOptions); +#endif + } + + auto compression_options = get_compression_options(); + if (!compression_options.empty()) { + auto sstable_compression_class = compression_options.find(sstring(compression_parameters::SSTABLE_COMPRESSION)); + if (sstable_compression_class == compression_options.end()) { + throw exceptions::configuration_exception(sstring("Missing sub-option '") + compression_parameters::SSTABLE_COMPRESSION + "' for the '" + KW_COMPRESSION + "' option."); + } + compression_parameters cp(compression_options); + cp.validate(); + } + + validate_minimum_int(KW_DEFAULT_TIME_TO_LIVE, 0, DEFAULT_DEFAULT_TIME_TO_LIVE); + + auto min_index_interval = get_int(KW_MIN_INDEX_INTERVAL, DEFAULT_MIN_INDEX_INTERVAL); + auto max_index_interval = get_int(KW_MAX_INDEX_INTERVAL, DEFAULT_MAX_INDEX_INTERVAL); + if (min_index_interval < 1) { + throw exceptions::configuration_exception(KW_MIN_INDEX_INTERVAL + " must be greater than 0"); + } + if (max_index_interval < min_index_interval) { + throw exceptions::configuration_exception(KW_MAX_INDEX_INTERVAL + " must be greater than " + KW_MIN_INDEX_INTERVAL); + } + + speculative_retry::from_sstring(get_string(KW_SPECULATIVE_RETRY, speculative_retry(speculative_retry::type::NONE, 0).to_sstring())); +} + +std::map cf_prop_defs::get_compaction_options() const { + auto compaction_options = get_map(KW_COMPACTION); + if (compaction_options ) { + return compaction_options.value(); + } + return std::map{}; +} + +std::map cf_prop_defs::get_compression_options() const { + auto compression_options = get_map(KW_COMPRESSION); + if (compression_options) { + return compression_options.value(); + } + return std::map{}; +} + +void cf_prop_defs::apply_to_builder(schema_builder& builder) { + 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); + + builder.set_default_time_to_live(gc_clock::duration(get_int(KW_DEFAULT_TIME_TO_LIVE, DEFAULT_DEFAULT_TIME_TO_LIVE))); + + if (has_property(KW_SPECULATIVE_RETRY)) { + builder.set_speculative_retry(get_string(KW_SPECULATIVE_RETRY, builder.get_speculative_retry().to_sstring())); + } + + if (has_property(KW_MEMTABLE_FLUSH_PERIOD)) { + builder.set_memtable_flush_period(get_int(KW_MEMTABLE_FLUSH_PERIOD, builder.get_memtable_flush_period())); + } + + 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 (_compaction_strategy_class) { + builder.set_compaction_strategy(*_compaction_strategy_class); + builder.set_compaction_strategy_options(get_compaction_options()); + } + + builder.set_bloom_filter_fp_chance(get_double(KW_BF_FP_CHANCE, builder.get_bloom_filter_fp_chance())); + if (!get_compression_options().empty()) { + builder.set_compressor_params(compression_parameters(get_compression_options())); + } +#if 0 + CachingOptions cachingOptions = getCachingOptions(); + if (cachingOptions != null) + cfm.caching(cachingOptions); +#endif +} + +void cf_prop_defs::validate_minimum_int(const sstring& field, int32_t minimum_value, int32_t default_value) const +{ + auto val = get_int(field, default_value); + if (val < minimum_value) { + throw exceptions::configuration_exception(sprint("%s cannot be smaller than %s, (default %s)", + field, minimum_value, default_value)); + } +} + } } diff --git a/cql3/statements/cf_prop_defs.hh b/cql3/statements/cf_prop_defs.hh index 02a86bce3b..5d53cefe10 100644 --- a/cql3/statements/cf_prop_defs.hh +++ b/cql3/statements/cf_prop_defs.hh @@ -63,64 +63,7 @@ public: private: std::experimental::optional _compaction_strategy_class; public: - void validate() { - // Skip validation if the comapction strategy class is already set as it means we've alreayd - // prepared (and redoing it would set strategyClass back to null, which we don't want) - if (_compaction_strategy_class) { - return; - } - - static std::set keywords({ - KW_COMMENT, KW_READREPAIRCHANCE, KW_DCLOCALREADREPAIRCHANCE, - KW_GCGRACESECONDS, KW_CACHING, KW_DEFAULT_TIME_TO_LIVE, - KW_MIN_INDEX_INTERVAL, KW_MAX_INDEX_INTERVAL, KW_SPECULATIVE_RETRY, - KW_BF_FP_CHANCE, KW_MEMTABLE_FLUSH_PERIOD, KW_COMPACTION, - KW_COMPRESSION, - }); - static std::set obsolete_keywords({ - sstring("index_interval"), - sstring("replicate_on_write"), - sstring("populate_io_cache_on_flush"), - }); - property_definitions::validate(keywords, obsolete_keywords); - - auto compaction_options = get_compaction_options(); - if (!compaction_options.empty()) { - auto strategy = compaction_options.find(COMPACTION_STRATEGY_CLASS_KEY); - if (strategy == compaction_options.end()) { - throw exceptions::configuration_exception(sstring("Missing sub-option '") + COMPACTION_STRATEGY_CLASS_KEY + "' for the '" + KW_COMPACTION + "' option."); - } - _compaction_strategy_class = sstables::compaction_strategy::type(strategy->second); -#if 0 - compactionOptions.remove(COMPACTION_STRATEGY_CLASS_KEY); - - CFMetaData.validateCompactionOptions(compactionStrategyClass, compactionOptions); -#endif - } - - auto compression_options = get_compression_options(); - if (!compression_options.empty()) { - auto sstable_compression_class = compression_options.find(sstring(compression_parameters::SSTABLE_COMPRESSION)); - if (sstable_compression_class == compression_options.end()) { - throw exceptions::configuration_exception(sstring("Missing sub-option '") + compression_parameters::SSTABLE_COMPRESSION + "' for the '" + KW_COMPRESSION + "' option."); - } - compression_parameters cp(compression_options); - cp.validate(); - } - - validate_minimum_int(KW_DEFAULT_TIME_TO_LIVE, 0, DEFAULT_DEFAULT_TIME_TO_LIVE); - - auto min_index_interval = get_int(KW_MIN_INDEX_INTERVAL, DEFAULT_MIN_INDEX_INTERVAL); - auto max_index_interval = get_int(KW_MAX_INDEX_INTERVAL, DEFAULT_MAX_INDEX_INTERVAL); - if (min_index_interval < 1) { - throw exceptions::configuration_exception(KW_MIN_INDEX_INTERVAL + " must be greater than 0"); - } - if (max_index_interval < min_index_interval) { - throw exceptions::configuration_exception(KW_MAX_INDEX_INTERVAL + " must be greater than " + KW_MIN_INDEX_INTERVAL); - } - - speculative_retry::from_sstring(get_string(KW_SPECULATIVE_RETRY, speculative_retry(speculative_retry::type::NONE, 0).to_sstring())); - } + void validate(); #if 0 public Class getCompactionStrategy() @@ -128,20 +71,8 @@ public: return compactionStrategyClass; } #endif - std::map get_compaction_options() const { - auto compaction_options = get_map(KW_COMPACTION); - if (compaction_options ) { - return compaction_options.value(); - } - return std::map{}; - } - std::map get_compression_options() const { - auto compression_options = get_map(KW_COMPRESSION); - if (compression_options) { - return compression_options.value(); - } - return std::map{}; - } + std::map get_compaction_options() const; + std::map get_compression_options() const; #if 0 public CachingOptions getCachingOptions() throws SyntaxException, ConfigurationException { @@ -160,77 +91,7 @@ public: } #endif - void apply_to_builder(schema_builder& builder) { - 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); - - builder.set_default_time_to_live(gc_clock::duration(get_int(KW_DEFAULT_TIME_TO_LIVE, DEFAULT_DEFAULT_TIME_TO_LIVE))); - - if (has_property(KW_SPECULATIVE_RETRY)) { - builder.set_speculative_retry(get_string(KW_SPECULATIVE_RETRY, builder.get_speculative_retry().to_sstring())); - } - - if (has_property(KW_MEMTABLE_FLUSH_PERIOD)) { - builder.set_memtable_flush_period(get_int(KW_MEMTABLE_FLUSH_PERIOD, builder.get_memtable_flush_period())); - } - - 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 (_compaction_strategy_class) { - builder.set_compaction_strategy(*_compaction_strategy_class); - builder.set_compaction_strategy_options(get_compaction_options()); - } - - builder.set_bloom_filter_fp_chance(get_double(KW_BF_FP_CHANCE, builder.get_bloom_filter_fp_chance())); - if (!get_compression_options().empty()) { - builder.set_compressor_params(compression_parameters(get_compression_options())); - } -#if 0 - CachingOptions cachingOptions = getCachingOptions(); - if (cachingOptions != null) - cfm.caching(cachingOptions); -#endif - } + void apply_to_builder(schema_builder& builder); #if 0 @Override @@ -239,14 +100,7 @@ public: return String.format("CFPropDefs(%s)", properties.toString()); } #endif - void validate_minimum_int(const sstring& field, int32_t minimum_value, int32_t default_value) const - { - auto val = get_int(field, default_value); - if (val < minimum_value) { - throw exceptions::configuration_exception(sprint("%s cannot be smaller than %s, (default %s)", - field, minimum_value, default_value)); - } - } + void validate_minimum_int(const sstring& field, int32_t minimum_value, int32_t default_value) const; }; }