mirror of
https://github.com/codership/wsrep-lib.git
synced 2025-07-28 20:02:00 +03:00
Refactored storage service out of client service interface.
This commit is contained in:
@ -69,9 +69,13 @@ namespace wsrep
|
||||
virtual bool statement_allowed_for_streaming() const = 0;
|
||||
virtual size_t bytes_generated() const = 0;
|
||||
virtual int prepare_fragment_for_replication(wsrep::mutable_buffer&) = 0;
|
||||
/**
|
||||
* Remove fragments from the storage within current transaction.
|
||||
* Fragment removal will be committed once the current transaction
|
||||
* commits.
|
||||
*/
|
||||
virtual void remove_fragments() = 0;
|
||||
|
||||
virtual int commit(const wsrep::ws_handle&, const wsrep::ws_meta&) = 0;
|
||||
//
|
||||
// Rollback
|
||||
//
|
||||
@ -128,12 +132,6 @@ namespace wsrep
|
||||
*/
|
||||
virtual void wait_for_replayers(wsrep::unique_lock<wsrep::mutex>&) = 0;
|
||||
|
||||
// Streaming replication
|
||||
/**
|
||||
* Append a write set fragment into fragment storage.
|
||||
*/
|
||||
virtual int append_fragment(const wsrep::transaction&, int flag, const wsrep::const_buffer&) = 0;
|
||||
|
||||
//
|
||||
// Debug interface
|
||||
//
|
||||
|
@ -306,6 +306,23 @@ namespace wsrep
|
||||
enum wsrep::streaming_context::fragment_unit
|
||||
fragment_unit,
|
||||
size_t fragment_size);
|
||||
|
||||
/**
|
||||
* Prepare write set meta data for fragment storage ordering.
|
||||
* This method should be called from storage service commit
|
||||
* or rollback before performing the operation.
|
||||
*/
|
||||
int prepare_for_fragment_ordering(const wsrep::ws_handle& ws_handle,
|
||||
const wsrep::ws_meta& ws_meta,
|
||||
bool is_commit)
|
||||
{
|
||||
assert(mode_ == m_high_priority);
|
||||
assert(state_ == s_exec);
|
||||
return transaction_.prepare_for_fragment_ordering(
|
||||
ws_handle, ws_meta, is_commit);
|
||||
}
|
||||
/** @} */
|
||||
|
||||
/** @name Applying interface */
|
||||
/** @{ */
|
||||
int start_transaction(const wsrep::ws_handle& wsh,
|
||||
@ -734,26 +751,6 @@ namespace wsrep
|
||||
return to_c_string(mode);
|
||||
}
|
||||
|
||||
class client_state_switch
|
||||
{
|
||||
public:
|
||||
client_state_switch(wsrep::client_state& orig_context,
|
||||
wsrep::client_state& current_context)
|
||||
: orig_context_(orig_context)
|
||||
, current_context_(current_context)
|
||||
{
|
||||
current_context_.client_service_.store_globals();
|
||||
}
|
||||
~client_state_switch()
|
||||
{
|
||||
orig_context_.client_service_.store_globals();
|
||||
}
|
||||
private:
|
||||
client_state& orig_context_;
|
||||
client_state& current_context_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Utility class to switch the client state to high priority
|
||||
* mode. The client is switched back to the original mode
|
||||
@ -804,44 +801,6 @@ namespace wsrep
|
||||
enum wsrep::client_state::mode orig_mode_;
|
||||
};
|
||||
|
||||
class client_deleter
|
||||
{
|
||||
public:
|
||||
client_deleter(wsrep::server_service& server_service)
|
||||
: server_service_(server_service)
|
||||
{ }
|
||||
void operator()(wsrep::client_state* client_state)
|
||||
{
|
||||
server_service_.release_client_state(client_state);
|
||||
}
|
||||
private:
|
||||
wsrep::server_service& server_service_;
|
||||
};
|
||||
|
||||
template <class D>
|
||||
class scoped_client_state
|
||||
{
|
||||
public:
|
||||
scoped_client_state(wsrep::client_state* client_state, D deleter)
|
||||
: client_state_(client_state)
|
||||
, deleter_(deleter)
|
||||
{
|
||||
if (client_state_ == 0)
|
||||
{
|
||||
throw wsrep::runtime_error("Null client_state provided");
|
||||
}
|
||||
}
|
||||
wsrep::client_state& client_state() { return *client_state_; }
|
||||
~scoped_client_state()
|
||||
{
|
||||
deleter_(client_state_);
|
||||
}
|
||||
private:
|
||||
scoped_client_state(const scoped_client_state&);
|
||||
scoped_client_state& operator=(const scoped_client_state&);
|
||||
wsrep::client_state* client_state_;
|
||||
D deleter_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // WSREP_CLIENT_STATE_HPP
|
||||
|
@ -40,6 +40,7 @@ namespace wsrep
|
||||
* Adopt a transaction.
|
||||
*/
|
||||
virtual void adopt_transaction(const wsrep::transaction&) = 0;
|
||||
|
||||
/**
|
||||
* Apply a write set.
|
||||
*
|
||||
@ -50,6 +51,11 @@ namespace wsrep
|
||||
*/
|
||||
virtual int apply_write_set(const wsrep::const_buffer&) = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
virtual int append_fragment(const wsrep::ws_meta&,
|
||||
const wsrep::const_buffer& data) = 0;
|
||||
/**
|
||||
* Commit a transaction.
|
||||
*/
|
||||
|
@ -83,6 +83,7 @@ namespace wsrep
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream&, const wsrep::id& id);
|
||||
std::istream& operator>>(std::istream&, wsrep::id& id);
|
||||
}
|
||||
|
||||
#endif // WSREP_ID_HPP
|
||||
|
@ -20,7 +20,8 @@
|
||||
|
||||
namespace wsrep
|
||||
{
|
||||
class client_state;
|
||||
class client_service;
|
||||
class storage_service;
|
||||
class high_priority_service;
|
||||
class ws_meta;
|
||||
class gtid;
|
||||
@ -28,17 +29,11 @@ namespace wsrep
|
||||
class server_service
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create client state instance which acts only locally, i.e. does
|
||||
* not participate in replication. However, local client
|
||||
* state may execute transactions which require ordering,
|
||||
* as when modifying local SR fragment storage requires
|
||||
* strict commit ordering.
|
||||
*
|
||||
* @return Pointer to Client State.
|
||||
*/
|
||||
virtual wsrep::client_state* local_client_state() = 0;
|
||||
virtual void release_client_state(wsrep::client_state*) = 0;
|
||||
|
||||
virtual wsrep::storage_service* storage_service(
|
||||
wsrep::client_service&) = 0;
|
||||
|
||||
virtual void release_storage_service(wsrep::storage_service*) = 0;
|
||||
/**
|
||||
* Create an applier state for streaming transaction applying.
|
||||
*
|
||||
|
@ -87,6 +87,7 @@ namespace wsrep
|
||||
class transaction;
|
||||
class const_buffer;
|
||||
class server_service;
|
||||
|
||||
/** @class Server Context
|
||||
*
|
||||
*
|
||||
@ -172,11 +173,11 @@ namespace wsrep
|
||||
const std::string& name() const { return name_; }
|
||||
|
||||
/**
|
||||
* Return Server identifier string.
|
||||
* Return Server identifier.
|
||||
*
|
||||
* @return Server indetifier string.
|
||||
* @return Server identifier.
|
||||
*/
|
||||
const std::string& id() const { return id_; }
|
||||
const wsrep::id& id() const { return id_; }
|
||||
|
||||
const std::string& incoming_address() const
|
||||
{ return incoming_address_; }
|
||||
@ -575,7 +576,7 @@ namespace wsrep
|
||||
streaming_appliers_map streaming_appliers_;
|
||||
wsrep::provider* provider_;
|
||||
std::string name_;
|
||||
std::string id_;
|
||||
wsrep::id id_;
|
||||
std::string incoming_address_;
|
||||
std::string address_;
|
||||
std::string working_dir_;
|
||||
|
75
include/wsrep/storage_service.hpp
Normal file
75
include/wsrep/storage_service.hpp
Normal file
@ -0,0 +1,75 @@
|
||||
//
|
||||
// Copyright (C) 2018 Codership Oy <info@codership.com>
|
||||
//
|
||||
|
||||
/** @file storage_service.hpp
|
||||
*
|
||||
* Abstract interface which defines required access to DBMS storage
|
||||
* service. The service is used for storing streaming replication
|
||||
* write set fragments into stable storage. The interface is used
|
||||
* from locally processing transaction context only. Corresponding
|
||||
* operations for high priority processing can be found from
|
||||
* wsrep::high_priority_service interface.
|
||||
*/
|
||||
#ifndef WSREP_STORAGE_SERVICE_HPP
|
||||
#define WSREP_STORAGE_SERVICE_HPP
|
||||
|
||||
#include "client_id.hpp"
|
||||
#include "id.hpp"
|
||||
#include "buffer.hpp"
|
||||
|
||||
namespace wsrep
|
||||
{
|
||||
// Forward declarations
|
||||
class ws_handle;
|
||||
class ws_meta;
|
||||
|
||||
|
||||
/**
|
||||
* Storage service abstract interface.
|
||||
*/
|
||||
class storage_service
|
||||
{
|
||||
public:
|
||||
virtual ~storage_service() { }
|
||||
/**
|
||||
* Start a new transaction for storage access.
|
||||
*
|
||||
* @param ws_hande Write set handle
|
||||
* @param ws_meta Write set meta data
|
||||
*
|
||||
* @return Zero in case of success, non-zero on error.
|
||||
*/
|
||||
virtual int start_transaction() = 0;
|
||||
|
||||
/**
|
||||
* Append fragment into stable storage.
|
||||
*/
|
||||
virtual int append_fragment(const wsrep::id& server_id,
|
||||
wsrep::client_id client_id,
|
||||
int flags,
|
||||
const wsrep::const_buffer& data) = 0;
|
||||
|
||||
/**
|
||||
* Update fragment meta data after certification process.
|
||||
*/
|
||||
virtual int update_fragment_meta(const wsrep::ws_meta&) = 0;
|
||||
|
||||
/**
|
||||
* Commit the transaction.
|
||||
*/
|
||||
virtual int commit(const wsrep::ws_handle&, const wsrep::ws_meta&) = 0;
|
||||
|
||||
/**
|
||||
* Roll back the transaction.
|
||||
*/
|
||||
virtual int rollback(const wsrep::ws_handle&,
|
||||
const wsrep::ws_meta&) = 0;
|
||||
|
||||
|
||||
virtual void store_globals() = 0;
|
||||
virtual void reset_globals() = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // WSREP_STORAGE_SERVICE_HPP
|
@ -87,6 +87,10 @@ namespace wsrep
|
||||
int start_transaction(const wsrep::ws_handle& ws_handle,
|
||||
const wsrep::ws_meta& ws_meta);
|
||||
|
||||
int prepare_for_fragment_ordering(const wsrep::ws_handle& ws_handle,
|
||||
const wsrep::ws_meta& ws_meta,
|
||||
bool is_commit);
|
||||
|
||||
int start_replaying(const wsrep::ws_meta&);
|
||||
|
||||
int append_key(const wsrep::key&);
|
||||
|
Reference in New Issue
Block a user