Skip to content

Commit

Permalink
Change default compaction strategy and add option for flow tables
Browse files Browse the repository at this point in the history
Change default compaction strategy to SizeTieredCompactionStrategy

Add CASSANDRA.flow_tables.compaction_strategy and default to
DateTieredCompactionStrategy

(cherry-pick da5161c)

Change-Id: I4742dceaece999b31e065e004188e30919b461c3
Related-Bug: #1648252
Closes-Bug: #1671625
  • Loading branch information
Megh Bhatt authored and pjediny committed Mar 9, 2017
1 parent eaad31f commit 832f870
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 16 deletions.
6 changes: 5 additions & 1 deletion src/analytics/db_handler.cc
Expand Up @@ -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,
Expand All @@ -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),
Expand Down Expand Up @@ -183,7 +185,7 @@ bool DbHandler::CreateTables() {

for (std::vector<GenDb::NewCf>::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;
}
Expand Down Expand Up @@ -1717,6 +1719,7 @@ DbHandlerInitializer::DbHandlerInitializer(EventManager *evm,
const std::vector<int> &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,
Expand All @@ -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)),
Expand Down
3 changes: 3 additions & 0 deletions src/analytics/db_handler.h
Expand Up @@ -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);
Expand Down Expand Up @@ -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_;
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/analytics/main.cc
Expand Up @@ -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(),
Expand Down
48 changes: 34 additions & 14 deletions src/analytics/options.cc
Expand Up @@ -89,8 +89,12 @@ void Options::Initialize(EventManager &evm,
"Cassandra password")
("CASSANDRA.compaction_strategy",
opt::value<string>()->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<string>()->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");
Expand Down Expand Up @@ -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[],
Expand Down Expand Up @@ -397,18 +420,15 @@ void Options::Process(int argc, char *argv[],
GetOptValue<string>(var_map, cassandra_password_, "CASSANDRA.cassandra_password");
GetOptValue<string>(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<string>(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<uint16_t>(var_map, ks_port_, "KEYSTONE.auth_port");
Expand Down
4 changes: 4 additions & 0 deletions src/analytics/options.h
Expand Up @@ -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_; }
Expand Down Expand Up @@ -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_;
Expand Down
2 changes: 1 addition & 1 deletion src/analytics/test/db_handler_mock.h
Expand Up @@ -15,7 +15,7 @@ class DbHandlerMock : public DbHandler {
DbHandler(evm, boost::bind(&DbHandlerMock::StartDbifReinit, this),
std::vector<std::string>(1, "127.0.0.1"),
std::vector<int>(1, 9160), "localhost", ttl_map, "", "",
"", "", false, false, false, false) {
"", "", "", false, false, false, false, false) {
}
void StartDbifReinit() {
UnInit(-1);
Expand Down
2 changes: 2 additions & 0 deletions src/analytics/viz_collector.cc
Expand Up @@ -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,
Expand All @@ -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)),
Expand Down
1 change: 1 addition & 0 deletions src/analytics/viz_collector.h
Expand Up @@ -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,
Expand Down

0 comments on commit 832f870

Please sign in to comment.