1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-07-30 07:23:07 +03:00

Refactored storage service out of client service interface.

This commit is contained in:
Teemu Ollakka
2018-07-07 18:06:37 +03:00
parent a8be09161c
commit 2ac13100f7
31 changed files with 465 additions and 247 deletions

View File

@ -16,8 +16,8 @@ db::client::client(db::server& server,
, params_(params)
, server_(server)
, server_state_(server.server_state())
, client_state_(mutex_, cond_, this, server_state_, client_service_, client_id, mode)
, client_service_(client_state_)
, client_state_(mutex_, cond_, server_state_, client_service_, client_id, mode)
, client_service_(*this)
, se_trx_(server.storage_engine())
, stats_()
{ }
@ -114,7 +114,7 @@ void db::client::run_one_transaction()
{
// wsrep::log_debug() << "Commit";
assert(err == 0);
if (client_state_.do_2pc())
if (do_2pc())
{
err = err || client_state_.before_prepare();
err = err || client_state_.after_prepare();

View File

@ -44,6 +44,7 @@ namespace db
{ }
void start();
wsrep::client_state& client_state() { return client_state_; }
bool do_2pc() const { return false; }
private:
friend class db::server_state;
friend class db::client_service;

View File

@ -6,24 +6,22 @@
#include "db_high_priority_service.hpp"
#include "db_client.hpp"
db::client_service::client_service(db::client& client)
: wsrep::client_service()
, client_(client)
, client_state_(client_.client_state())
{ }
int db::client_service::commit(const wsrep::ws_handle&,
const wsrep::ws_meta&)
bool db::client_service::do_2pc() const
{
db::client* client(client_state_.client());
int ret(client_state_.before_commit());
if (ret == 0) client->se_trx_.commit();
ret = ret || client_state_.ordered_commit();
ret = ret || client_state_.after_commit();
return ret;
return client_.do_2pc();
}
int db::client_service::bf_rollback()
{
db::client* client(client_state_.client());
int ret(client_state_.before_rollback());
assert(ret == 0);
client->se_trx_.rollback();
client_.se_trx_.rollback();
ret = client_state_.after_rollback();
assert(ret == 0);
return ret;
@ -34,13 +32,13 @@ db::client_service::replay()
{
wsrep::high_priority_context high_priority_context(client_state_);
db::high_priority_service high_priority_service(
client_state_.client()->server_, client_state_.client());
client_.server_, client_);
auto ret(client_state_.provider().replay(
client_state_.transaction().ws_handle(),
&high_priority_service));
if (ret == wsrep::provider::success)
{
++client_state_.client()->stats_.replays;
++client_.stats_.replays;
}
return ret;
}

View File

@ -8,37 +8,26 @@
#include "wsrep/client_service.hpp"
#include "wsrep/transaction.hpp"
#include "db_client_state.hpp"
namespace db
{
class client;
class client_state;
class client_service : public wsrep::client_service
{
public:
client_service(db::client_state& client_state)
: wsrep::client_service()
, client_state_(client_state)
{ }
client_service(db::client& client);
bool do_2pc() const override
{
return client_state_.do_2pc();
}
bool do_2pc() const override;
bool interrupted() const override
{
return false;
}
void reset_globals() override
{
client_state_.reset_globals();
}
void reset_globals() override { }
void store_globals() override
{
client_state_.store_globals();
}
void store_globals() override { }
int prepare_data_for_replication() override
{
@ -56,6 +45,7 @@ namespace db
{
return true;
}
int prepare_fragment_for_replication(wsrep::mutable_buffer&) override
{
return 0;
@ -64,12 +54,6 @@ namespace db
void remove_fragments() override
{ }
// int apply_write_set(const wsrep::const_buffer&) override;
// int apply_toi(const wsrep::const_buffer&) override;
int commit(const wsrep::ws_handle&, const wsrep::ws_meta&) override;
int bf_rollback() override;
void will_replay() override
@ -79,17 +63,12 @@ namespace db
enum wsrep::provider::status replay()
override;
int append_fragment(const wsrep::transaction&, int,
const wsrep::const_buffer&) override
{
return 0;
}
void emergency_shutdown() { ::abort(); }
void debug_sync(const char*) override { }
void debug_crash(const char*) override { }
private:
db::client_state& client_state_;
db::client& client_;
wsrep::client_state& client_state_;
};
}

View File

@ -16,7 +16,6 @@ namespace db
public:
client_state(wsrep::mutex& mutex,
wsrep::condition_variable& cond,
db::client* client,
db::server_state& server_state,
wsrep::client_service& client_service,
const wsrep::client_id& client_id,
@ -27,22 +26,11 @@ namespace db
client_service,
client_id,
mode)
, client_(client)
, is_autocommit_(false)
, do_2pc_(false)
{ }
db::client* client() { return client_; }
void reset_globals() { }
void store_globals() { wsrep::client_state::store_globals(); }
bool is_autocommit() const { return is_autocommit_; }
bool do_2pc() const { return do_2pc_; }
private:
client_state(const client_state&);
client_state& operator=(const client_state&);
db::client* client_;
bool is_autocommit_;
bool do_2pc_;
};
}

View File

@ -7,7 +7,7 @@
#include "db_client.hpp"
db::high_priority_service::high_priority_service(
db::server& server, db::client* client)
db::server& server, db::client& client)
: wsrep::high_priority_service(server_.server_state())
, server_(server)
, client_(client)
@ -17,7 +17,7 @@ int db::high_priority_service::start_transaction(
const wsrep::ws_handle& ws_handle,
const wsrep::ws_meta& ws_meta)
{
return client_->client_state().start_transaction(ws_handle, ws_meta);
return client_.client_state().start_transaction(ws_handle, ws_meta);
}
void db::high_priority_service::adopt_transaction(const wsrep::transaction&)
@ -27,8 +27,8 @@ void db::high_priority_service::adopt_transaction(const wsrep::transaction&)
int db::high_priority_service::apply_write_set(const wsrep::const_buffer&)
{
client_->se_trx_.start(client_);
client_->se_trx_.apply(client_->client_state().transaction());
client_.se_trx_.start(&client_);
client_.se_trx_.apply(client_.client_state().transaction());
return 0;
}
@ -41,29 +41,29 @@ int db::high_priority_service::apply_toi(
int db::high_priority_service::commit()
{
int ret(client_->client_state_.before_commit());
if (ret == 0) client_->se_trx_.commit();
ret = ret || client_->client_state_.ordered_commit();
ret = ret || client_->client_state_.after_commit();
int ret(client_.client_state_.before_commit());
if (ret == 0) client_.se_trx_.commit();
ret = ret || client_.client_state_.ordered_commit();
ret = ret || client_.client_state_.after_commit();
return ret;
}
int db::high_priority_service::rollback()
{
int ret(client_->client_state_.before_rollback());
int ret(client_.client_state_.before_rollback());
assert(ret == 0);
client_->se_trx_.rollback();
ret = client_->client_state_.after_rollback();
client_.se_trx_.rollback();
ret = client_.client_state_.after_rollback();
assert(ret == 0);
return ret;
}
void db::high_priority_service::after_apply()
{
client_->client_state_.after_statement();
client_.client_state_.after_statement();
}
bool db::high_priority_service::is_replaying() const
{
return (client_->client_state_.transaction().state() == wsrep::transaction::s_replaying);
return (client_.client_state_.transaction().state() == wsrep::transaction::s_replaying);
}

View File

@ -14,11 +14,14 @@ namespace db
class high_priority_service : public wsrep::high_priority_service
{
public:
high_priority_service(db::server& server, db::client* client);
high_priority_service(db::server& server, db::client& client);
int start_transaction(const wsrep::ws_handle&,
const wsrep::ws_meta&) override;
void adopt_transaction(const wsrep::transaction&) override;
int apply_write_set(const wsrep::const_buffer&) override;
int append_fragment(const wsrep::ws_meta&, const wsrep::const_buffer&)
override
{ return 0; }
int commit() override;
int rollback() override;
int apply_toi(const wsrep::ws_meta&, const wsrep::const_buffer&) override;
@ -33,7 +36,7 @@ namespace db
high_priority_service(const high_priority_service&);
high_priority_service& operator=(const high_priority_service&);
db::server& server_;
db::client* client_;
db::client& client_;
};
}

View File

@ -36,7 +36,7 @@ void db::server::applier_thread()
simulator_.params());
wsrep::client_state* cc(static_cast<wsrep::client_state*>(
&applier.client_state()));
db::high_priority_service hps(*this, &applier);
db::high_priority_service hps(*this, applier);
cc->open(cc->id());
cc->before_command();
enum wsrep::provider::status ret(
@ -110,21 +110,6 @@ void db::server::donate_sst(const std::string& req,
simulator_.sst(*this, req, gtid, bypass);
}
wsrep::client_state* db::server::local_client_state()
{
std::ostringstream id_os;
size_t client_id(++last_client_id_);
db::client* client(new db::client(*this, client_id,
wsrep::client_state::m_local,
simulator_.params()));
return &client->client_state();
}
void db::server::release_client_state(wsrep::client_state* client_state)
{
db::client_state* db_client_state(
dynamic_cast<db::client_state*>(client_state));
delete db_client_state->client();
}
wsrep::high_priority_service* db::server::streaming_applier_service()
{

View File

@ -4,6 +4,7 @@
#include "db_server_service.hpp"
#include "db_server.hpp"
#include "db_storage_service.hpp"
#include "wsrep/logger.hpp"
#include "wsrep/high_priority_service.hpp"
@ -12,15 +13,16 @@ db::server_service::server_service(db::server& server)
: server_(server)
{ }
wsrep::client_state* db::server_service::local_client_state()
wsrep::storage_service* db::server_service::storage_service(
wsrep::client_service&)
{
return server_.local_client_state();
return new db::storage_service();
}
void db::server_service::release_client_state(
wsrep::client_state* client_state)
void db::server_service::release_storage_service(
wsrep::storage_service* storage_service)
{
server_.release_client_state(client_state);
delete storage_service;
}
wsrep::high_priority_service* db::server_service::streaming_applier_service()
@ -41,7 +43,12 @@ bool db::server_service::sst_before_init() const
std::string db::server_service::sst_request()
{
return server_.server_state().id();
std::ostringstream os;
os << server_.server_state().id();
wsrep::log_info() << "SST request: "
<< server_.server_state().id();
return os.str();
}
int db::server_service::start_sst(

View File

@ -15,8 +15,8 @@ namespace db
{
public:
server_service(db::server& server);
wsrep::client_state* local_client_state() override;
void release_client_state(wsrep::client_state*) override;
wsrep::storage_service* storage_service(wsrep::client_service&) override;
void release_storage_service(wsrep::storage_service*) override;
wsrep::high_priority_service* streaming_applier_service() override;
void release_high_priority_service(wsrep::high_priority_service*) override;

View File

@ -23,11 +23,12 @@ void db::simulator::sst(db::server& server,
const wsrep::gtid& gtid,
bool bypass)
{
size_t id;
wsrep::id id;
std::istringstream is(request);
is >> id;
wsrep::unique_lock<wsrep::mutex> lock(mutex_);
auto i(servers_.find(id));
wsrep::log_info() << "SST request";
if (i == servers_.end())
{
throw wsrep::runtime_error("Server " + request + " not found");
@ -86,9 +87,10 @@ void db::simulator::start()
id_os << (i + 1);
std::ostringstream address_os;
address_os << "127.0.0.1:" << server_port(i);
wsrep::id server_id(id_os.str());
auto it(servers_.insert(
std::make_pair(
(i + 1),
server_id,
std::make_unique<db::server>(
*this,
name_os.str(),

View File

@ -46,7 +46,7 @@ namespace db
wsrep::default_mutex mutex_;
const db::params& params_;
std::map<size_t, std::unique_ptr<db::server>> servers_;
std::map<wsrep::id, 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:

View File

@ -0,0 +1,33 @@
//
// Copyright (C) 2018 Codership Oy <info@codership.com>
//
#ifndef WSREP_DB_STORAGE_SERVICE_HPP
#define WSREP_DB_STORAGE_SERVICE_HPP
#include "wsrep/storage_service.hpp"
#include "wsrep/exception.hpp"
namespace db
{
class storage_service : public wsrep::storage_service
{
int start_transaction() override
{ throw wsrep::not_implemented_error(); }
int append_fragment(const wsrep::id&, wsrep::client_id,
int,
const wsrep::const_buffer&) override
{ throw wsrep::not_implemented_error(); }
int update_fragment_meta(const wsrep::ws_meta&) override
{ throw wsrep::not_implemented_error(); }
int commit(const wsrep::ws_handle&, const wsrep::ws_meta&) override
{ throw wsrep::not_implemented_error(); }
int rollback(const wsrep::ws_handle&, const wsrep::ws_meta&)
override
{ throw wsrep::not_implemented_error(); }
void store_globals() override { }
void reset_globals() override { }
};
}
#endif // WSREP_DB_STORAGE_SERVICE_HPP