1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-07-24 10:42:31 +03:00

Renamed server_context to server_state.

This commit is contained in:
Teemu Ollakka
2018-06-17 10:07:48 +03:00
parent 790c2bec4e
commit ef4baa9f9d
29 changed files with 212 additions and 297 deletions

View File

@ -7,7 +7,7 @@ add_executable(dbsim
db_client_service.cpp db_client_service.cpp
db_params.cpp db_params.cpp
db_server.cpp db_server.cpp
db_server_context.cpp db_server_state.cpp
db_simulator.cpp db_simulator.cpp
db_storage_engine.cpp db_storage_engine.cpp
dbsim.cpp dbsim.cpp

View File

@ -12,9 +12,9 @@ db::client::client(db::server& server,
: mutex_() : mutex_()
, params_(params) , params_(params)
, server_(server) , server_(server)
, server_context_(server.server_context()) , server_state_(server.server_state())
, client_state_(mutex_, this, server_context_, client_service_, client_id, mode) , client_state_(mutex_, this, server_state_, client_service_, client_id, mode)
, client_service_(server_context_.provider(), client_state_) , client_service_(server_state_.provider(), client_state_)
, se_trx_(server.storage_engine()) , se_trx_(server.storage_engine())
, stats_() , stats_()
{ } { }

View File

@ -5,7 +5,7 @@
#ifndef WSREP_DB_CLIENT_HPP #ifndef WSREP_DB_CLIENT_HPP
#define WSREP_DB_CLIENT_HPP #define WSREP_DB_CLIENT_HPP
#include "db_server_context.hpp" #include "db_server_state.hpp"
#include "db_storage_engine.hpp" #include "db_storage_engine.hpp"
#include "db_client_state.hpp" #include "db_client_state.hpp"
#include "db_client_service.hpp" #include "db_client_service.hpp"
@ -43,7 +43,7 @@ namespace db
void start(); void start();
wsrep::client_state& client_state() { return client_state_; } wsrep::client_state& client_state() { return client_state_; }
private: private:
friend class db::server_context; friend class db::server_state;
friend class db::client_service; friend class db::client_service;
template <class F> int client_command(F f); template <class F> int client_command(F f);
void run_one_transaction(); void run_one_transaction();
@ -52,7 +52,7 @@ namespace db
wsrep::default_mutex mutex_; wsrep::default_mutex mutex_;
const db::params& params_; const db::params& params_;
db::server& server_; db::server& server_;
db::server_context& server_context_; db::server_state& server_state_;
db::client_state client_state_; db::client_state client_state_;
db::client_service client_service_; db::client_service client_service_;
db::storage_engine::transaction se_trx_; db::storage_engine::transaction se_trx_;

View File

@ -6,7 +6,7 @@
#define WSREP_DB_CLIENT_CONTEXT_HPP #define WSREP_DB_CLIENT_CONTEXT_HPP
#include "wsrep/client_state.hpp" #include "wsrep/client_state.hpp"
#include "db_server_context.hpp" #include "db_server_state.hpp"
namespace db namespace db
{ {
@ -16,12 +16,12 @@ namespace db
public: public:
client_state(wsrep::mutex& mutex, client_state(wsrep::mutex& mutex,
db::client* client, db::client* client,
db::server_context& server_context, db::server_state& server_state,
wsrep::client_service& client_service, wsrep::client_service& client_service,
const wsrep::client_id& client_id, const wsrep::client_id& client_id,
enum wsrep::client_state::mode mode) enum wsrep::client_state::mode mode)
: wsrep::client_state(mutex, : wsrep::client_state(mutex,
server_context, server_state,
client_service, client_service,
client_id, client_id,
mode) mode)

View File

@ -14,7 +14,7 @@ db::server::server(simulator& simulator,
, storage_engine_(simulator_.params()) , storage_engine_(simulator_.params())
, mutex_() , mutex_()
, cond_() , cond_()
, server_context_(*this, name, server_id, address, "dbsim_" + name + "_data") , server_state_(*this, name, server_id, address, "dbsim_" + name + "_data")
, last_client_id_(0) , last_client_id_(0)
, last_transaction_id_(0) , last_transaction_id_(0)
, appliers_() , appliers_()
@ -31,7 +31,7 @@ void db::server::applier_thread()
wsrep::client_state* cc(static_cast<wsrep::client_state*>( wsrep::client_state* cc(static_cast<wsrep::client_state*>(
&applier.client_state())); &applier.client_state()));
enum wsrep::provider::status ret( enum wsrep::provider::status ret(
server_context_.provider().run_applier(cc)); server_state_.provider().run_applier(cc));
wsrep::log() << "Applier thread exited with error code " << ret; wsrep::log() << "Applier thread exited with error code " << ret;
} }

View File

@ -9,7 +9,7 @@
#include "wsrep/client_state.hpp" #include "wsrep/client_state.hpp"
#include "db_storage_engine.hpp" #include "db_storage_engine.hpp"
#include "db_server_context.hpp" #include "db_server_state.hpp"
#include <boost/thread.hpp> #include <boost/thread.hpp>
@ -34,7 +34,7 @@ namespace db
void stop_clients(); void stop_clients();
void client_thread(const std::shared_ptr<db::client>& client); void client_thread(const std::shared_ptr<db::client>& client);
db::storage_engine& storage_engine() { return storage_engine_; } db::storage_engine& storage_engine() { return storage_engine_; }
db::server_context& server_context() { return server_context_; } db::server_state& server_state() { return server_state_; }
wsrep::transaction_id next_transaction_id() wsrep::transaction_id next_transaction_id()
{ {
return (last_transaction_id_.fetch_add(1) + 1); return (last_transaction_id_.fetch_add(1) + 1);
@ -51,7 +51,7 @@ namespace db
db::storage_engine storage_engine_; db::storage_engine storage_engine_;
wsrep::default_mutex mutex_; wsrep::default_mutex mutex_;
wsrep::default_condition_variable cond_; wsrep::default_condition_variable cond_;
db::server_context server_context_; db::server_state server_state_;
std::atomic<size_t> last_client_id_; std::atomic<size_t> last_client_id_;
std::atomic<size_t> last_transaction_id_; std::atomic<size_t> last_transaction_id_;
std::vector<boost::thread> appliers_; std::vector<boost::thread> appliers_;

View File

@ -2,46 +2,46 @@
// Copyright (C) 2018 Codership Oy <info@codership.com> // Copyright (C) 2018 Codership Oy <info@codership.com>
// //
#include "db_server_context.hpp" #include "db_server_state.hpp"
#include "db_server.hpp" #include "db_server.hpp"
wsrep::client_state* db::server_context::local_client_state() wsrep::client_state* db::server_state::local_client_state()
{ {
return server_.local_client_state(); return server_.local_client_state();
} }
wsrep::client_state* db::server_context::streaming_applier_client_state() wsrep::client_state* db::server_state::streaming_applier_client_state()
{ {
return server_.streaming_applier_client_state(); return server_.streaming_applier_client_state();
} }
void db::server_context::release_client_state( void db::server_state::release_client_state(
wsrep::client_state* client_state) wsrep::client_state* client_state)
{ {
server_.release_client_state(client_state); server_.release_client_state(client_state);
} }
bool db::server_context::sst_before_init() const bool db::server_state::sst_before_init() const
{ {
return false; return false;
} }
std::string db::server_context::on_sst_required() std::string db::server_state::on_sst_required()
{ {
return id(); return id();
} }
void db::server_context::on_sst_request( void db::server_state::on_sst_request(
const std::string& request, const wsrep::gtid& gtid, bool bypass) const std::string& request, const wsrep::gtid& gtid, bool bypass)
{ {
server_.donate_sst(request, gtid, bypass); server_.donate_sst(request, gtid, bypass);
} }
void db::server_context::background_rollback(wsrep::client_state&) void db::server_state::background_rollback(wsrep::client_state&)
{ {
} }
void db::server_context::log_dummy_write_set( void db::server_state::log_dummy_write_set(
wsrep::client_state&, const wsrep::ws_meta& meta) wsrep::client_state&, const wsrep::ws_meta& meta)
{ {
wsrep::log_info() << "Dummy write set: " << meta.seqno(); wsrep::log_info() << "Dummy write set: " << meta.seqno();

View File

@ -5,7 +5,7 @@
#ifndef WSREP_DB_SERVER_CONTEXT_HPP #ifndef WSREP_DB_SERVER_CONTEXT_HPP
#define WSREP_DB_SERVER_CONTEXT_HPP #define WSREP_DB_SERVER_CONTEXT_HPP
#include "wsrep/server_context.hpp" #include "wsrep/server_state.hpp"
#include "wsrep/client_state.hpp" #include "wsrep/client_state.hpp"
#include <atomic> #include <atomic>
@ -13,22 +13,22 @@
namespace db namespace db
{ {
class server; class server;
class server_context : public wsrep::server_context class server_state : public wsrep::server_state
{ {
public: public:
server_context(db::server& server, server_state(db::server& server,
const std::string& name, const std::string& name,
const std::string& server_id, const std::string& server_id,
const std::string& address, const std::string& address,
const std::string& working_dir) const std::string& working_dir)
: wsrep::server_context( : wsrep::server_state(
mutex_, mutex_,
cond_, cond_,
name, name,
server_id, server_id,
address, address,
working_dir, working_dir,
wsrep::server_context::rm_async) wsrep::server_state::rm_async)
, mutex_() , mutex_()
, cond_() , cond_()
, server_(server) , server_(server)

View File

@ -31,10 +31,10 @@ void db::simulator::sst(db::server& server,
} }
if (bypass == false) if (bypass == false)
{ {
wsrep::log_info() << "SST " << server.server_context().id() << " -> " << id; wsrep::log_info() << "SST " << server.server_state().id() << " -> " << id;
} }
i->second->server_context().sst_received(gtid, 0); i->second->server_state().sst_received(gtid, 0);
server.server_context().sst_sent(gtid, 0); server.server_state().sst_sent(gtid, 0);
} }
std::string db::simulator::stats() const std::string db::simulator::stats() const
@ -99,22 +99,22 @@ void db::simulator::start()
boost::filesystem::create_directory(dir); boost::filesystem::create_directory(dir);
db::server& server(*it.first->second); db::server& server(*it.first->second);
server.server_context().debug_log_level(params_.debug_log_level); server.server_state().debug_log_level(params_.debug_log_level);
std::string server_options(params_.wsrep_provider_options); std::string server_options(params_.wsrep_provider_options);
if (server.server_context().load_provider( if (server.server_state().load_provider(
params_.wsrep_provider, server_options)) params_.wsrep_provider, server_options))
{ {
throw wsrep::runtime_error("Failed to load provider"); throw wsrep::runtime_error("Failed to load provider");
} }
if (server.server_context().connect("sim_cluster", cluster_address, "", if (server.server_state().connect("sim_cluster", cluster_address, "",
i == 0)) i == 0))
{ {
throw wsrep::runtime_error("Failed to connect"); throw wsrep::runtime_error("Failed to connect");
} }
server.start_applier(); server.start_applier();
server.server_context().wait_until_state( server.server_state().wait_until_state(
wsrep::server_context::s_synced); wsrep::server_state::s_synced);
} }
// Start client threads // Start client threads
@ -150,18 +150,18 @@ void db::simulator::stop()
{ {
db::server& server(*i.second); db::server& server(*i.second);
wsrep::log_info() << "Status for server: " wsrep::log_info() << "Status for server: "
<< server.server_context().id(); << server.server_state().id();
auto status(server.server_context().provider().status()); auto status(server.server_state().provider().status());
for_each(status.begin(), status.end(), for_each(status.begin(), status.end(),
[](const wsrep::provider::status_variable& sv) [](const wsrep::provider::status_variable& sv)
{ {
wsrep::log() << sv.name() << " = " << sv.value(); wsrep::log() << sv.name() << " = " << sv.value();
}); });
server.server_context().disconnect(); server.server_state().disconnect();
server.server_context().wait_until_state( server.server_state().wait_until_state(
wsrep::server_context::s_disconnected); wsrep::server_state::s_disconnected);
server.stop_applier(); server.stop_applier();
server.server_context().unload_provider(); server.server_state().unload_provider();
} }
} }

View File

@ -38,7 +38,7 @@
#ifndef WSREP_CLIENT_CONTEXT_HPP #ifndef WSREP_CLIENT_CONTEXT_HPP
#define WSREP_CLIENT_CONTEXT_HPP #define WSREP_CLIENT_CONTEXT_HPP
#include "server_context.hpp" #include "server_state.hpp"
#include "provider.hpp" #include "provider.hpp"
#include "transaction.hpp" #include "transaction.hpp"
#include "client_id.hpp" #include "client_id.hpp"
@ -51,7 +51,7 @@
namespace wsrep namespace wsrep
{ {
class server_context; class server_state;
class provider; class provider;
enum client_error enum client_error
@ -475,8 +475,8 @@ namespace wsrep
* *
* @return Reference to server context. * @return Reference to server context.
*/ */
wsrep::server_context& server_context() const wsrep::server_state& server_state() const
{ return server_context_; } { return server_state_; }
/** /**
* Get reference to the Provider which is associated * Get reference to the Provider which is associated
@ -521,7 +521,7 @@ namespace wsrep
int debug_log_level() const int debug_log_level() const
{ {
return std::max(debug_log_level_, return std::max(debug_log_level_,
server_context_.debug_log_level()); server_state_.debug_log_level());
} }
void reset_error() void reset_error()
@ -539,13 +539,13 @@ namespace wsrep
* can be called from derived class constructors only. * can be called from derived class constructors only.
*/ */
client_state(wsrep::mutex& mutex, client_state(wsrep::mutex& mutex,
wsrep::server_context& server_context, wsrep::server_state& server_state,
wsrep::client_service& client_service, wsrep::client_service& client_service,
const client_id& id, const client_id& id,
enum mode mode) enum mode mode)
: thread_id_(wsrep::this_thread::get_id()) : thread_id_(wsrep::this_thread::get_id())
, mutex_(mutex) , mutex_(mutex)
, server_context_(server_context) , server_state_(server_state)
, client_service_(client_service) , client_service_(client_service)
, id_(id) , id_(id)
, mode_(mode) , mode_(mode)
@ -575,7 +575,7 @@ namespace wsrep
wsrep::thread::id thread_id_; wsrep::thread::id thread_id_;
wsrep::mutex& mutex_; wsrep::mutex& mutex_;
wsrep::server_context& server_context_; wsrep::server_state& server_state_;
wsrep::client_service& client_service_; wsrep::client_service& client_service_;
client_id id_; client_id id_;
enum mode mode_; enum mode mode_;

View File

@ -21,7 +21,7 @@
namespace wsrep namespace wsrep
{ {
class server_context; class server_state;
class stid class stid
{ {
@ -195,8 +195,8 @@ namespace wsrep
static const int snapshot = (1 << 7); static const int snapshot = (1 << 7);
}; };
provider(wsrep::server_context& server_context) provider(wsrep::server_state& server_state)
: server_context_(server_context) : server_state_(server_state)
{ } { }
virtual ~provider() { } virtual ~provider() { }
// Provider state management // Provider state management
@ -260,11 +260,11 @@ namespace wsrep
* @param provider_options Initial options to provider * @param provider_options Initial options to provider
*/ */
static provider* make_provider( static provider* make_provider(
wsrep::server_context&, wsrep::server_state&,
const std::string& provider_spec, const std::string& provider_spec,
const std::string& provider_options); const std::string& provider_options);
protected: protected:
wsrep::server_context& server_context_; wsrep::server_state& server_state_;
}; };
static inline std::string flags_to_string(int flags) static inline std::string flags_to_string(int flags)

View File

@ -2,7 +2,7 @@
// Copyright (C) 2018 Codership Oy <info@codership.com> // Copyright (C) 2018 Codership Oy <info@codership.com>
// //
/** @file server_context.hpp /** @file server_state.hpp
* *
* Server Context Abstraction * Server Context Abstraction
* ========================== * ==========================
@ -86,7 +86,7 @@ namespace wsrep
* *
* *
*/ */
class server_context class server_state
{ {
public: public:
/** /**
@ -155,7 +155,7 @@ namespace wsrep
}; };
virtual ~server_context(); virtual ~server_state();
/** /**
* Return human readable server name. * Return human readable server name.
* *
@ -292,7 +292,7 @@ namespace wsrep
/** /**
* Wait until server reaches given state. * Wait until server reaches given state.
*/ */
void wait_until_state(wsrep::server_context::state) const; void wait_until_state(wsrep::server_state::state) const;
/** /**
* Virtual method to return true if the configured SST * Virtual method to return true if the configured SST
@ -403,7 +403,7 @@ namespace wsrep
* data files. * data files.
* @param rollback_mode Rollback mode which server operates on. * @param rollback_mode Rollback mode which server operates on.
*/ */
server_context(wsrep::mutex& mutex, server_state(wsrep::mutex& mutex,
wsrep::condition_variable& cond, wsrep::condition_variable& cond,
const std::string& name, const std::string& name,
const std::string& id, const std::string& id,
@ -426,8 +426,8 @@ namespace wsrep
private: private:
server_context(const server_context&); server_state(const server_state&);
server_context& operator=(const server_context&); server_state& operator=(const server_state&);
void state(wsrep::unique_lock<wsrep::mutex>&, enum state); void state(wsrep::unique_lock<wsrep::mutex>&, enum state);
@ -449,30 +449,30 @@ namespace wsrep
class client_deleter class client_deleter
{ {
public: public:
client_deleter(wsrep::server_context& server_context) client_deleter(wsrep::server_state& server_state)
: server_context_(server_context) : server_state_(server_state)
{ } { }
void operator()(wsrep::client_state* client_state) void operator()(wsrep::client_state* client_state)
{ {
server_context_.release_client_state(client_state); server_state_.release_client_state(client_state);
} }
private: private:
wsrep::server_context& server_context_; wsrep::server_state& server_state_;
}; };
static inline std::string to_string(enum wsrep::server_context::state state) static inline std::string to_string(enum wsrep::server_state::state state)
{ {
switch (state) switch (state)
{ {
case wsrep::server_context::s_disconnected: return "disconnected"; case wsrep::server_state::s_disconnected: return "disconnected";
case wsrep::server_context::s_initializing: return "initilizing"; case wsrep::server_state::s_initializing: return "initilizing";
case wsrep::server_context::s_initialized: return "initilized"; case wsrep::server_state::s_initialized: return "initilized";
case wsrep::server_context::s_connected: return "connected"; case wsrep::server_state::s_connected: return "connected";
case wsrep::server_context::s_joiner: return "joiner"; case wsrep::server_state::s_joiner: return "joiner";
case wsrep::server_context::s_joined: return "joined"; case wsrep::server_state::s_joined: return "joined";
case wsrep::server_context::s_donor: return "donor"; case wsrep::server_state::s_donor: return "donor";
case wsrep::server_context::s_synced: return "synced"; case wsrep::server_state::s_synced: return "synced";
case wsrep::server_context::s_disconnecting: return "disconnecting"; case wsrep::server_state::s_disconnecting: return "disconnecting";
} }
return "unknown"; return "unknown";
} }

View File

@ -6,7 +6,7 @@
#define WSREP_TRANSACTION_CONTEXT_HPP #define WSREP_TRANSACTION_CONTEXT_HPP
#include "provider.hpp" #include "provider.hpp"
#include "server_context.hpp" #include "server_state.hpp"
#include "transaction_id.hpp" #include "transaction_id.hpp"
#include "streaming_context.hpp" #include "streaming_context.hpp"
#include "lock.hpp" #include "lock.hpp"

View File

@ -7,7 +7,7 @@ add_library(wsrep-lib
id.cpp id.cpp
logger.cpp logger.cpp
provider.cpp provider.cpp
server_context.cpp server_state.cpp
transaction.cpp transaction.cpp
wsrep_provider_v26.cpp) wsrep_provider_v26.cpp)
target_link_libraries(wsrep-lib wsrep_api_v26 pthread dl) target_link_libraries(wsrep-lib wsrep_api_v26 pthread dl)

View File

@ -12,7 +12,7 @@
wsrep::provider& wsrep::client_state::provider() const wsrep::provider& wsrep::client_state::provider() const
{ {
return server_context_.provider(); return server_state_.provider();
} }
void wsrep::client_state::override_error(enum wsrep::client_error error) void wsrep::client_state::override_error(enum wsrep::client_error error)
@ -32,7 +32,7 @@ int wsrep::client_state::before_command()
wsrep::unique_lock<wsrep::mutex> lock(mutex_); wsrep::unique_lock<wsrep::mutex> lock(mutex_);
debug_log_state("before_command: enter"); debug_log_state("before_command: enter");
assert(state_ == s_idle); assert(state_ == s_idle);
if (server_context_.rollback_mode() == wsrep::server_context::rm_sync) if (server_state_.rollback_mode() == wsrep::server_state::rm_sync)
{ {
/** /**
* @todo Wait until the possible synchronous rollback * @todo Wait until the possible synchronous rollback
@ -48,14 +48,14 @@ int wsrep::client_state::before_command()
(transaction_.state() == wsrep::transaction::s_executing || (transaction_.state() == wsrep::transaction::s_executing ||
transaction_.state() == wsrep::transaction::s_aborted || transaction_.state() == wsrep::transaction::s_aborted ||
(transaction_.state() == wsrep::transaction::s_must_abort && (transaction_.state() == wsrep::transaction::s_must_abort &&
server_context_.rollback_mode() == wsrep::server_context::rm_async))); server_state_.rollback_mode() == wsrep::server_state::rm_async)));
if (transaction_.active()) if (transaction_.active())
{ {
if (transaction_.state() == wsrep::transaction::s_must_abort) if (transaction_.state() == wsrep::transaction::s_must_abort)
{ {
assert(server_context_.rollback_mode() == assert(server_state_.rollback_mode() ==
wsrep::server_context::rm_async); wsrep::server_state::rm_async);
override_error(wsrep::e_deadlock_error); override_error(wsrep::e_deadlock_error);
lock.unlock(); lock.unlock();
client_service_.rollback(*this); client_service_.rollback(*this);
@ -139,7 +139,7 @@ int wsrep::client_state::before_statement()
* server synced state. * server synced state.
*/ */
if (allow_dirty_reads_ == false && if (allow_dirty_reads_ == false &&
server_context_.state() != wsrep::server_context::s_synced) server_state_.state() != wsrep::server_state::s_synced)
{ {
return 1; return 1;
} }
@ -192,7 +192,7 @@ void wsrep::client_state::debug_log_state(const char* context) const
if (debug_log_level() >= 1) if (debug_log_level() >= 1)
{ {
wsrep::log_debug() << "client_state: " << context wsrep::log_debug() << "client_state: " << context
<< ": server: " << server_context_.name() << ": server: " << server_state_.name()
<< " client: " << id_.get() << " client: " << id_.get()
<< " current_error: " << current_error_; << " current_error: " << current_error_;
} }

View File

@ -8,14 +8,14 @@
#include "wsrep_provider_v26.hpp" #include "wsrep_provider_v26.hpp"
wsrep::provider* wsrep::provider::make_provider( wsrep::provider* wsrep::provider::make_provider(
wsrep::server_context& server_context, wsrep::server_state& server_state,
const std::string& provider_spec, const std::string& provider_spec,
const std::string& provider_options) const std::string& provider_options)
{ {
try try
{ {
return new wsrep::wsrep_provider_v26( return new wsrep::wsrep_provider_v26(
server_context, provider_options, provider_spec); server_state, provider_options, provider_spec);
} }
catch (const wsrep::runtime_error& e) catch (const wsrep::runtime_error& e)
{ {

View File

@ -1,85 +0,0 @@
//
// Copyright (C) 2018 Codership Oy <info@codership.com>
//
#include "mock_server_context.hpp"
#include <boost/test/unit_test.hpp>
namespace
{
struct applying_server_fixture
{
applying_server_fixture()
: sc("s1", "s1",
wsrep::server_context::rm_sync)
, cc(sc,
wsrep::client_id(1),
wsrep::client_state::m_applier,
false)
, ws_handle(1, (void*)1)
, ws_meta(wsrep::gtid(wsrep::id("1"), wsrep::seqno(1)),
wsrep::stid(wsrep::id("1"), 1, 1),
wsrep::seqno(0),
wsrep::provider::flag::start_transaction |
wsrep::provider::flag::commit)
{
cc.start_transaction(ws_handle, ws_meta);
}
wsrep::mock_server_context sc;
wsrep::mock_client_state cc;
wsrep::ws_handle ws_handle;
wsrep::ws_meta ws_meta;
};
}
// Test on_apply() method for 1pc
BOOST_FIXTURE_TEST_CASE(server_context_applying_1pc,
applying_server_fixture)
{
char buf[1] = { 1 };
BOOST_REQUIRE(sc.on_apply(cc, ws_handle, ws_meta,
wsrep::const_buffer(buf, 1)) == 0);
const wsrep::transaction& txc(cc.transaction());
// ::abort();
BOOST_REQUIRE_MESSAGE(
txc.state() == wsrep::transaction::s_committed,
"Transaction state " << txc.state() << " not committed");
}
// Test on_apply() method for 2pc
BOOST_FIXTURE_TEST_CASE(server_context_applying_2pc,
applying_server_fixture)
{
char buf[1] = { 1 };
BOOST_REQUIRE(sc.on_apply(cc, ws_handle, ws_meta,
wsrep::const_buffer(buf, 1)) == 0);
const wsrep::transaction& txc(cc.transaction());
BOOST_REQUIRE(txc.state() == wsrep::transaction::s_committed);
}
// Test on_apply() method for 1pc transaction which
// fails applying and rolls back
BOOST_FIXTURE_TEST_CASE(server_context_applying_1pc_rollback,
applying_server_fixture)
{
cc.fail_next_applying_ = true;
char buf[1] = { 1 };
BOOST_REQUIRE(sc.on_apply(cc, ws_handle, ws_meta,
wsrep::const_buffer(buf, 1)) == 1);
const wsrep::transaction& txc(cc.transaction());
BOOST_REQUIRE(txc.state() == wsrep::transaction::s_aborted);
}
// Test on_apply() method for 2pc transaction which
// fails applying and rolls back
BOOST_FIXTURE_TEST_CASE(server_context_applying_2pc_rollback,
applying_server_fixture)
{
cc.fail_next_applying_ = true;
char buf[1] = { 1 };
BOOST_REQUIRE(sc.on_apply(cc, ws_handle, ws_meta,
wsrep::const_buffer(buf, 1)) == 1);
const wsrep::transaction& txc(cc.transaction());
BOOST_REQUIRE(txc.state() == wsrep::transaction::s_aborted);
}

View File

@ -2,7 +2,7 @@
// Copyright (C) 2018 Codership Oy <info@codership.com> // Copyright (C) 2018 Codership Oy <info@codership.com>
// //
#include "wsrep/server_context.hpp" #include "wsrep/server_state.hpp"
#include "wsrep/client_state.hpp" #include "wsrep/client_state.hpp"
#include "wsrep/transaction.hpp" #include "wsrep/transaction.hpp"
#include "wsrep/view.hpp" #include "wsrep/view.hpp"
@ -18,7 +18,7 @@ namespace
} }
int wsrep::server_context::load_provider(const std::string& provider_spec, int wsrep::server_state::load_provider(const std::string& provider_spec,
const std::string& provider_options) const std::string& provider_options)
{ {
wsrep::log_info() << "Loading provider " << provider_spec; wsrep::log_info() << "Loading provider " << provider_spec;
@ -26,13 +26,13 @@ int wsrep::server_context::load_provider(const std::string& provider_spec,
return (provider_ ? 0 : 1); return (provider_ ? 0 : 1);
} }
void wsrep::server_context::unload_provider() void wsrep::server_state::unload_provider()
{ {
delete provider_; delete provider_;
provider_ = 0; provider_ = 0;
} }
int wsrep::server_context::connect(const std::string& cluster_name, int wsrep::server_state::connect(const std::string& cluster_name,
const std::string& cluster_address, const std::string& cluster_address,
const std::string& state_donor, const std::string& state_donor,
bool bootstrap) bool bootstrap)
@ -41,7 +41,7 @@ int wsrep::server_context::connect(const std::string& cluster_name,
bootstrap); bootstrap);
} }
int wsrep::server_context::disconnect() int wsrep::server_state::disconnect()
{ {
{ {
wsrep::unique_lock<wsrep::mutex> lock(mutex_); wsrep::unique_lock<wsrep::mutex> lock(mutex_);
@ -50,22 +50,22 @@ int wsrep::server_context::disconnect()
return provider().disconnect(); return provider().disconnect();
} }
wsrep::server_context::~server_context() wsrep::server_state::~server_state()
{ {
delete provider_; delete provider_;
} }
void wsrep::server_context::sst_sent(const wsrep::gtid& gtid, int error) void wsrep::server_state::sst_sent(const wsrep::gtid& gtid, int error)
{ {
provider_->sst_sent(gtid, error); provider_->sst_sent(gtid, error);
} }
void wsrep::server_context::sst_received(const wsrep::gtid& gtid, int error) void wsrep::server_state::sst_received(const wsrep::gtid& gtid, int error)
{ {
provider_->sst_received(gtid, error); provider_->sst_received(gtid, error);
} }
void wsrep::server_context::wait_until_state( void wsrep::server_state::wait_until_state(
enum wsrep::server_context::state state) const enum wsrep::server_state::state state) const
{ {
wsrep::unique_lock<wsrep::mutex> lock(mutex_); wsrep::unique_lock<wsrep::mutex> lock(mutex_);
++state_waiters_[state]; ++state_waiters_[state];
@ -77,14 +77,14 @@ void wsrep::server_context::wait_until_state(
cond_.notify_all(); cond_.notify_all();
} }
void wsrep::server_context::on_connect() void wsrep::server_state::on_connect()
{ {
wsrep::log() << "Server " << name_ << " connected to cluster"; wsrep::log() << "Server " << name_ << " connected to cluster";
wsrep::unique_lock<wsrep::mutex> lock(mutex_); wsrep::unique_lock<wsrep::mutex> lock(mutex_);
state(lock, s_connected); state(lock, s_connected);
} }
void wsrep::server_context::on_view(const wsrep::view& view) void wsrep::server_state::on_view(const wsrep::view& view)
{ {
wsrep::log() << "================================================\nView:\n" wsrep::log() << "================================================\nView:\n"
<< "id: " << view.id() << "\n" << "id: " << view.id() << "\n"
@ -107,7 +107,7 @@ void wsrep::server_context::on_view(const wsrep::view& view)
} }
} }
void wsrep::server_context::on_sync() void wsrep::server_state::on_sync()
{ {
wsrep::log() << "Server " << name_ << " synced with group"; wsrep::log() << "Server " << name_ << " synced with group";
wsrep::unique_lock<wsrep::mutex> lock(mutex_); wsrep::unique_lock<wsrep::mutex> lock(mutex_);
@ -117,7 +117,7 @@ void wsrep::server_context::on_sync()
} }
} }
int wsrep::server_context::on_apply( int wsrep::server_state::on_apply(
wsrep::client_state& client_state, wsrep::client_state& client_state,
const wsrep::ws_handle& ws_handle, const wsrep::ws_handle& ws_handle,
const wsrep::ws_meta& ws_meta, const wsrep::ws_meta& ws_meta,
@ -273,7 +273,7 @@ int wsrep::server_context::on_apply(
return ret; return ret;
} }
bool wsrep::server_context::statement_allowed_for_streaming( bool wsrep::server_state::statement_allowed_for_streaming(
const wsrep::client_state&, const wsrep::client_state&,
const wsrep::transaction&) const const wsrep::transaction&) const
{ {
@ -281,7 +281,7 @@ bool wsrep::server_context::statement_allowed_for_streaming(
return false; return false;
} }
void wsrep::server_context::start_streaming_applier( void wsrep::server_state::start_streaming_applier(
const wsrep::id& server_id, const wsrep::id& server_id,
const wsrep::transaction_id& transaction_id, const wsrep::transaction_id& transaction_id,
wsrep::client_state* client_state) wsrep::client_state* client_state)
@ -296,7 +296,7 @@ void wsrep::server_context::start_streaming_applier(
} }
} }
void wsrep::server_context::stop_streaming_applier( void wsrep::server_state::stop_streaming_applier(
const wsrep::id& server_id, const wsrep::id& server_id,
const wsrep::transaction_id& transaction_id) const wsrep::transaction_id& transaction_id)
{ {
@ -314,7 +314,7 @@ void wsrep::server_context::stop_streaming_applier(
} }
} }
wsrep::client_state* wsrep::server_context::find_streaming_applier( wsrep::client_state* wsrep::server_state::find_streaming_applier(
const wsrep::id& server_id, const wsrep::id& server_id,
const wsrep::transaction_id& transaction_id) const const wsrep::transaction_id& transaction_id) const
{ {
@ -325,9 +325,9 @@ wsrep::client_state* wsrep::server_context::find_streaming_applier(
// Private // Private
void wsrep::server_context::state( void wsrep::server_state::state(
wsrep::unique_lock<wsrep::mutex>& lock WSREP_UNUSED, wsrep::unique_lock<wsrep::mutex>& lock WSREP_UNUSED,
enum wsrep::server_context::state state) enum wsrep::server_state::state state)
{ {
assert(lock.owns_lock()); assert(lock.owns_lock());
static const char allowed[n_states_][n_states_] = static const char allowed[n_states_][n_states_] =

View File

@ -4,7 +4,7 @@
#include "wsrep/transaction.hpp" #include "wsrep/transaction.hpp"
#include "wsrep/client_state.hpp" #include "wsrep/client_state.hpp"
#include "wsrep/server_context.hpp" #include "wsrep/server_state.hpp"
#include "wsrep/key.hpp" #include "wsrep/key.hpp"
#include "wsrep/logger.hpp" #include "wsrep/logger.hpp"
#include "wsrep/compiler.hpp" #include "wsrep/compiler.hpp"
@ -163,7 +163,7 @@ int wsrep::transaction::before_prepare(
client_state_.debug_crash( client_state_.debug_crash(
"crash_last_fragment_commit_before_fragment_removal"); "crash_last_fragment_commit_before_fragment_removal");
lock.unlock(); lock.unlock();
if (client_state_.server_context().statement_allowed_for_streaming( if (client_state_.server_state().statement_allowed_for_streaming(
client_state_, *this)) client_state_, *this))
{ {
client_state_.override_error(wsrep::e_error_during_commit); client_state_.override_error(wsrep::e_error_during_commit);
@ -626,8 +626,8 @@ bool wsrep::transaction::bf_abort(
{ {
bf_abort_client_state_ = client_state_.state(); bf_abort_client_state_ = client_state_.state();
if (client_state_.state() == wsrep::client_state::s_idle && if (client_state_.state() == wsrep::client_state::s_idle &&
client_state_.server_context().rollback_mode() == client_state_.server_state().rollback_mode() ==
wsrep::server_context::rm_sync) wsrep::server_state::rm_sync)
{ {
// We need to change the state to aborting under the // We need to change the state to aborting under the
// lock protection to avoid a race between client thread, // lock protection to avoid a race between client thread,
@ -636,7 +636,7 @@ bool wsrep::transaction::bf_abort(
// rollbacker gets control. // rollbacker gets control.
state(lock, wsrep::transaction::s_aborting); state(lock, wsrep::transaction::s_aborting);
lock.unlock(); lock.unlock();
client_state_.server_context().background_rollback(client_state_); client_state_.server_state().background_rollback(client_state_);
} }
} }
return ret; return ret;
@ -720,10 +720,10 @@ int wsrep::transaction::certify_fragment(
// Switch temporarily to sr_transaction, switch back // Switch temporarily to sr_transaction, switch back
// to original when this goes out of scope // to original when this goes out of scope
// std::auto_ptr<wsrep::client_state> sr_client_state( // std::auto_ptr<wsrep::client_state> sr_client_state(
// client_state_.server_context().local_client_state()); // client_state_.server_state().local_client_state());
wsrep::scoped_client_state<wsrep::client_deleter> sr_client_state_scope( wsrep::scoped_client_state<wsrep::client_deleter> sr_client_state_scope(
client_state_.server_context().local_client_state(), client_state_.server_state().local_client_state(),
wsrep::client_deleter(client_state_.server_context())); wsrep::client_deleter(client_state_.server_state()));
wsrep::client_state& sr_client_state( wsrep::client_state& sr_client_state(
sr_client_state_scope.client_state()); sr_client_state_scope.client_state());
wsrep::client_state_switch client_state_switch( wsrep::client_state_switch client_state_switch(
@ -929,9 +929,9 @@ void wsrep::transaction::streaming_rollback()
{ {
assert(streaming_context_.rolled_back() == false); assert(streaming_context_.rolled_back() == false);
wsrep::client_state* sac( wsrep::client_state* sac(
client_state_.server_context().streaming_applier_client_state()); client_state_.server_state().streaming_applier_client_state());
client_state_.server_context().start_streaming_applier( client_state_.server_state().start_streaming_applier(
client_state_.server_context().id(), id(), sac); client_state_.server_state().id(), id(), sac);
sac->adopt_transaction(*this); sac->adopt_transaction(*this);
streaming_context_.cleanup(); streaming_context_.cleanup();
// Replicate rollback fragment // Replicate rollback fragment
@ -963,7 +963,7 @@ void wsrep::transaction::debug_log_state(
{ {
WSREP_TC_LOG_DEBUG( WSREP_TC_LOG_DEBUG(
1, context 1, context
<< ": server: " << client_state_.server_context().name() << ": server: " << client_state_.server_state().name()
<< " client: " << client_state_.id().get() << " client: " << client_state_.id().get()
<< " trx: " << int64_t(id_.get()) << " trx: " << int64_t(id_.get())
<< " state: " << wsrep::to_string(state_) << " state: " << wsrep::to_string(state_)

View File

@ -4,7 +4,7 @@
#include "wsrep_provider_v26.hpp" #include "wsrep_provider_v26.hpp"
#include "wsrep/server_context.hpp" #include "wsrep/server_state.hpp"
#include "wsrep/client_state.hpp" #include "wsrep/client_state.hpp"
#include "wsrep/view.hpp" #include "wsrep/view.hpp"
#include "wsrep/exception.hpp" #include "wsrep/exception.hpp"
@ -240,14 +240,14 @@ namespace
const wsrep_view_info_t* view __attribute((unused))) const wsrep_view_info_t* view __attribute((unused)))
{ {
assert(app_ctx); assert(app_ctx);
wsrep::server_context& server_context( wsrep::server_state& server_state(
*reinterpret_cast<wsrep::server_context*>(app_ctx)); *reinterpret_cast<wsrep::server_state*>(app_ctx));
// //
// TODO: Fetch server id and group id from view infor // TODO: Fetch server id and group id from view infor
// //
try try
{ {
server_context.on_connect(); server_state.on_connect();
return WSREP_CB_SUCCESS; return WSREP_CB_SUCCESS;
} }
catch (const wsrep::runtime_error& e) catch (const wsrep::runtime_error& e)
@ -265,12 +265,12 @@ namespace
{ {
assert(app_ctx); assert(app_ctx);
assert(view_info); assert(view_info);
wsrep::server_context& server_context( wsrep::server_state& server_state(
*reinterpret_cast<wsrep::server_context*>(app_ctx)); *reinterpret_cast<wsrep::server_state*>(app_ctx));
try try
{ {
wsrep::view view(*view_info); wsrep::view view(*view_info);
server_context.on_view(view); server_state.on_view(view);
return WSREP_CB_SUCCESS; return WSREP_CB_SUCCESS;
} }
catch (const wsrep::runtime_error& e) catch (const wsrep::runtime_error& e)
@ -284,12 +284,12 @@ namespace
void **sst_req, size_t* sst_req_len) void **sst_req, size_t* sst_req_len)
{ {
assert(app_ctx); assert(app_ctx);
wsrep::server_context& server_context( wsrep::server_state& server_state(
*reinterpret_cast<wsrep::server_context*>(app_ctx)); *reinterpret_cast<wsrep::server_state*>(app_ctx));
try try
{ {
std::string req(server_context.on_sst_required()); std::string req(server_state.on_sst_required());
*sst_req = ::strdup(req.c_str()); *sst_req = ::strdup(req.c_str());
*sst_req_len = strlen(req.c_str()); *sst_req_len = strlen(req.c_str());
return WSREP_CB_SUCCESS; return WSREP_CB_SUCCESS;
@ -326,7 +326,7 @@ namespace
meta->stid.conn), wsrep::seqno(seqno_from_native(meta->depends_on)), meta->stid.conn), wsrep::seqno(seqno_from_native(meta->depends_on)),
map_flags_from_native(flags)); map_flags_from_native(flags));
if (ret == WSREP_CB_SUCCESS && if (ret == WSREP_CB_SUCCESS &&
client_state->server_context().on_apply( client_state->server_state().on_apply(
*client_state, ws_handle, ws_meta, data)) *client_state, ws_handle, ws_meta, data))
{ {
ret = WSREP_CB_FAILURE; ret = WSREP_CB_FAILURE;
@ -337,11 +337,11 @@ namespace
wsrep_cb_status_t synced_cb(void* app_ctx) wsrep_cb_status_t synced_cb(void* app_ctx)
{ {
assert(app_ctx); assert(app_ctx);
wsrep::server_context& server_context( wsrep::server_state& server_state(
*reinterpret_cast<wsrep::server_context*>(app_ctx)); *reinterpret_cast<wsrep::server_state*>(app_ctx));
try try
{ {
server_context.on_sync(); server_state.on_sync();
return WSREP_CB_SUCCESS; return WSREP_CB_SUCCESS;
} }
catch (const wsrep::runtime_error& e) catch (const wsrep::runtime_error& e)
@ -360,8 +360,8 @@ namespace
bool bypass) bool bypass)
{ {
assert(app_ctx); assert(app_ctx);
wsrep::server_context& server_context( wsrep::server_state& server_state(
*reinterpret_cast<wsrep::server_context*>(app_ctx)); *reinterpret_cast<wsrep::server_state*>(app_ctx));
try try
{ {
std::string req(reinterpret_cast<const char*>(req_buf->ptr), std::string req(reinterpret_cast<const char*>(req_buf->ptr),
@ -369,7 +369,7 @@ namespace
wsrep::gtid gtid(wsrep::id(req_gtid->uuid.data, wsrep::gtid gtid(wsrep::id(req_gtid->uuid.data,
sizeof(req_gtid->uuid.data)), sizeof(req_gtid->uuid.data)),
wsrep::seqno(req_gtid->seqno)); wsrep::seqno(req_gtid->seqno));
server_context.on_sst_request(req, gtid, bypass); server_state.on_sst_request(req, gtid, bypass);
return WSREP_CB_SUCCESS; return WSREP_CB_SUCCESS;
} }
catch (const wsrep::runtime_error& e) catch (const wsrep::runtime_error& e)
@ -380,19 +380,19 @@ namespace
} }
wsrep::wsrep_provider_v26::wsrep_provider_v26( wsrep::wsrep_provider_v26::wsrep_provider_v26(
wsrep::server_context& server_context, wsrep::server_state& server_state,
const std::string& provider_options, const std::string& provider_options,
const std::string& provider_spec) const std::string& provider_spec)
: provider(server_context) : provider(server_state)
, wsrep_() , wsrep_()
{ {
struct wsrep_init_args init_args; struct wsrep_init_args init_args;
memset(&init_args, 0, sizeof(init_args)); memset(&init_args, 0, sizeof(init_args));
init_args.app_ctx = &server_context; init_args.app_ctx = &server_state;
init_args.node_name = server_context_.name().c_str(); init_args.node_name = server_state_.name().c_str();
init_args.node_address = server_context_.address().c_str(); init_args.node_address = server_state_.address().c_str();
init_args.node_incoming = ""; init_args.node_incoming = "";
init_args.data_dir = server_context_.working_dir().c_str(); init_args.data_dir = server_state_.working_dir().c_str();
init_args.options = provider_options.c_str(); init_args.options = provider_options.c_str();
init_args.proto_ver = 1; init_args.proto_ver = 1;
init_args.state_id = 0; init_args.state_id = 0;

View File

@ -15,7 +15,7 @@ namespace wsrep
{ {
public: public:
wsrep_provider_v26(wsrep::server_context&, const std::string&, wsrep_provider_v26(wsrep::server_state&, const std::string&,
const std::string&); const std::string&);
~wsrep_provider_v26(); ~wsrep_provider_v26();
int connect(const std::string&, const std::string&, const std::string&, int connect(const std::string&, const std::string&, const std::string&,

View File

@ -5,7 +5,7 @@
#ifndef WSREP_TEST_CLIENT_CONTEXT_FIXTURE_HPP #ifndef WSREP_TEST_CLIENT_CONTEXT_FIXTURE_HPP
#define WSREP_TEST_CLIENT_CONTEXT_FIXTURE_HPP #define WSREP_TEST_CLIENT_CONTEXT_FIXTURE_HPP
#include "mock_server_context.hpp" #include "mock_server_state.hpp"
#include "mock_client_state.hpp" #include "mock_client_state.hpp"
@ -16,7 +16,7 @@ namespace
struct replicating_client_fixture_sync_rm struct replicating_client_fixture_sync_rm
{ {
replicating_client_fixture_sync_rm() replicating_client_fixture_sync_rm()
: sc("s1", "s1", wsrep::server_context::rm_sync) : sc("s1", "s1", wsrep::server_state::rm_sync)
, cc(sc, sc.client_service(), wsrep::client_id(1), , cc(sc, sc.client_service(), wsrep::client_id(1),
wsrep::client_state::m_replicating) wsrep::client_state::m_replicating)
, tc(cc.transaction()) , tc(cc.transaction())
@ -27,7 +27,7 @@ namespace
BOOST_REQUIRE(tc.active() == false); BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing); BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
} }
wsrep::mock_server_context sc; wsrep::mock_server_state sc;
wsrep::mock_client_state cc; wsrep::mock_client_state cc;
const wsrep::transaction& tc; const wsrep::transaction& tc;
}; };
@ -35,7 +35,7 @@ namespace
struct replicating_client_fixture_async_rm struct replicating_client_fixture_async_rm
{ {
replicating_client_fixture_async_rm() replicating_client_fixture_async_rm()
: sc("s1", "s1", wsrep::server_context::rm_async) : sc("s1", "s1", wsrep::server_state::rm_async)
, cc(sc, sc.client_service(), wsrep::client_id(1), , cc(sc, sc.client_service(), wsrep::client_id(1),
wsrep::client_state::m_replicating) wsrep::client_state::m_replicating)
, tc(cc.transaction()) , tc(cc.transaction())
@ -46,7 +46,7 @@ namespace
BOOST_REQUIRE(tc.active() == false); BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing); BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
} }
wsrep::mock_server_context sc; wsrep::mock_server_state sc;
wsrep::mock_client_state cc; wsrep::mock_client_state cc;
const wsrep::transaction& tc; const wsrep::transaction& tc;
}; };
@ -54,7 +54,7 @@ namespace
struct replicating_client_fixture_2pc struct replicating_client_fixture_2pc
{ {
replicating_client_fixture_2pc() replicating_client_fixture_2pc()
: sc("s1", "s1", wsrep::server_context::rm_sync) : sc("s1", "s1", wsrep::server_state::rm_sync)
, cc(sc, sc.client_service(), wsrep::client_id(1), , cc(sc, sc.client_service(), wsrep::client_id(1),
wsrep::client_state::m_replicating) wsrep::client_state::m_replicating)
, tc(cc.transaction()) , tc(cc.transaction())
@ -66,7 +66,7 @@ namespace
BOOST_REQUIRE(tc.active() == false); BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing); BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
} }
wsrep::mock_server_context sc; wsrep::mock_server_state sc;
wsrep::mock_client_state cc; wsrep::mock_client_state cc;
const wsrep::transaction& tc; const wsrep::transaction& tc;
}; };
@ -74,7 +74,7 @@ namespace
struct replicating_client_fixture_autocommit struct replicating_client_fixture_autocommit
{ {
replicating_client_fixture_autocommit() replicating_client_fixture_autocommit()
: sc("s1", "s1", wsrep::server_context::rm_sync) : sc("s1", "s1", wsrep::server_state::rm_sync)
, cc(sc, sc.client_service(), wsrep::client_id(1), , cc(sc, sc.client_service(), wsrep::client_id(1),
wsrep::client_state::m_replicating) wsrep::client_state::m_replicating)
, tc(cc.transaction()) , tc(cc.transaction())
@ -86,7 +86,7 @@ namespace
BOOST_REQUIRE(tc.active() == false); BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing); BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
} }
wsrep::mock_server_context sc; wsrep::mock_server_state sc;
wsrep::mock_client_state cc; wsrep::mock_client_state cc;
const wsrep::transaction& tc; const wsrep::transaction& tc;
}; };
@ -95,7 +95,7 @@ namespace
{ {
applying_client_fixture() applying_client_fixture()
: sc("s1", "s1", : sc("s1", "s1",
wsrep::server_context::rm_async) wsrep::server_state::rm_async)
, cc(sc, sc.client_service(), , cc(sc, sc.client_service(),
wsrep::client_id(1), wsrep::client_id(1),
wsrep::client_state::m_high_priority) wsrep::client_state::m_high_priority)
@ -114,7 +114,7 @@ namespace
BOOST_REQUIRE(tc.certified() == true); BOOST_REQUIRE(tc.certified() == true);
BOOST_REQUIRE(tc.ordered() == true); BOOST_REQUIRE(tc.ordered() == true);
} }
wsrep::mock_server_context sc; wsrep::mock_server_state sc;
wsrep::mock_client_state cc; wsrep::mock_client_state cc;
const wsrep::transaction& tc; const wsrep::transaction& tc;
}; };
@ -123,7 +123,7 @@ namespace
{ {
applying_client_fixture_2pc() applying_client_fixture_2pc()
: sc("s1", "s1", : sc("s1", "s1",
wsrep::server_context::rm_async) wsrep::server_state::rm_async)
, cc(sc, sc.client_service(), , cc(sc, sc.client_service(),
wsrep::client_id(1), wsrep::client_id(1),
wsrep::client_state::m_high_priority) wsrep::client_state::m_high_priority)
@ -143,7 +143,7 @@ namespace
BOOST_REQUIRE(tc.certified() == true); BOOST_REQUIRE(tc.certified() == true);
BOOST_REQUIRE(tc.ordered() == true); BOOST_REQUIRE(tc.ordered() == true);
} }
wsrep::mock_server_context sc; wsrep::mock_server_state sc;
wsrep::mock_client_state cc; wsrep::mock_client_state cc;
const wsrep::transaction& tc; const wsrep::transaction& tc;
}; };
@ -151,7 +151,7 @@ namespace
struct streaming_client_fixture_row struct streaming_client_fixture_row
{ {
streaming_client_fixture_row() streaming_client_fixture_row()
: sc("s1", "s1", wsrep::server_context::rm_sync) : sc("s1", "s1", wsrep::server_state::rm_sync)
, cc(sc, sc.client_service(), wsrep::client_id(1), , cc(sc, sc.client_service(), wsrep::client_id(1),
wsrep::client_state::m_replicating) wsrep::client_state::m_replicating)
, tc(cc.transaction()) , tc(cc.transaction())
@ -163,7 +163,7 @@ namespace
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing); BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
cc.enable_streaming(wsrep::streaming_context::row, 1); cc.enable_streaming(wsrep::streaming_context::row, 1);
} }
wsrep::mock_server_context sc; wsrep::mock_server_state sc;
wsrep::mock_client_state cc; wsrep::mock_client_state cc;
const wsrep::transaction& tc; const wsrep::transaction& tc;
}; };
@ -171,7 +171,7 @@ namespace
struct streaming_client_fixture_byte struct streaming_client_fixture_byte
{ {
streaming_client_fixture_byte() streaming_client_fixture_byte()
: sc("s1", "s1", wsrep::server_context::rm_sync) : sc("s1", "s1", wsrep::server_state::rm_sync)
, cc(sc, sc.client_service(), wsrep::client_id(1), , cc(sc, sc.client_service(), wsrep::client_id(1),
wsrep::client_state::m_replicating) wsrep::client_state::m_replicating)
, tc(cc.transaction()) , tc(cc.transaction())
@ -183,7 +183,7 @@ namespace
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing); BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
cc.enable_streaming(wsrep::streaming_context::bytes, 1); cc.enable_streaming(wsrep::streaming_context::bytes, 1);
} }
wsrep::mock_server_context sc; wsrep::mock_server_state sc;
wsrep::mock_client_state cc; wsrep::mock_client_state cc;
const wsrep::transaction& tc; const wsrep::transaction& tc;
}; };
@ -191,7 +191,7 @@ namespace
struct streaming_client_fixture_statement struct streaming_client_fixture_statement
{ {
streaming_client_fixture_statement() streaming_client_fixture_statement()
: sc("s1", "s1", wsrep::server_context::rm_sync) : sc("s1", "s1", wsrep::server_state::rm_sync)
, cc(sc, sc.client_service(), wsrep::client_id(1), , cc(sc, sc.client_service(), wsrep::client_id(1),
wsrep::client_state::m_replicating) wsrep::client_state::m_replicating)
, tc(cc.transaction()) , tc(cc.transaction())
@ -204,7 +204,7 @@ namespace
cc.enable_streaming(wsrep::streaming_context::row, 1); cc.enable_streaming(wsrep::streaming_context::row, 1);
} }
wsrep::mock_server_context sc; wsrep::mock_server_state sc;
wsrep::mock_client_state cc; wsrep::mock_client_state cc;
const wsrep::transaction& tc; const wsrep::transaction& tc;
}; };

View File

@ -16,11 +16,11 @@ namespace wsrep
class mock_client_state : public wsrep::client_state class mock_client_state : public wsrep::client_state
{ {
public: public:
mock_client_state(wsrep::server_context& server_context, mock_client_state(wsrep::server_state& server_state,
wsrep::client_service& client_service, wsrep::client_service& client_service,
const wsrep::client_id& id, const wsrep::client_id& id,
enum wsrep::client_state::mode mode) enum wsrep::client_state::mode mode)
: wsrep::client_state(mutex_, server_context, client_service, id, mode) : wsrep::client_state(mutex_, server_state, client_service, id, mode)
// Note: Mutex is initialized only after passed // Note: Mutex is initialized only after passed
// to client_state constructor. // to client_state constructor.
, mutex_() , mutex_()

View File

@ -22,8 +22,8 @@ namespace wsrep
public: public:
typedef std::map<wsrep::transaction_id, wsrep::seqno> bf_abort_map; typedef std::map<wsrep::transaction_id, wsrep::seqno> bf_abort_map;
mock_provider(wsrep::server_context& server_context) mock_provider(wsrep::server_state& server_state)
: provider(server_context) : provider(server_state)
, certify_result_() , certify_result_()
, commit_order_enter_result_() , commit_order_enter_result_()
, commit_order_leave_result_() , commit_order_leave_result_()
@ -183,7 +183,7 @@ namespace wsrep
return replay_result_; return replay_result_;
} }
if (server_context_.on_apply(cc, tc.ws_handle(), ws_meta, if (server_state_.on_apply(cc, tc.ws_handle(), ws_meta,
wsrep::const_buffer())) wsrep::const_buffer()))
{ {
return wsrep::provider::error_fatal; return wsrep::provider::error_fatal;

View File

@ -5,7 +5,7 @@
#ifndef WSREP_MOCK_SERVER_CONTEXT_HPP #ifndef WSREP_MOCK_SERVER_CONTEXT_HPP
#define WSREP_MOCK_SERVER_CONTEXT_HPP #define WSREP_MOCK_SERVER_CONTEXT_HPP
#include "wsrep/server_context.hpp" #include "wsrep/server_state.hpp"
#include "mock_client_state.hpp" #include "mock_client_state.hpp"
#include "mock_provider.hpp" #include "mock_provider.hpp"
@ -13,13 +13,13 @@
namespace wsrep namespace wsrep
{ {
class mock_server_context : public wsrep::server_context class mock_server_state : public wsrep::server_state
{ {
public: public:
mock_server_context(const std::string& name, mock_server_state(const std::string& name,
const std::string& id, const std::string& id,
enum wsrep::server_context::rollback_mode rollback_mode) enum wsrep::server_state::rollback_mode rollback_mode)
: wsrep::server_context(mutex_, cond_, : wsrep::server_state(mutex_, cond_,
name, id, "", "./", rollback_mode) name, id, "", "./", rollback_mode)
, mutex_() , mutex_()
, cond_() , cond_()

View File

@ -2,7 +2,7 @@
// Copyright (C) 2018 Codership Oy <info@codership.com> // Copyright (C) 2018 Codership Oy <info@codership.com>
// //
#include "mock_server_context.hpp" #include "mock_server_state.hpp"
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
@ -12,7 +12,7 @@ namespace
{ {
applying_server_fixture() applying_server_fixture()
: sc("s1", "s1", : sc("s1", "s1",
wsrep::server_context::rm_sync) wsrep::server_state::rm_sync)
, cc(sc, sc.client_service(), , cc(sc, sc.client_service(),
wsrep::client_id(1), wsrep::client_id(1),
wsrep::client_state::m_high_priority) wsrep::client_state::m_high_priority)
@ -24,7 +24,7 @@ namespace
wsrep::provider::flag::commit) wsrep::provider::flag::commit)
{ {
} }
wsrep::mock_server_context sc; wsrep::mock_server_state sc;
wsrep::mock_client_state cc; wsrep::mock_client_state cc;
wsrep::ws_handle ws_handle; wsrep::ws_handle ws_handle;
wsrep::ws_meta ws_meta; wsrep::ws_meta ws_meta;
@ -32,7 +32,7 @@ namespace
} }
// Test on_apply() method for 1pc // Test on_apply() method for 1pc
BOOST_FIXTURE_TEST_CASE(server_context_applying_1pc, BOOST_FIXTURE_TEST_CASE(server_state_applying_1pc,
applying_server_fixture) applying_server_fixture)
{ {
char buf[1] = { 1 }; char buf[1] = { 1 };
@ -46,7 +46,7 @@ BOOST_FIXTURE_TEST_CASE(server_context_applying_1pc,
} }
// Test on_apply() method for 2pc // Test on_apply() method for 2pc
BOOST_FIXTURE_TEST_CASE(server_context_applying_2pc, BOOST_FIXTURE_TEST_CASE(server_state_applying_2pc,
applying_server_fixture) applying_server_fixture)
{ {
char buf[1] = { 1 }; char buf[1] = { 1 };
@ -58,7 +58,7 @@ BOOST_FIXTURE_TEST_CASE(server_context_applying_2pc,
// Test on_apply() method for 1pc transaction which // Test on_apply() method for 1pc transaction which
// fails applying and rolls back // fails applying and rolls back
BOOST_FIXTURE_TEST_CASE(server_context_applying_1pc_rollback, BOOST_FIXTURE_TEST_CASE(server_state_applying_1pc_rollback,
applying_server_fixture) applying_server_fixture)
{ {
sc.client_service().fail_next_applying_ = true; sc.client_service().fail_next_applying_ = true;
@ -71,7 +71,7 @@ BOOST_FIXTURE_TEST_CASE(server_context_applying_1pc_rollback,
// Test on_apply() method for 2pc transaction which // Test on_apply() method for 2pc transaction which
// fails applying and rolls back // fails applying and rolls back
BOOST_FIXTURE_TEST_CASE(server_context_applying_2pc_rollback, BOOST_FIXTURE_TEST_CASE(server_state_applying_2pc_rollback,
applying_server_fixture) applying_server_fixture)
{ {
sc.client_service().fail_next_applying_ = true; sc.client_service().fail_next_applying_ = true;
@ -82,10 +82,10 @@ BOOST_FIXTURE_TEST_CASE(server_context_applying_2pc_rollback,
BOOST_REQUIRE(txc.state() == wsrep::transaction::s_aborted); BOOST_REQUIRE(txc.state() == wsrep::transaction::s_aborted);
} }
BOOST_AUTO_TEST_CASE(server_context_streaming) BOOST_AUTO_TEST_CASE(server_state_streaming)
{ {
wsrep::mock_server_context sc("s1", "s1", wsrep::mock_server_state sc("s1", "s1",
wsrep::server_context::rm_sync); wsrep::server_state::rm_sync);
wsrep::mock_client_state cc(sc, wsrep::mock_client_state cc(sc,
sc.client_service(), sc.client_service(),
wsrep::client_id(1), wsrep::client_id(1),
@ -116,26 +116,26 @@ BOOST_AUTO_TEST_CASE(server_context_streaming)
} }
BOOST_AUTO_TEST_CASE(server_context_state_strings) BOOST_AUTO_TEST_CASE(server_state_state_strings)
{ {
BOOST_REQUIRE(wsrep::to_string( BOOST_REQUIRE(wsrep::to_string(
wsrep::server_context::s_disconnected) == "disconnected"); wsrep::server_state::s_disconnected) == "disconnected");
BOOST_REQUIRE(wsrep::to_string( BOOST_REQUIRE(wsrep::to_string(
wsrep::server_context::s_initializing) == "initilizing"); wsrep::server_state::s_initializing) == "initilizing");
BOOST_REQUIRE(wsrep::to_string( BOOST_REQUIRE(wsrep::to_string(
wsrep::server_context::s_initialized) == "initilized"); wsrep::server_state::s_initialized) == "initilized");
BOOST_REQUIRE(wsrep::to_string( BOOST_REQUIRE(wsrep::to_string(
wsrep::server_context::s_connected) == "connected"); wsrep::server_state::s_connected) == "connected");
BOOST_REQUIRE(wsrep::to_string( BOOST_REQUIRE(wsrep::to_string(
wsrep::server_context::s_joiner) == "joiner"); wsrep::server_state::s_joiner) == "joiner");
BOOST_REQUIRE(wsrep::to_string( BOOST_REQUIRE(wsrep::to_string(
wsrep::server_context::s_joined) == "joined"); wsrep::server_state::s_joined) == "joined");
BOOST_REQUIRE(wsrep::to_string( BOOST_REQUIRE(wsrep::to_string(
wsrep::server_context::s_donor) == "donor"); wsrep::server_state::s_donor) == "donor");
BOOST_REQUIRE(wsrep::to_string( BOOST_REQUIRE(wsrep::to_string(
wsrep::server_context::s_synced) == "synced"); wsrep::server_state::s_synced) == "synced");
BOOST_REQUIRE(wsrep::to_string( BOOST_REQUIRE(wsrep::to_string(
wsrep::server_context::s_disconnecting) == "disconnecting"); wsrep::server_state::s_disconnecting) == "disconnecting");
BOOST_REQUIRE(wsrep::to_string( BOOST_REQUIRE(wsrep::to_string(
static_cast<enum wsrep::server_context::state>(0xff)) == "unknown"); static_cast<enum wsrep::server_state::state>(0xff)) == "unknown");
} }

View File

@ -4,7 +4,7 @@
#include "test_utils.hpp" #include "test_utils.hpp"
#include "wsrep/client_state.hpp" #include "wsrep/client_state.hpp"
#include "mock_server_context.hpp" #include "mock_server_state.hpp"
// Simple BF abort method to BF abort unordered transasctions // Simple BF abort method to BF abort unordered transasctions
@ -20,7 +20,7 @@ void wsrep_test::bf_abort_ordered(wsrep::client_state& cc)
cc.bf_abort(wsrep::seqno(0)); cc.bf_abort(wsrep::seqno(0));
} }
// BF abort method to abort transactions via provider // BF abort method to abort transactions via provider
void wsrep_test::bf_abort_provider(wsrep::mock_server_context& sc, void wsrep_test::bf_abort_provider(wsrep::mock_server_state& sc,
const wsrep::transaction& tc, const wsrep::transaction& tc,
wsrep::seqno bf_seqno) wsrep::seqno bf_seqno)
{ {

View File

@ -6,7 +6,7 @@
namespace wsrep namespace wsrep
{ {
class client_state; class client_state;
class mock_server_context; class mock_server_state;
} }
#include "wsrep/transaction.hpp" #include "wsrep/transaction.hpp"
@ -25,7 +25,7 @@ namespace wsrep_test
void bf_abort_ordered(wsrep::client_state& cc); void bf_abort_ordered(wsrep::client_state& cc);
// BF abort method to abort transactions via provider // BF abort method to abort transactions via provider
void bf_abort_provider(wsrep::mock_server_context& sc, void bf_abort_provider(wsrep::mock_server_state& sc,
const wsrep::transaction& tc, const wsrep::transaction& tc,
wsrep::seqno bf_seqno); wsrep::seqno bf_seqno);

View File

@ -158,7 +158,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
transaction_1pc_bf_during_before_commit_uncertified, T, transaction_1pc_bf_during_before_commit_uncertified, T,
replicating_fixtures, T) replicating_fixtures, T)
{ {
wsrep::mock_server_context& sc(T::sc); wsrep::mock_server_state& sc(T::sc);
wsrep::client_state& cc(T::cc); wsrep::client_state& cc(T::cc);
const wsrep::transaction& tc(T::tc); const wsrep::transaction& tc(T::tc);
@ -198,7 +198,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
transaction_1pc_bf_during_commit_wait_for_replayers, T, transaction_1pc_bf_during_commit_wait_for_replayers, T,
replicating_fixtures, T) replicating_fixtures, T)
{ {
wsrep::mock_server_context& sc(T::sc); wsrep::mock_server_state& sc(T::sc);
wsrep::mock_client_state& cc(T::cc); wsrep::mock_client_state& cc(T::cc);
const wsrep::transaction& tc(T::tc); const wsrep::transaction& tc(T::tc);
@ -237,7 +237,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
transaction_1pc_error_during_prepare_data, T, transaction_1pc_error_during_prepare_data, T,
replicating_fixtures, T) replicating_fixtures, T)
{ {
wsrep::mock_server_context& sc(T::sc); wsrep::mock_server_state& sc(T::sc);
wsrep::mock_client_state& cc(T::cc); wsrep::mock_client_state& cc(T::cc);
const wsrep::transaction& tc(T::tc); const wsrep::transaction& tc(T::tc);
@ -277,7 +277,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
transaction_1pc_killed_before_certify, T, transaction_1pc_killed_before_certify, T,
replicating_fixtures, T) replicating_fixtures, T)
{ {
wsrep::mock_server_context& sc(T::sc); wsrep::mock_server_state& sc(T::sc);
wsrep::mock_client_state& cc(T::cc); wsrep::mock_client_state& cc(T::cc);
const wsrep::transaction& tc(T::tc); const wsrep::transaction& tc(T::tc);
@ -359,7 +359,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
transaction_1pc_bf_during_before_commit_certified, T, transaction_1pc_bf_during_before_commit_certified, T,
replicating_fixtures, T) replicating_fixtures, T)
{ {
wsrep::mock_server_context& sc(T::sc); wsrep::mock_server_state& sc(T::sc);
wsrep::mock_client_state& cc(T::cc); wsrep::mock_client_state& cc(T::cc);
const wsrep::transaction& tc(T::tc); const wsrep::transaction& tc(T::tc);
@ -402,7 +402,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
transaction_1pc_bf_before_unordered_cert_failure, T, transaction_1pc_bf_before_unordered_cert_failure, T,
replicating_fixtures, T) replicating_fixtures, T)
{ {
wsrep::mock_server_context& sc(T::sc); wsrep::mock_server_state& sc(T::sc);
wsrep::mock_client_state& cc(T::cc); wsrep::mock_client_state& cc(T::cc);
const wsrep::transaction& tc(T::tc); const wsrep::transaction& tc(T::tc);
@ -435,7 +435,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
transaction_1pc_warning_error_from_certify, T, transaction_1pc_warning_error_from_certify, T,
replicating_fixtures, T) replicating_fixtures, T)
{ {
wsrep::mock_server_context& sc(T::sc); wsrep::mock_server_state& sc(T::sc);
wsrep::client_state& cc(T::cc); wsrep::client_state& cc(T::cc);
const wsrep::transaction& tc(T::tc); const wsrep::transaction& tc(T::tc);
@ -476,7 +476,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
transaction_1pc_transaction_missing_from_certify, T, transaction_1pc_transaction_missing_from_certify, T,
replicating_fixtures, T) replicating_fixtures, T)
{ {
wsrep::mock_server_context& sc(T::sc); wsrep::mock_server_state& sc(T::sc);
wsrep::client_state& cc(T::cc); wsrep::client_state& cc(T::cc);
const wsrep::transaction& tc(T::tc); const wsrep::transaction& tc(T::tc);
@ -517,7 +517,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
transaction_1pc_size_exceeded_from_certify, T, transaction_1pc_size_exceeded_from_certify, T,
replicating_fixtures, T) replicating_fixtures, T)
{ {
wsrep::mock_server_context& sc(T::sc); wsrep::mock_server_state& sc(T::sc);
wsrep::client_state& cc(T::cc); wsrep::client_state& cc(T::cc);
const wsrep::transaction& tc(T::tc); const wsrep::transaction& tc(T::tc);
@ -558,7 +558,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
transaction_1pc_connection_failed_from_certify, T, transaction_1pc_connection_failed_from_certify, T,
replicating_fixtures, T) replicating_fixtures, T)
{ {
wsrep::mock_server_context& sc(T::sc); wsrep::mock_server_state& sc(T::sc);
wsrep::client_state& cc(T::cc); wsrep::client_state& cc(T::cc);
const wsrep::transaction& tc(T::tc); const wsrep::transaction& tc(T::tc);
@ -599,7 +599,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
transaction_1pc_no_allowed_from_certify, T, transaction_1pc_no_allowed_from_certify, T,
replicating_fixtures, T) replicating_fixtures, T)
{ {
wsrep::mock_server_context& sc(T::sc); wsrep::mock_server_state& sc(T::sc);
wsrep::client_state& cc(T::cc); wsrep::client_state& cc(T::cc);
const wsrep::transaction& tc(T::tc); const wsrep::transaction& tc(T::tc);
@ -640,7 +640,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
transaction_1pc_fatal_from_certify, T, transaction_1pc_fatal_from_certify, T,
replicating_fixtures, T) replicating_fixtures, T)
{ {
wsrep::mock_server_context& sc(T::sc); wsrep::mock_server_state& sc(T::sc);
wsrep::mock_client_state& cc(T::cc); wsrep::mock_client_state& cc(T::cc);
const wsrep::transaction& tc(T::tc); const wsrep::transaction& tc(T::tc);
@ -682,7 +682,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
transaction_1pc_unknown_from_certify, T, transaction_1pc_unknown_from_certify, T,
replicating_fixtures, T) replicating_fixtures, T)
{ {
wsrep::mock_server_context& sc(T::sc); wsrep::mock_server_state& sc(T::sc);
wsrep::mock_client_state& cc(T::cc); wsrep::mock_client_state& cc(T::cc);
const wsrep::transaction& tc(T::tc); const wsrep::transaction& tc(T::tc);
@ -724,7 +724,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
transaction_1pc_bf_abort_before_certify_regain_lock, T, transaction_1pc_bf_abort_before_certify_regain_lock, T,
replicating_fixtures, T) replicating_fixtures, T)
{ {
wsrep::mock_server_context& sc(T::sc); wsrep::mock_server_state& sc(T::sc);
wsrep::mock_client_state& cc(T::cc); wsrep::mock_client_state& cc(T::cc);
const wsrep::transaction& tc(T::tc); const wsrep::transaction& tc(T::tc);