From dae5231dfcaed9db28350fa78bf511db375d26ae Mon Sep 17 00:00:00 2001 From: Teemu Ollakka Date: Sat, 16 Jun 2018 11:30:50 +0300 Subject: [PATCH] Added topology argument to dbsim to allow testing master/slave --- dbsim/db_params.cpp | 28 +++++++++++++++++++++++++++- dbsim/db_params.hpp | 2 ++ dbsim/db_simulator.cpp | 10 +++++++--- dbsim/dbsim.cpp | 10 +++++++++- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/dbsim/db_params.cpp b/dbsim/db_params.cpp index f3b2d60..2799afa 100644 --- a/dbsim/db_params.cpp +++ b/dbsim/db_params.cpp @@ -6,6 +6,28 @@ #include #include +#include + +namespace +{ + void validate_params(const db::params& params) + { + std::ostringstream os; + if (params.n_servers != params.topology.size()) + { + if (params.topology.size() > 0) + { + os << "Error: --topology=" << params.topology << " does not " + << "match the number of server --servers=" + << params.n_servers << "\n"; + } + } + if (os.str().size()) + { + throw std::invalid_argument(os.str()); + } + } +} db::params db::parse_args(int argc, char** argv) { @@ -22,8 +44,10 @@ db::params db::parse_args(int argc, char** argv) "wsrep provider options") ("servers", po::value(¶ms.n_servers)->required(), "number of servers to start") + ("topology", po::value(¶ms.topology), + "replication topology (e.g. mm for multi master, ms for master/slave") ("clients", po::value(¶ms.n_clients)->required(), - "number of clients to start per server") + "number of clients to start per master") ("transactions", po::value(¶ms.n_transactions), "number of transactions run by a client") ("rows", po::value(¶ms.n_rows), @@ -42,5 +66,7 @@ db::params db::parse_args(int argc, char** argv) std::cerr << desc << "\n"; exit(0); } + + validate_params(params); return params; } diff --git a/dbsim/db_params.hpp b/dbsim/db_params.hpp index 8e3f8ee..156d817 100644 --- a/dbsim/db_params.hpp +++ b/dbsim/db_params.hpp @@ -17,6 +17,7 @@ namespace db size_t n_transactions; size_t n_rows; size_t alg_freq; + std::string topology; std::string wsrep_provider; std::string wsrep_provider_options; int debug_log_level; @@ -27,6 +28,7 @@ namespace db , n_transactions(0) , n_rows(1000) , alg_freq(0) + , topology() , wsrep_provider() , wsrep_provider_options() , debug_log_level(0) diff --git a/dbsim/db_simulator.cpp b/dbsim/db_simulator.cpp index 6ae01ac..a9168a3 100644 --- a/dbsim/db_simulator.cpp +++ b/dbsim/db_simulator.cpp @@ -39,10 +39,9 @@ void db::simulator::sst(db::server& server, std::string db::simulator::stats() const { - size_t transactions(params_.n_servers * params_.n_clients - * params_.n_transactions); auto duration(std::chrono::duration( clients_stop_ - clients_start_).count()); + long long transactions(stats_.commits + stats_.rollbacks); long long bf_aborts(0); for (const auto& s : servers_) { @@ -121,9 +120,14 @@ void db::simulator::start() // Start client threads wsrep::log() << "####################### Starting client load"; clients_start_ = std::chrono::steady_clock::now(); + size_t index(0); for (auto& i : servers_) { - i.second->start_clients(); + if (params_.topology.size() == 0 || params_.topology[index] == 'm') + { + i.second->start_clients(); + } + ++index; } } diff --git a/dbsim/dbsim.cpp b/dbsim/dbsim.cpp index f58cf82..5aa4610 100644 --- a/dbsim/dbsim.cpp +++ b/dbsim/dbsim.cpp @@ -7,6 +7,14 @@ int main(int argc, char** argv) { - db::simulator(db::parse_args(argc, argv)).run(); + try + { + db::simulator(db::parse_args(argc, argv)).run(); + } + catch (const std::exception& e) + { + std::cerr << e.what() << std::endl; + return 1; + } return 0; }