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

@ -3,8 +3,9 @@
#
add_executable(wsrep-lib_test
mock_high_priority_service.cpp
mock_client_state.cpp
mock_high_priority_service.cpp
mock_storage_service.cpp
test_utils.cpp
id_test.cpp
server_context_test.cpp

View File

@ -6,31 +6,6 @@
#include "mock_client_state.hpp"
#include "mock_high_priority_service.hpp"
int wsrep::mock_client_service::commit(
const wsrep::ws_handle&, const wsrep::ws_meta&)
{
int ret(0);
if (do_2pc())
{
if (client_state_.before_prepare())
{
ret = 1;
}
else if (client_state_.after_prepare())
{
ret = 1;
}
}
if (ret == 0 &&
(client_state_.before_commit() ||
client_state_.ordered_commit() ||
client_state_.after_commit()))
{
ret = 1;
}
return ret;
}
int wsrep::mock_client_service::bf_rollback()
{
int ret(0);

View File

@ -63,21 +63,15 @@ namespace wsrep
int apply_toi(const wsrep::const_buffer&) WSREP_OVERRIDE;
int commit(const wsrep::ws_handle&, const wsrep::ws_meta&)
WSREP_OVERRIDE;
int bf_rollback() WSREP_OVERRIDE;
bool is_autocommit() const WSREP_OVERRIDE
{ return is_autocommit_; }
bool do_2pc() const WSREP_OVERRIDE
{ return do_2pc_; }
bool interrupted() const WSREP_OVERRIDE
{ return killed_before_certify_; }
void reset_globals() WSREP_OVERRIDE { }
void emergency_shutdown() WSREP_OVERRIDE { ++aborts_; }
int append_fragment(const wsrep::transaction&,
@ -135,6 +129,7 @@ namespace wsrep
}
void store_globals() WSREP_OVERRIDE { }
void reset_globals() WSREP_OVERRIDE { }
void debug_sync(const char* sync_point) WSREP_OVERRIDE
{
@ -181,7 +176,6 @@ namespace wsrep
//
size_t replays() const { return replays_; }
size_t aborts() const { return aborts_; }
private:
wsrep::mock_client_state& client_state_;
size_t replays_;

View File

@ -33,6 +33,9 @@ namespace wsrep
void adopt_transaction(const wsrep::transaction&) WSREP_OVERRIDE;
int apply_write_set(const wsrep::const_buffer&) WSREP_OVERRIDE;
int append_fragment(const wsrep::ws_meta&,
const wsrep::const_buffer& data) WSREP_OVERRIDE
{ return 0; }
int commit() WSREP_OVERRIDE;
int rollback() WSREP_OVERRIDE;
int apply_toi(const wsrep::ws_meta&,

View File

@ -9,6 +9,7 @@
#include "wsrep/server_service.hpp"
#include "mock_client_state.hpp"
#include "mock_high_priority_service.hpp"
#include "mock_storage_service.hpp"
#include "mock_provider.hpp"
#include "wsrep/compiler.hpp"
@ -32,9 +33,22 @@ namespace wsrep
, cond_()
, provider_(*this)
, last_client_id_(0)
, last_transaction_id_(0)
{ }
wsrep::mock_provider& provider() const
{ return provider_; }
wsrep::storage_service* storage_service(wsrep::client_service&)
{
return new wsrep::mock_storage_service(*this, ++last_client_id_);
}
void release_storage_service(wsrep::storage_service* storage_service)
{
delete storage_service;
}
wsrep::client_state* local_client_state()
{
wsrep::client_state* ret(new wsrep::mock_client(
@ -43,6 +57,7 @@ namespace wsrep
ret->open(ret->id());
return ret;
}
void release_client_state(wsrep::client_state* client_state)
{
delete client_state;
@ -103,6 +118,11 @@ namespace wsrep
int wait_committing_transactions(int) WSREP_OVERRIDE { return 0; }
wsrep::transaction_id next_transaction_id()
{
return wsrep::transaction_id(++last_transaction_id_);
}
void debug_sync(const char* sync_point) WSREP_OVERRIDE
{
if (sync_point_enabled_ == sync_point)
@ -128,6 +148,7 @@ namespace wsrep
wsrep::default_condition_variable cond_;
mutable wsrep::mock_provider provider_;
unsigned long long last_client_id_;
unsigned long long last_transaction_id_;
};
}

View File

@ -0,0 +1,56 @@
//
// Copyright (C) 2018 Codership Oy <info@codership.com>
//
#include "mock_storage_service.hpp"
#include "mock_server_state.hpp"
#include "wsrep/client_state.hpp"
wsrep::mock_storage_service::mock_storage_service(
wsrep::mock_server_state& server_state,
wsrep::client_id client_id)
: server_state_(server_state)
, client_service_(client_state_)
, client_state_(server_state, client_service_, client_id,
wsrep::client_state::m_high_priority)
{
client_state_.open(client_id);
client_state_.before_command();
}
wsrep::mock_storage_service::~mock_storage_service()
{
client_state_.after_command_before_result();
client_state_.after_command_after_result();
client_state_.close();
client_state_.cleanup();
}
int wsrep::mock_storage_service::start_transaction()
{
return client_state_.start_transaction(
server_state_.next_transaction_id());
}
int wsrep::mock_storage_service::commit(const wsrep::ws_handle& ws_handle,
const wsrep::ws_meta& ws_meta)
{
return client_state_.prepare_for_fragment_ordering(
ws_handle, ws_meta, true) ||
client_state_.before_commit() ||
client_state_.ordered_commit() ||
client_state_.after_commit() ||
client_state_.after_statement();
}
int wsrep::mock_storage_service::rollback(const wsrep::ws_handle& ws_handle,
const wsrep::ws_meta& ws_meta)
{
return client_state_.prepare_for_fragment_ordering(
ws_handle, ws_meta, false) ||
client_state_.before_rollback() ||
client_state_.after_rollback() ||
client_state_.after_statement();
}

View File

@ -0,0 +1,48 @@
//
// Copyright (C) 2018 Codership Oy <info@codership.com>
//
#ifndef WSREP_MOCK_STORAGE_SERVICE_HPP
#define WSREP_MOCK_STORAGE_SERVICE_HPP
#include "wsrep/storage_service.hpp"
#include "mock_client_state.hpp"
namespace wsrep
{
class mock_server_state;
class mock_storage_service : public wsrep::storage_service
{
public:
mock_storage_service(wsrep::mock_server_state&,
wsrep::client_id);
~mock_storage_service();
int start_transaction() WSREP_OVERRIDE;
int append_fragment(const wsrep::id&,
wsrep::client_id,
int,
const wsrep::const_buffer&)
WSREP_OVERRIDE
{ return 0; }
int update_fragment_meta(const wsrep::ws_meta&) WSREP_OVERRIDE
{ return 0; }
int commit(const wsrep::ws_handle&, const wsrep::ws_meta&)
WSREP_OVERRIDE;
int rollback(const wsrep::ws_handle&, const wsrep::ws_meta&)
WSREP_OVERRIDE;
void store_globals() WSREP_OVERRIDE { }
void reset_globals() WSREP_OVERRIDE { }
private:
wsrep::mock_server_state& server_state_;
wsrep::mock_client_service client_service_;
wsrep::mock_client_state client_state_;
};
}
#endif // WSREP_MOCK_STORAGE_SERVICE_HPP