From 6b42d0f9b11406f20b24911e0451356d33076feb Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Thu, 27 Aug 2015 14:19:26 +0300 Subject: [PATCH 1/2] compaction_strategy: Fix type() to throw configuration exception Fix compaction_strategy::type() to throw configuration_exception which is what Origin throws from CFMetaData.createCompactionStrategy(). This ensures that the CQL error we send back to the client is the same. Signed-off-by: Pekka Enberg --- compaction_strategy.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compaction_strategy.hh b/compaction_strategy.hh index bd7df83e41..89eb14fa14 100644 --- a/compaction_strategy.hh +++ b/compaction_strategy.hh @@ -50,7 +50,7 @@ public: } else if (name == "SizeTieredCompactionStrategy") { return compaction_strategy_type::size_tiered; } else { - throw std::runtime_error("Invalid Compaction Strategy"); + throw exceptions::configuration_exception(sprint("Unable to find compaction strategy class 'org.apache.cassandra.db.compaction.%s", name)); } } }; From 5d41eadd6abf63760894b84041b68becf789d2dd Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Thu, 27 Aug 2015 14:13:38 +0300 Subject: [PATCH 2/2] cql3: Fix 'CREATE TABLE' compaction strategy support Fix cf_prop_defs::apply_to_builder() to actually apply the given compaction strategy to the schema that is being created. Fixes #192. Signed-off-by: Pekka Enberg --- cql3/statements/cf_prop_defs.hh | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/cql3/statements/cf_prop_defs.hh b/cql3/statements/cf_prop_defs.hh index 74bd7001ea..02a86bce3b 100644 --- a/cql3/statements/cf_prop_defs.hh +++ b/cql3/statements/cf_prop_defs.hh @@ -29,6 +29,7 @@ #include "schema.hh" #include "database.hh" #include "schema_builder.hh" +#include "compaction_strategy.hh" namespace cql3 { @@ -60,7 +61,7 @@ public: static constexpr int32_t DEFAULT_MIN_INDEX_INTERVAL = 128; static constexpr int32_t DEFAULT_MAX_INDEX_INTERVAL = 2048; private: - std::experimental::optional _compaction_strategy_class; + 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 @@ -89,9 +90,8 @@ public: 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 = strategy->second; + _compaction_strategy_class = sstables::compaction_strategy::type(strategy->second); #if 0 - compactionStrategyClass = CFMetaData.createCompactionStrategy(strategy); compactionOptions.remove(COMPACTION_STRATEGY_CLASS_KEY); CFMetaData.validateCompactionOptions(compactionStrategyClass, compactionOptions); @@ -216,13 +216,10 @@ public: builder.set_max_index_interval(get_int(KW_MAX_INDEX_INTERVAL, builder.get_max_index_interval())); } -#if 0 - if (compactionStrategyClass != null) - { - cfm.compactionStrategyClass(compactionStrategyClass); - cfm.compactionStrategyOptions(new HashMap<>(getCompactionOptions())); + if (_compaction_strategy_class) { + builder.set_compaction_strategy(*_compaction_strategy_class); + builder.set_compaction_strategy_options(get_compaction_options()); } -#endif builder.set_bloom_filter_fp_chance(get_double(KW_BF_FP_CHANCE, builder.get_bloom_filter_fp_chance())); if (!get_compression_options().empty()) {