From 80194180b6bc2cb4d837ba31c5c6b99cd7020f11 Mon Sep 17 00:00:00 2001 From: Teemu Ollakka Date: Tue, 6 Nov 2018 18:14:37 +0200 Subject: [PATCH] codership/wsrep-lib#13 Fix dbsim to deal with provider generated server id Dbsim has internal map of server objects for SST simulation. This was mapped using server_id, which is not available anymore when server object is constructed. Changed the dbsim to use server name instead for internal mapping. --- dbsim/db_high_priority_service.cpp | 2 +- dbsim/db_server_service.cpp | 4 ++-- dbsim/db_simulator.cpp | 24 +++++++++++++++++------- dbsim/db_simulator.hpp | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/dbsim/db_high_priority_service.cpp b/dbsim/db_high_priority_service.cpp index 301a2544..57a982e6 100644 --- a/dbsim/db_high_priority_service.cpp +++ b/dbsim/db_high_priority_service.cpp @@ -86,7 +86,7 @@ int db::high_priority_service::rollback(const wsrep::ws_handle& ws_handle, void db::high_priority_service::after_apply() { - client_.client_state_.after_statement(); + client_.client_state_.after_applying(); } bool db::high_priority_service::is_replaying() const diff --git a/dbsim/db_server_service.cpp b/dbsim/db_server_service.cpp index f5eb6a43..9bcf8a8e 100644 --- a/dbsim/db_server_service.cpp +++ b/dbsim/db_server_service.cpp @@ -72,9 +72,9 @@ bool db::server_service::sst_before_init() const std::string db::server_service::sst_request() { std::ostringstream os; - os << server_.server_state().id(); + os << server_.server_state().name(); wsrep::log_info() << "SST request: " - << server_.server_state().id(); + << server_.server_state().name(); return os.str(); } diff --git a/dbsim/db_simulator.cpp b/dbsim/db_simulator.cpp index 1e700f6a..9f8fbea7 100644 --- a/dbsim/db_simulator.cpp +++ b/dbsim/db_simulator.cpp @@ -38,19 +38,29 @@ void db::simulator::sst(db::server& server, const wsrep::gtid& gtid, bool bypass) { - wsrep::id id; - std::istringstream is(request); - is >> id; + // The request may contain extra trailing '\0' after it goes + // through the provider, strip it first. + std::string name(request); + name.erase(std::find(name.begin(), name.end(), '\0'), name.end()); + wsrep::unique_lock lock(mutex_); - auto i(servers_.find(id)); - wsrep::log_info() << "SST request"; + auto i(servers_.find(name)); + wsrep::log_info() << "SST request '" << name << "'"; if (i == servers_.end()) { + wsrep::log_error() << "Server " << request << " not found"; + wsrep::log_info() << "servers:"; + for (const auto& s : servers_) + { + wsrep::log_info() << "server: " << s.first; + } throw wsrep::runtime_error("Server " + request + " not found"); } if (bypass == false) { - wsrep::log_info() << "SST " << server.server_state().id() << " -> " << id; + wsrep::log_info() << "SST " + << server.server_state().name() + << " -> " << request; } i->second->server_state().sst_received(gtid, 0); server.server_state().sst_sent(gtid, 0); @@ -105,7 +115,7 @@ void db::simulator::start() wsrep::id server_id(id_os.str()); auto it(servers_.insert( std::make_pair( - server_id, + name_os.str(), std::make_unique( *this, name_os.str(), diff --git a/dbsim/db_simulator.hpp b/dbsim/db_simulator.hpp index c0261619..693645e3 100644 --- a/dbsim/db_simulator.hpp +++ b/dbsim/db_simulator.hpp @@ -61,7 +61,7 @@ namespace db wsrep::default_mutex mutex_; const db::params& params_; - std::map> servers_; + std::map> servers_; std::chrono::time_point clients_start_; std::chrono::time_point clients_stop_; public: