mirror of
https://github.com/codership/wsrep-lib.git
synced 2025-07-30 07:23:07 +03:00
Refactored high priority service out of client service.
This commit is contained in:
@ -6,16 +6,12 @@
|
||||
*
|
||||
* This file will define a `callback` abstract interface for a
|
||||
* DBMS client session service. The interface will define methods
|
||||
* which will be called by the wsrep-lib under certain circumstances,
|
||||
* for example when a transaction rollback is required by internal
|
||||
* wsrep-lib operation or applier client needs to apply a write set.
|
||||
* which will be called by the wsrep-lib.
|
||||
*/
|
||||
|
||||
#ifndef WSREP_CLIENT_SERVICE_HPP
|
||||
#define WSREP_CLIENT_SERVICE_HPP
|
||||
|
||||
#include "transaction_termination_service.hpp"
|
||||
|
||||
#include "buffer.hpp"
|
||||
#include "provider.hpp"
|
||||
#include "mutex.hpp"
|
||||
@ -24,7 +20,7 @@
|
||||
namespace wsrep
|
||||
{
|
||||
class transaction;
|
||||
class client_service : public wsrep::transaction_termination_service
|
||||
class client_service
|
||||
{
|
||||
public:
|
||||
client_service() { }
|
||||
@ -80,28 +76,15 @@ namespace wsrep
|
||||
virtual int prepare_fragment_for_replication(wsrep::mutable_buffer&) = 0;
|
||||
virtual void remove_fragments() = 0;
|
||||
|
||||
virtual int commit(const wsrep::ws_handle&, const wsrep::ws_meta&) = 0;
|
||||
//
|
||||
// Applying interface
|
||||
// Rollback
|
||||
//
|
||||
|
||||
/**
|
||||
* Apply a write set.
|
||||
*
|
||||
* A write set applying happens always
|
||||
* as a part of the transaction. The caller must start a
|
||||
* new transaction before applying a write set and must
|
||||
* either commit to make changes persistent or roll back.
|
||||
* Roll back all transactions which are currently active
|
||||
* in the client session.
|
||||
*/
|
||||
virtual int apply_write_set(const wsrep::const_buffer&) = 0;
|
||||
|
||||
/**
|
||||
* Apply a TOI operation.
|
||||
*
|
||||
* TOI operation is a standalone operation and should not
|
||||
* be executed as a part of a transaction.
|
||||
*/
|
||||
virtual int apply_toi(const wsrep::const_buffer&) = 0;
|
||||
|
||||
virtual int rollback() = 0;
|
||||
|
||||
//
|
||||
// Interface to global server state
|
||||
|
@ -391,7 +391,7 @@ namespace wsrep
|
||||
return transaction_.start_replaying(ws_meta);
|
||||
}
|
||||
|
||||
void adopt_transaction(wsrep::transaction& transaction)
|
||||
void adopt_transaction(const wsrep::transaction& transaction)
|
||||
{
|
||||
assert(mode_ == m_high_priority);
|
||||
transaction_.start_transaction(transaction.id());
|
||||
|
99
include/wsrep/high_priority_service.hpp
Normal file
99
include/wsrep/high_priority_service.hpp
Normal file
@ -0,0 +1,99 @@
|
||||
//
|
||||
// Copyright (C) 2018 Codership Oy <info@codership.com>
|
||||
//
|
||||
|
||||
/** @file high_priority_service.hpp
|
||||
*
|
||||
* Interface for services for applying high priority transactions.
|
||||
*/
|
||||
#ifndef WSREP_HIGH_PRIORITY_SERVICE_HPP
|
||||
#define WSREP_HIGH_PRIORITY_SERVICE_HPP
|
||||
|
||||
namespace wsrep
|
||||
{
|
||||
class ws_handle;
|
||||
class ws_meta;
|
||||
class const_buffer;
|
||||
class transaction;
|
||||
class high_priority_service
|
||||
{
|
||||
public:
|
||||
virtual ~high_priority_service() { }
|
||||
|
||||
virtual int apply(const ws_handle&, const ws_meta&,
|
||||
const const_buffer&) = 0;
|
||||
/**
|
||||
* Start a new transaction
|
||||
*/
|
||||
virtual int start_transaction(const wsrep::ws_handle&,
|
||||
const wsrep::ws_meta&) = 0;
|
||||
|
||||
/**
|
||||
* Adopt a transaction.
|
||||
*/
|
||||
virtual void adopt_transaction(const wsrep::transaction&) = 0;
|
||||
/**
|
||||
* Apply a write set.
|
||||
*
|
||||
* A write set applying happens always
|
||||
* as a part of the transaction. The caller must start a
|
||||
* new transaction before applying a write set and must
|
||||
* either commit to make changes persistent or roll back.
|
||||
*/
|
||||
virtual int apply_write_set(const wsrep::const_buffer&) = 0;
|
||||
|
||||
/**
|
||||
* Commit a transaction.
|
||||
*/
|
||||
virtual int commit() = 0;
|
||||
|
||||
/**
|
||||
* Roll back a transaction
|
||||
*/
|
||||
virtual int rollback() = 0;
|
||||
|
||||
/**
|
||||
* Apply a TOI operation.
|
||||
*
|
||||
* TOI operation is a standalone operation and should not
|
||||
* be executed as a part of a transaction.
|
||||
*/
|
||||
virtual int apply_toi(const wsrep::const_buffer&) = 0;
|
||||
|
||||
/**
|
||||
* Actions to take after applying a write set was completed.
|
||||
*/
|
||||
virtual void after_apply() = 0;
|
||||
|
||||
virtual void store_globals() = 0;
|
||||
virtual void reset_globals() = 0;
|
||||
|
||||
virtual int log_dummy_write_set(const ws_handle&, const ws_meta&) = 0;
|
||||
|
||||
virtual bool is_replaying() const = 0;
|
||||
private:
|
||||
};
|
||||
|
||||
class high_priority_switch
|
||||
{
|
||||
public:
|
||||
high_priority_switch(high_priority_service& orig_service,
|
||||
high_priority_service& current_service)
|
||||
: orig_service_(orig_service)
|
||||
, current_service_(current_service)
|
||||
{
|
||||
orig_service_.reset_globals();
|
||||
current_service_.store_globals();
|
||||
}
|
||||
~high_priority_switch()
|
||||
{
|
||||
current_service_.reset_globals();
|
||||
orig_service_.store_globals();
|
||||
}
|
||||
private:
|
||||
high_priority_service& orig_service_;
|
||||
high_priority_service& current_service_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // WSREP_HIGH_PRIORITY_SERVICE_HPP
|
@ -20,6 +20,7 @@
|
||||
namespace wsrep
|
||||
{
|
||||
class client_state;
|
||||
class high_priority_service;
|
||||
class ws_meta;
|
||||
class gtid;
|
||||
class view;
|
||||
@ -36,19 +37,21 @@ namespace wsrep
|
||||
* @return Pointer to Client State.
|
||||
*/
|
||||
virtual wsrep::client_state* local_client_state() = 0;
|
||||
|
||||
virtual void release_client_state(wsrep::client_state*) = 0;
|
||||
/**
|
||||
* Create an applier state for streaming transaction applying.
|
||||
*
|
||||
* @return Pointer to streaming applier client state.
|
||||
*/
|
||||
virtual wsrep::client_state* streaming_applier_client_state() = 0;
|
||||
virtual wsrep::high_priority_service*
|
||||
streaming_applier_service() = 0;
|
||||
|
||||
/**
|
||||
* Release a client state allocated by either local_client_state()
|
||||
* or streaming_applier_client_state().
|
||||
*/
|
||||
virtual void release_client_state(wsrep::client_state*) = 0;
|
||||
virtual void release_high_priority_service(
|
||||
wsrep::high_priority_service*) = 0;
|
||||
|
||||
/**
|
||||
* Perform a background rollback for a transaction.
|
||||
|
@ -215,15 +215,16 @@ namespace wsrep
|
||||
void start_streaming_applier(
|
||||
const wsrep::id&,
|
||||
const wsrep::transaction_id&,
|
||||
wsrep::client_state* client_state);
|
||||
wsrep::high_priority_service*);
|
||||
|
||||
void stop_streaming_applier(
|
||||
const wsrep::id&, const wsrep::transaction_id&);
|
||||
/**
|
||||
* Return reference to streaming applier.
|
||||
*/
|
||||
client_state* find_streaming_applier(const wsrep::id&,
|
||||
const wsrep::transaction_id&) const;
|
||||
wsrep::high_priority_service* find_streaming_applier(
|
||||
const wsrep::id&,
|
||||
const wsrep::transaction_id&) const;
|
||||
/**
|
||||
* Load WSRep provider.
|
||||
*
|
||||
@ -429,13 +430,13 @@ namespace wsrep
|
||||
*
|
||||
* @todo Make this private, allow calls for provider implementations
|
||||
* only.
|
||||
* @param client_state Applier client context.
|
||||
* @param high_priority_service High priority applier service.
|
||||
* @param transaction Transaction context.
|
||||
* @param data Write set data
|
||||
*
|
||||
* @return Zero on success, non-zero on failure.
|
||||
*/
|
||||
int on_apply(wsrep::client_state& client_state,
|
||||
int on_apply(wsrep::high_priority_service& high_priority_service,
|
||||
const wsrep::ws_handle& ws_handle,
|
||||
const wsrep::ws_meta& ws_meta,
|
||||
const wsrep::const_buffer& data);
|
||||
@ -555,7 +556,7 @@ namespace wsrep
|
||||
size_t pause_count_;
|
||||
wsrep::seqno pause_seqno_;
|
||||
bool desynced_on_pause_;
|
||||
typedef std::map<std::pair<wsrep::id, wsrep::transaction_id>, wsrep::client_state*> streaming_appliers_map;
|
||||
typedef std::map<std::pair<wsrep::id, wsrep::transaction_id>, wsrep::high_priority_service*> streaming_appliers_map;
|
||||
streaming_appliers_map streaming_appliers_;
|
||||
wsrep::provider* provider_;
|
||||
std::string name_;
|
||||
|
@ -1,21 +0,0 @@
|
||||
//
|
||||
// Copyright (C) 2018 Codership Oy <info@codership.com>
|
||||
//
|
||||
|
||||
|
||||
#ifndef WSREP_TRANSACTION_TERMINATION_SERVICE_HPP
|
||||
#define WSREP_TRANSACTION_TERMINATION_SERVICE_HPP
|
||||
|
||||
namespace wsrep
|
||||
{
|
||||
class ws_handle;
|
||||
class ws_meta;
|
||||
class transaction_termination_service
|
||||
{
|
||||
public:
|
||||
virtual int commit(const wsrep::ws_handle&, const wsrep::ws_meta&) = 0;
|
||||
virtual int rollback() = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // WSREP_TRANSACTION_TERMINATION_SERVICE_HPP
|
Reference in New Issue
Block a user