mirror of
https://github.com/codership/wsrep-lib.git
synced 2025-07-28 20:02:00 +03:00
* Unit test for SR 2PC
* Removed redundant data class * Introduced const_buffer and mutable_buffer * Transaction context and client context interface refactoring
This commit is contained in:
@ -5,27 +5,52 @@
|
||||
#ifndef WSREP_BUFFER_HPP
|
||||
#define WSREP_BUFFER_HPP
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace wsrep
|
||||
{
|
||||
class buffer
|
||||
class const_buffer
|
||||
{
|
||||
public:
|
||||
buffer()
|
||||
const_buffer()
|
||||
: ptr_()
|
||||
, size_()
|
||||
{ }
|
||||
buffer(const void* ptr, size_t size)
|
||||
|
||||
const_buffer(const void* ptr, size_t size)
|
||||
: ptr_(ptr)
|
||||
, size_(size)
|
||||
{ }
|
||||
|
||||
const void* ptr() const { return ptr_; }
|
||||
const void* data() const { return ptr_; }
|
||||
size_t size() const { return size_; }
|
||||
|
||||
private:
|
||||
// const_buffer(const const_buffer&);
|
||||
// const_buffer& operator=(const const_buffer&);
|
||||
const void* ptr_;
|
||||
size_t size_;
|
||||
};
|
||||
|
||||
|
||||
class mutable_buffer
|
||||
{
|
||||
public:
|
||||
mutable_buffer()
|
||||
: buffer_()
|
||||
{ }
|
||||
|
||||
void push_back(const char* begin, const char* end)
|
||||
{
|
||||
buffer_.insert(buffer_.end(), begin, end);
|
||||
}
|
||||
const char* data() const { return &buffer_[0]; }
|
||||
size_t size() const { return buffer_.size(); }
|
||||
private:
|
||||
std::vector<char> buffer_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // WSREP_BUFFER_HPP
|
||||
|
@ -44,7 +44,7 @@
|
||||
#include "client_id.hpp"
|
||||
#include "mutex.hpp"
|
||||
#include "lock.hpp"
|
||||
#include "data.hpp"
|
||||
#include "buffer.hpp"
|
||||
#include "thread.hpp"
|
||||
|
||||
|
||||
@ -242,7 +242,7 @@ namespace wsrep
|
||||
return transaction_.append_key(key);
|
||||
}
|
||||
|
||||
int append_data(const wsrep::data& data)
|
||||
int append_data(const wsrep::const_buffer& data)
|
||||
{
|
||||
assert(state_ == s_exec);
|
||||
return transaction_.append_data(data);
|
||||
@ -400,7 +400,7 @@ namespace wsrep
|
||||
friend int server_context::on_apply(client_context&,
|
||||
const wsrep::ws_handle&,
|
||||
const wsrep::ws_meta&,
|
||||
const wsrep::data&);
|
||||
const wsrep::const_buffer&);
|
||||
friend class client_context_switch;
|
||||
friend class client_applier_mode;
|
||||
friend class client_toi_mode;
|
||||
@ -425,18 +425,17 @@ namespace wsrep
|
||||
/*!
|
||||
* Append SR fragment to the transaction.
|
||||
*/
|
||||
virtual int append_fragment(wsrep::transaction_context&,
|
||||
int, const wsrep::data&)
|
||||
{ return 0; }
|
||||
|
||||
virtual int append_fragment(const wsrep::transaction_context&,
|
||||
int, const wsrep::const_buffer&) = 0;
|
||||
|
||||
virtual void remove_fragments(const wsrep::transaction_context&) = 0;
|
||||
/*!
|
||||
* This method applies a write set give in data buffer.
|
||||
* This must be implemented by the DBMS integration.
|
||||
*
|
||||
* \return Zero on success, non-zero on applying failure.
|
||||
*/
|
||||
virtual int apply(const wsrep::data& data) = 0;
|
||||
virtual int apply(const wsrep::const_buffer& data) = 0;
|
||||
|
||||
/*!
|
||||
* Virtual method which will be called
|
||||
@ -474,8 +473,10 @@ namespace wsrep
|
||||
virtual void wait_for_replayers(wsrep::unique_lock<wsrep::mutex>&) = 0;
|
||||
|
||||
virtual int prepare_data_for_replication(
|
||||
const wsrep::transaction_context&, wsrep::data& data) = 0;
|
||||
const wsrep::transaction_context&) = 0;
|
||||
|
||||
virtual int prepare_fragment_for_replication(
|
||||
const wsrep::transaction_context&, wsrep::mutable_buffer&) = 0;
|
||||
/*!
|
||||
* Return true if the current client operation was killed.
|
||||
*/
|
||||
|
@ -1,27 +0,0 @@
|
||||
//
|
||||
// Copyright (C) 2018 Codership Oy <info@codership.com>
|
||||
//
|
||||
|
||||
#ifndef WSREP_DATA_HPP
|
||||
#define WSREP_DATA_HPP
|
||||
|
||||
namespace wsrep
|
||||
{
|
||||
class data
|
||||
{
|
||||
public:
|
||||
data()
|
||||
: buf_()
|
||||
{
|
||||
}
|
||||
data(const void* ptr, size_t len)
|
||||
: buf_(ptr, len)
|
||||
{
|
||||
}
|
||||
const wsrep::buffer& get() const { return buf_; }
|
||||
private:
|
||||
wsrep::buffer buf_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // WSREP_DATA_HPP
|
@ -33,7 +33,7 @@ namespace wsrep
|
||||
{
|
||||
throw wsrep::runtime_error("key parts exceed maximum of 3");
|
||||
}
|
||||
key_parts_[key_parts_len_] = wsrep::buffer(ptr, len);
|
||||
key_parts_[key_parts_len_] = wsrep::const_buffer(ptr, len);
|
||||
++key_parts_len_;
|
||||
}
|
||||
|
||||
@ -47,14 +47,14 @@ namespace wsrep
|
||||
return key_parts_len_;
|
||||
}
|
||||
|
||||
const wsrep::buffer* key_parts() const
|
||||
const wsrep::const_buffer* key_parts() const
|
||||
{
|
||||
return key_parts_;
|
||||
}
|
||||
private:
|
||||
|
||||
enum type type_;
|
||||
wsrep::buffer key_parts_[3];
|
||||
wsrep::const_buffer key_parts_[3];
|
||||
size_t key_parts_len_;
|
||||
};
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "gtid.hpp"
|
||||
#include "key.hpp"
|
||||
#include "data.hpp"
|
||||
#include "buffer.hpp"
|
||||
#include "client_id.hpp"
|
||||
#include "transaction_id.hpp"
|
||||
|
||||
@ -213,7 +213,7 @@ namespace wsrep
|
||||
// TODO: Rename to assing_read_view()
|
||||
virtual int start_transaction(wsrep::ws_handle&) = 0;
|
||||
virtual int append_key(wsrep::ws_handle&, const wsrep::key&) = 0;
|
||||
virtual int append_data(wsrep::ws_handle&, const wsrep::data&) = 0;
|
||||
virtual int append_data(wsrep::ws_handle&, const wsrep::const_buffer&) = 0;
|
||||
virtual enum status
|
||||
certify(wsrep::client_id, wsrep::ws_handle&,
|
||||
int,
|
||||
|
@ -77,7 +77,7 @@ namespace wsrep
|
||||
class transaction_context;
|
||||
class gtid;
|
||||
class view;
|
||||
class data;
|
||||
class const_buffer;
|
||||
|
||||
/*! \class Server Context
|
||||
*
|
||||
@ -342,7 +342,7 @@ namespace wsrep
|
||||
int on_apply(wsrep::client_context& client_context,
|
||||
const wsrep::ws_handle& ws_handle,
|
||||
const wsrep::ws_meta& ws_meta,
|
||||
const wsrep::data& data);
|
||||
const wsrep::const_buffer& data);
|
||||
|
||||
/*!
|
||||
* This virtual method should be implemented by the DBMS
|
||||
|
@ -17,7 +17,7 @@ namespace wsrep
|
||||
{
|
||||
class client_context;
|
||||
class key;
|
||||
class data;
|
||||
class const_buffer;
|
||||
|
||||
|
||||
class transaction_context
|
||||
@ -67,10 +67,13 @@ namespace wsrep
|
||||
bool ordered() const
|
||||
{ return (ws_meta_.seqno().nil() == false); }
|
||||
|
||||
/*!
|
||||
* Return true if any fragments have been succesfully certified
|
||||
* for the transaction.
|
||||
*/
|
||||
bool is_streaming() const
|
||||
{
|
||||
// Streaming support not yet implemented
|
||||
return false;
|
||||
return (streaming_context_.fragments_certified() > 0);
|
||||
}
|
||||
|
||||
bool pa_unsafe() const { return pa_unsafe_; }
|
||||
@ -91,7 +94,7 @@ namespace wsrep
|
||||
|
||||
int append_key(const wsrep::key&);
|
||||
|
||||
int append_data(const wsrep::data&);
|
||||
int append_data(const wsrep::const_buffer&);
|
||||
|
||||
int after_row();
|
||||
|
||||
@ -132,7 +135,6 @@ namespace wsrep
|
||||
void flags(int flags) { flags_ = flags; }
|
||||
int certify_fragment(wsrep::unique_lock<wsrep::mutex>&);
|
||||
int certify_commit(wsrep::unique_lock<wsrep::mutex>&);
|
||||
void remove_fragments();
|
||||
void clear_fragments();
|
||||
void cleanup();
|
||||
void debug_log_state(const char*) const;
|
||||
@ -215,6 +217,14 @@ namespace wsrep
|
||||
|
||||
size_t unit_counter() const { return unit_counter_; }
|
||||
void increment_unit_counter() { ++unit_counter_; }
|
||||
|
||||
void cleanup()
|
||||
{
|
||||
fragments_.clear();
|
||||
rollback_replicated_for_ = wsrep::transaction_id::invalid();
|
||||
bytes_certified_ = 0;
|
||||
unit_counter_ = 0;
|
||||
}
|
||||
private:
|
||||
std::vector<wsrep::seqno> fragments_;
|
||||
wsrep::transaction_id rollback_replicated_for_;
|
||||
|
Reference in New Issue
Block a user