From 832f870f0b14f03672b88746c83199f0ba08c788 Mon Sep 17 00:00:00 2001 From: Megh Bhatt Date: Wed, 7 Dec 2016 15:23:45 -0800 Subject: [PATCH] Change default compaction strategy and add option for flow tables Change default compaction strategy to SizeTieredCompactionStrategy Add CASSANDRA.flow_tables.compaction_strategy and default to DateTieredCompactionStrategy (cherry-pick da5161c595c483c0a90022f09d61e7f7411a2612) Change-Id: I4742dceaece999b31e065e004188e30919b461c3 Related-Bug: #1648252 Closes-Bug: #1671625 --- src/analytics/db_handler.cc | 6 +++- src/analytics/db_handler.h | 3 ++ src/analytics/main.cc | 1 + src/analytics/options.cc | 48 ++++++++++++++++++++-------- src/analytics/options.h | 4 +++ src/analytics/test/db_handler_mock.h | 2 +- src/analytics/viz_collector.cc | 2 ++ src/analytics/viz_collector.h | 1 + 8 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/analytics/db_handler.cc b/src/analytics/db_handler.cc index a81ec0b21d6..032bcfe396a 100644 --- a/src/analytics/db_handler.cc +++ b/src/analytics/db_handler.cc @@ -68,6 +68,7 @@ DbHandler::DbHandler(EventManager *evm, const std::string& cassandra_user, const std::string& cassandra_password, const std::string &cassandra_compaction_strategy, + const std::string &cassandra_flow_tables_compaction_strategy, const std::string &zookeeper_server_list, bool use_zookeeper, bool disable_all_writes, bool disable_statistics_writes, bool disable_messages_writes, @@ -79,6 +80,7 @@ DbHandler::DbHandler(EventManager *evm, ttl_map_(ttl_map), tablespace_(g_viz_constants.COLLECTOR_KEYSPACE_CQL), compaction_strategy_(cassandra_compaction_strategy), + flow_tables_compaction_strategy_(cassandra_flow_tables_compaction_strategy), gen_partition_no_((uint8_t)g_viz_constants.PARTITION_MIN, (uint8_t)g_viz_constants.PARTITION_MAX), zookeeper_server_list_(zookeeper_server_list), @@ -183,7 +185,7 @@ bool DbHandler::CreateTables() { for (std::vector::const_iterator it = vizd_flow_tables.begin(); it != vizd_flow_tables.end(); it++) { - if (!dbif_->Db_AddColumnfamily(*it, compaction_strategy_)) { + if (!dbif_->Db_AddColumnfamily(*it, flow_tables_compaction_strategy_)) { DB_LOG(ERROR, it->cfname_ << " FAILED"); return false; } @@ -1717,6 +1719,7 @@ DbHandlerInitializer::DbHandlerInitializer(EventManager *evm, const std::vector &cassandra_ports, const TtlMap& ttl_map, const std::string &cassandra_user, const std::string &cassandra_password, const std::string &cassandra_compaction_strategy, + const std::string &cassandra_flow_tables_compaction_strategy, const std::string &zookeeper_server_list, bool use_zookeeper, bool disable_all_db_writes, bool disable_db_stats_writes, bool disable_db_messages_writes, @@ -1727,6 +1730,7 @@ DbHandlerInitializer::DbHandlerInitializer(EventManager *evm, boost::bind(&DbHandlerInitializer::ScheduleInit, this), cassandra_ips, cassandra_ports, db_name, ttl_map, cassandra_user, cassandra_password, cassandra_compaction_strategy, + cassandra_flow_tables_compaction_strategy, zookeeper_server_list, use_zookeeper, disable_all_db_writes, disable_db_stats_writes, disable_db_messages_writes, disable_db_messages_keyword_writes)), diff --git a/src/analytics/db_handler.h b/src/analytics/db_handler.h index dcc52aaf6c1..0f29c35a067 100644 --- a/src/analytics/db_handler.h +++ b/src/analytics/db_handler.h @@ -93,6 +93,7 @@ class DbHandler { const std::string& cassandra_user, const std::string& cassandra_password, const std::string& cassandra_compaction_strategy, + const std::string& cassandra_flow_tables_compaction_strategy, const std::string &zookeeper_server_list, bool use_zookeeper, bool disable_all_writes, bool disable_stats_writes, bool disable_messages_writes, bool disable_messages_keyword_writes); @@ -214,6 +215,7 @@ class DbHandler { static tbb::mutex fmutex_; std::string tablespace_; std::string compaction_strategy_; + std::string flow_tables_compaction_strategy_; UniformInt8RandomGenerator gen_partition_no_; std::string zookeeper_server_list_; bool use_zookeeper_; @@ -266,6 +268,7 @@ class DbHandlerInitializer { const std::string& cassandra_user, const std::string& cassandra_password, const std::string &cassandra_compaction_strategy, + const std::string &cassandra_flow_tables_compaction_strategy, const std::string &zookeeper_server_list, bool use_zookeeper, bool disable_all_db_writes, bool disable_db_stats_writes, bool disable_db_messages_writes, diff --git a/src/analytics/main.cc b/src/analytics/main.cc index 62a6c7558fb..87979d53154 100644 --- a/src/analytics/main.cc +++ b/src/analytics/main.cc @@ -370,6 +370,7 @@ int main(int argc, char *argv[]) ttl_map, options.cassandra_user(), options.cassandra_password(), options.cassandra_compaction_strategy(), + options.cassandra_flow_tables_compaction_strategy(), zookeeper_server_list, use_zookeeper, options.disable_all_db_writes(), options.disable_db_statistics_writes(), diff --git a/src/analytics/options.cc b/src/analytics/options.cc index 2cf68b87135..a46d367d800 100644 --- a/src/analytics/options.cc +++ b/src/analytics/options.cc @@ -89,8 +89,12 @@ void Options::Initialize(EventManager &evm, "Cassandra password") ("CASSANDRA.compaction_strategy", opt::value()->default_value( - GenDb::g_gendb_constants.LEVELED_COMPACTION_STRATEGY), - "Cassandra compaction strategy");; + GenDb::g_gendb_constants.SIZE_TIERED_COMPACTION_STRATEGY), + "Cassandra compaction strategy") + ("CASSANDRA.flow_tables.compaction_strategy", + opt::value()->default_value( + GenDb::g_gendb_constants.DATE_TIERED_COMPACTION_STRATEGY), + "Cassandra compaction strategy for flow tables"); // Command line and config file options. opt::options_description config("Configuration options"); @@ -295,6 +299,25 @@ void Options::GetOptValueImpl( } } +static bool ValidateCompactionStrategyOption( + const std::string &compaction_strategy, + const std::string &option) { + if (!((compaction_strategy == + GenDb::g_gendb_constants.DATE_TIERED_COMPACTION_STRATEGY) || + (compaction_strategy == + GenDb::g_gendb_constants.LEVELED_COMPACTION_STRATEGY) || + (compaction_strategy == + GenDb::g_gendb_constants.SIZE_TIERED_COMPACTION_STRATEGY))) { + cout << "Invalid " << option << ", please select one of [" << + GenDb::g_gendb_constants.DATE_TIERED_COMPACTION_STRATEGY << ", " << + GenDb::g_gendb_constants.LEVELED_COMPACTION_STRATEGY << ", " << + GenDb::g_gendb_constants.SIZE_TIERED_COMPACTION_STRATEGY << "]" << + endl; + return false; + } + return true; +} + // Process command line options. They can come from a conf file as well. Options // from command line always overrides those that come from the config file. void Options::Process(int argc, char *argv[], @@ -397,18 +420,15 @@ void Options::Process(int argc, char *argv[], GetOptValue(var_map, cassandra_password_, "CASSANDRA.cassandra_password"); GetOptValue(var_map, cassandra_compaction_strategy_, "CASSANDRA.compaction_strategy"); - if (!((cassandra_compaction_strategy_ == - GenDb::g_gendb_constants.DATE_TIERED_COMPACTION_STRATEGY) || - (cassandra_compaction_strategy_ == - GenDb::g_gendb_constants.LEVELED_COMPACTION_STRATEGY) || - (cassandra_compaction_strategy_ == - GenDb::g_gendb_constants.SIZE_TIERED_COMPACTION_STRATEGY))) { - cout << "Invalid CASSANDRA.compaction_strategy," << - " please select one of [" << - GenDb::g_gendb_constants.DATE_TIERED_COMPACTION_STRATEGY << ", " << - GenDb::g_gendb_constants.LEVELED_COMPACTION_STRATEGY << ", " << - GenDb::g_gendb_constants.SIZE_TIERED_COMPACTION_STRATEGY << "]" << - endl; + if (!ValidateCompactionStrategyOption(cassandra_compaction_strategy_, + "CASSANDRA.compaction_strategy")) { + exit(-1); + } + GetOptValue(var_map, cassandra_flow_tables_compaction_strategy_, + "CASSANDRA.flow_tables.compaction_strategy"); + if (!ValidateCompactionStrategyOption( + cassandra_flow_tables_compaction_strategy_, + "CASSANDRA.flow_tables.compaction_strategy")) { exit(-1); } GetOptValue(var_map, ks_port_, "KEYSTONE.auth_port"); diff --git a/src/analytics/options.h b/src/analytics/options.h index eb7719b7e08..42ce6248d3a 100644 --- a/src/analytics/options.h +++ b/src/analytics/options.h @@ -45,6 +45,9 @@ class Options { const std::string cassandra_compaction_strategy() const { return cassandra_compaction_strategy_; } + const std::string cassandra_flow_tables_compaction_strategy() const { + return cassandra_flow_tables_compaction_strategy_; + } const std::string hostname() const { return hostname_; } const std::string host_ip() const { return host_ip_; } const uint16_t http_server_port() const { return http_server_port_; } @@ -122,6 +125,7 @@ class Options { std::string cassandra_user_; std::string cassandra_password_; std::string cassandra_compaction_strategy_; + std::string cassandra_flow_tables_compaction_strategy_; std::string hostname_; std::string host_ip_; uint16_t http_server_port_; diff --git a/src/analytics/test/db_handler_mock.h b/src/analytics/test/db_handler_mock.h index 815c973f7e6..4227617a9d6 100644 --- a/src/analytics/test/db_handler_mock.h +++ b/src/analytics/test/db_handler_mock.h @@ -15,7 +15,7 @@ class DbHandlerMock : public DbHandler { DbHandler(evm, boost::bind(&DbHandlerMock::StartDbifReinit, this), std::vector(1, "127.0.0.1"), std::vector(1, 9160), "localhost", ttl_map, "", "", - "", "", false, false, false, false) { + "", "", "", false, false, false, false, false) { } void StartDbifReinit() { UnInit(-1); diff --git a/src/analytics/viz_collector.cc b/src/analytics/viz_collector.cc index b40ec1cbf83..0a3e6205111 100644 --- a/src/analytics/viz_collector.cc +++ b/src/analytics/viz_collector.cc @@ -46,6 +46,7 @@ VizCollector::VizCollector(EventManager *evm, unsigned short listen_port, const std::string &cassandra_user, const std::string &cassandra_password, const std::string &cassandra_compaction_strategy, + const std::string &cassandra_flow_tables_compaction_strategy, const std::string &zookeeper_server_list, bool use_zookeeper, bool disable_all_db_writes, bool disable_db_stats_writes, bool disable_db_messages_writes, @@ -55,6 +56,7 @@ VizCollector::VizCollector(EventManager *evm, unsigned short listen_port, boost::bind(&VizCollector::DbInitializeCb, this), cassandra_ips, cassandra_ports, ttl_map, cassandra_user, cassandra_password, cassandra_compaction_strategy, + cassandra_flow_tables_compaction_strategy, zookeeper_server_list, use_zookeeper, disable_all_db_writes, disable_db_stats_writes, disable_db_messages_writes, disable_db_messages_keyword_writes)), diff --git a/src/analytics/viz_collector.h b/src/analytics/viz_collector.h index 14085e8dc18..3cdeb2ff9e7 100644 --- a/src/analytics/viz_collector.h +++ b/src/analytics/viz_collector.h @@ -43,6 +43,7 @@ class VizCollector { const std::string& cassandra_user, const std::string& cassandra_password, const std::string &cassandra_compaction_strategy, + const std::string &cassandra_flow_tables_compaction_strategy, const std::string &zookeeper_server_list, bool use_zookeeper, bool disable_all_db_writes, bool disable_db_stats_writes, bool disable_db_messages_writes,