1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-06-13 04:01:32 +03:00

Added topology argument to dbsim to allow testing master/slave

This commit is contained in:
Teemu Ollakka
2018-06-16 11:30:50 +03:00
parent 6dcac8ce4d
commit dae5231dfc
4 changed files with 45 additions and 5 deletions

View File

@ -6,6 +6,28 @@
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <iostream> #include <iostream>
#include <stdexcept>
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) 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") "wsrep provider options")
("servers", po::value<size_t>(&params.n_servers)->required(), ("servers", po::value<size_t>(&params.n_servers)->required(),
"number of servers to start") "number of servers to start")
("topology", po::value<std::string>(&params.topology),
"replication topology (e.g. mm for multi master, ms for master/slave")
("clients", po::value<size_t>(&params.n_clients)->required(), ("clients", po::value<size_t>(&params.n_clients)->required(),
"number of clients to start per server") "number of clients to start per master")
("transactions", po::value<size_t>(&params.n_transactions), ("transactions", po::value<size_t>(&params.n_transactions),
"number of transactions run by a client") "number of transactions run by a client")
("rows", po::value<size_t>(&params.n_rows), ("rows", po::value<size_t>(&params.n_rows),
@ -42,5 +66,7 @@ db::params db::parse_args(int argc, char** argv)
std::cerr << desc << "\n"; std::cerr << desc << "\n";
exit(0); exit(0);
} }
validate_params(params);
return params; return params;
} }

View File

@ -17,6 +17,7 @@ namespace db
size_t n_transactions; size_t n_transactions;
size_t n_rows; size_t n_rows;
size_t alg_freq; size_t alg_freq;
std::string topology;
std::string wsrep_provider; std::string wsrep_provider;
std::string wsrep_provider_options; std::string wsrep_provider_options;
int debug_log_level; int debug_log_level;
@ -27,6 +28,7 @@ namespace db
, n_transactions(0) , n_transactions(0)
, n_rows(1000) , n_rows(1000)
, alg_freq(0) , alg_freq(0)
, topology()
, wsrep_provider() , wsrep_provider()
, wsrep_provider_options() , wsrep_provider_options()
, debug_log_level(0) , debug_log_level(0)

View File

@ -39,10 +39,9 @@ void db::simulator::sst(db::server& server,
std::string db::simulator::stats() const std::string db::simulator::stats() const
{ {
size_t transactions(params_.n_servers * params_.n_clients
* params_.n_transactions);
auto duration(std::chrono::duration<double>( auto duration(std::chrono::duration<double>(
clients_stop_ - clients_start_).count()); clients_stop_ - clients_start_).count());
long long transactions(stats_.commits + stats_.rollbacks);
long long bf_aborts(0); long long bf_aborts(0);
for (const auto& s : servers_) for (const auto& s : servers_)
{ {
@ -121,9 +120,14 @@ void db::simulator::start()
// Start client threads // Start client threads
wsrep::log() << "####################### Starting client load"; wsrep::log() << "####################### Starting client load";
clients_start_ = std::chrono::steady_clock::now(); clients_start_ = std::chrono::steady_clock::now();
size_t index(0);
for (auto& i : servers_) for (auto& i : servers_)
{ {
i.second->start_clients(); if (params_.topology.size() == 0 || params_.topology[index] == 'm')
{
i.second->start_clients();
}
++index;
} }
} }

View File

@ -7,6 +7,14 @@
int main(int argc, char** argv) 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; return 0;
} }