Skip to content

Commit

Permalink
#13 Fix dbsim to deal with provider generated server id
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
temeo committed Nov 6, 2018
1 parent 73f8756 commit 8019418
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dbsim/db_high_priority_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dbsim/db_server_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
24 changes: 17 additions & 7 deletions dbsim/db_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<wsrep::mutex> 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);
Expand Down Expand Up @@ -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<db::server>(
*this,
name_os.str(),
Expand Down
2 changes: 1 addition & 1 deletion dbsim/db_simulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace db

wsrep::default_mutex mutex_;
const db::params& params_;
std::map<wsrep::id, std::unique_ptr<db::server>> servers_;
std::map<std::string, std::unique_ptr<db::server>> servers_;
std::chrono::time_point<std::chrono::steady_clock> clients_start_;
std::chrono::time_point<std::chrono::steady_clock> clients_stop_;
public:
Expand Down

0 comments on commit 8019418

Please sign in to comment.