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:
@ -13,7 +13,6 @@
|
||||
#include "wsrep/client_context.hpp"
|
||||
#include "wsrep/transaction_context.hpp"
|
||||
#include "wsrep/key.hpp"
|
||||
#include "wsrep/data.hpp"
|
||||
#include "wsrep/provider.hpp"
|
||||
#include "wsrep/condition_variable.hpp"
|
||||
#include "wsrep/view.hpp"
|
||||
@ -274,7 +273,7 @@ public:
|
||||
dbms_storage_engine& storage_engine() { return storage_engine_; }
|
||||
|
||||
int apply_to_storage_engine(const wsrep::transaction_context& txc,
|
||||
const wsrep::data&)
|
||||
const wsrep::const_buffer&)
|
||||
{
|
||||
storage_engine_.bf_abort_some(txc);
|
||||
return 0;
|
||||
@ -346,7 +345,15 @@ public:
|
||||
private:
|
||||
bool is_autocommit() const override { return false; }
|
||||
bool do_2pc() const override { return false; }
|
||||
int apply(const wsrep::data& data) override
|
||||
int append_fragment(const wsrep::transaction_context&,
|
||||
int, const wsrep::const_buffer&) override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
void remove_fragments(const wsrep::transaction_context&) override
|
||||
{
|
||||
}
|
||||
int apply(const wsrep::const_buffer& data) override
|
||||
{
|
||||
return server_.apply_to_storage_engine(transaction(), data);
|
||||
}
|
||||
@ -381,12 +388,12 @@ private:
|
||||
}
|
||||
void wait_for_replayers(wsrep::unique_lock<wsrep::mutex>&) override
|
||||
{ }
|
||||
int prepare_data_for_replication(const wsrep::transaction_context&,
|
||||
wsrep::data&)
|
||||
int prepare_data_for_replication(const wsrep::transaction_context&)
|
||||
override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
{ return 0; }
|
||||
int prepare_fragment_for_replication(const wsrep::transaction_context&,
|
||||
wsrep::mutable_buffer&) override
|
||||
{ return 0; }
|
||||
bool killed() const override { return false; }
|
||||
void abort() override { ::abort(); }
|
||||
public:
|
||||
@ -454,8 +461,9 @@ private:
|
||||
key.append_key_part(&client_key, sizeof(client_key));
|
||||
key.append_key_part(&data, sizeof(data));
|
||||
err = append_key(key);
|
||||
err = err || append_data(wsrep::data(os.str().c_str(),
|
||||
os.str().size()));
|
||||
err = err || append_data(
|
||||
wsrep::const_buffer(os.str().c_str(),
|
||||
os.str().size()));
|
||||
return err;
|
||||
});
|
||||
err = err || client_command(
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
int wsrep::mock_client_context::apply(
|
||||
const wsrep::data& data __attribute__((unused)))
|
||||
const wsrep::const_buffer& data __attribute__((unused)))
|
||||
|
||||
{
|
||||
assert(transaction_.state() == wsrep::transaction_context::s_executing);
|
||||
|
@ -42,11 +42,16 @@ namespace wsrep
|
||||
(void)rollback();
|
||||
}
|
||||
}
|
||||
int apply(const wsrep::data&);
|
||||
int apply(const wsrep::const_buffer&);
|
||||
int commit();
|
||||
int rollback();
|
||||
bool is_autocommit() const { return is_autocommit_; }
|
||||
bool do_2pc() const { return do_2pc_; }
|
||||
int append_fragment(const wsrep::transaction_context&,
|
||||
int, const wsrep::const_buffer&) WSREP_OVERRIDE
|
||||
{ return 0; }
|
||||
void remove_fragments(const wsrep::transaction_context& )
|
||||
WSREP_OVERRIDE { }
|
||||
void will_replay(wsrep::transaction_context&) WSREP_OVERRIDE { }
|
||||
int replay(wsrep::transaction_context& tc) WSREP_OVERRIDE
|
||||
{
|
||||
@ -68,17 +73,31 @@ namespace wsrep
|
||||
lock.lock();
|
||||
}
|
||||
int prepare_data_for_replication(
|
||||
const wsrep::transaction_context&, wsrep::data& data) WSREP_OVERRIDE
|
||||
const wsrep::transaction_context&) WSREP_OVERRIDE
|
||||
{
|
||||
if (error_during_prepare_data_)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
static const char buf[1] = { 1 };
|
||||
data = wsrep::data(buf, 1);
|
||||
return 0;
|
||||
|
||||
wsrep::const_buffer data = wsrep::const_buffer(buf, 1);
|
||||
return transaction_.append_data(data);
|
||||
}
|
||||
|
||||
int prepare_fragment_for_replication(const wsrep::transaction_context&,
|
||||
wsrep::mutable_buffer& buffer)
|
||||
WSREP_OVERRIDE
|
||||
{
|
||||
if (error_during_prepare_data_)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
static const char buf[1] = { 1 };
|
||||
buffer.push_back(&buf[0], &buf[1]);
|
||||
wsrep::const_buffer data(buffer.data(), buffer.size());
|
||||
return transaction_.append_data(data);
|
||||
}
|
||||
|
||||
bool killed() const WSREP_OVERRIDE { return killed_before_certify_; }
|
||||
void abort() WSREP_OVERRIDE { ++aborts_; }
|
||||
void store_globals() WSREP_OVERRIDE { }
|
||||
@ -94,7 +113,7 @@ namespace wsrep
|
||||
}
|
||||
void debug_suicide(const char*) WSREP_OVERRIDE
|
||||
{
|
||||
::abort();
|
||||
// Not going to do this while unit testing
|
||||
}
|
||||
void on_error(enum wsrep::client_error) { }
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "wsrep/provider.hpp"
|
||||
#include "wsrep/logger.hpp"
|
||||
#include "wsrep/buffer.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
@ -50,7 +51,10 @@ namespace wsrep
|
||||
{
|
||||
wsrep::log_info() << "provider certify: "
|
||||
<< "client: " << client_id.get()
|
||||
<< " flags: " << std::hex << flags;
|
||||
<< " flags: " << std::hex << flags
|
||||
<< std::dec
|
||||
<< "next_error: " << next_error_;
|
||||
|
||||
if (next_error_)
|
||||
{
|
||||
return next_error_;
|
||||
@ -108,9 +112,9 @@ namespace wsrep
|
||||
}
|
||||
|
||||
int append_key(wsrep::ws_handle&, const wsrep::key&)
|
||||
{ return next_error_; }
|
||||
int append_data(wsrep::ws_handle&, const wsrep::data&)
|
||||
{ return next_error_; }
|
||||
{ return 0; }
|
||||
int append_data(wsrep::ws_handle&, const wsrep::const_buffer&)
|
||||
{ return 0; }
|
||||
int rollback(const wsrep::transaction_id)
|
||||
{ return next_error_; }
|
||||
enum wsrep::provider::status
|
||||
|
@ -114,7 +114,7 @@ int wsrep::server_context::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)
|
||||
{
|
||||
int ret(0);
|
||||
const wsrep::transaction_context& txc(client_context.transaction());
|
||||
|
@ -39,7 +39,7 @@ BOOST_FIXTURE_TEST_CASE(server_context_applying_1pc,
|
||||
{
|
||||
char buf[1] = { 1 };
|
||||
BOOST_REQUIRE(sc.on_apply(cc, ws_handle, ws_meta,
|
||||
wsrep::data(buf, 1)) == 0);
|
||||
wsrep::const_buffer(buf, 1)) == 0);
|
||||
const wsrep::transaction_context& txc(cc.transaction());
|
||||
// ::abort();
|
||||
BOOST_REQUIRE_MESSAGE(
|
||||
@ -53,7 +53,7 @@ BOOST_FIXTURE_TEST_CASE(server_context_applying_2pc,
|
||||
{
|
||||
char buf[1] = { 1 };
|
||||
BOOST_REQUIRE(sc.on_apply(cc, ws_handle, ws_meta,
|
||||
wsrep::data(buf, 1)) == 0);
|
||||
wsrep::const_buffer(buf, 1)) == 0);
|
||||
const wsrep::transaction_context& txc(cc.transaction());
|
||||
BOOST_REQUIRE(txc.state() == wsrep::transaction_context::s_committed);
|
||||
}
|
||||
@ -66,7 +66,7 @@ BOOST_FIXTURE_TEST_CASE(server_context_applying_1pc_rollback,
|
||||
cc.fail_next_applying_ = true;
|
||||
char buf[1] = { 1 };
|
||||
BOOST_REQUIRE(sc.on_apply(cc, ws_handle, ws_meta,
|
||||
wsrep::data(buf, 1)) == 1);
|
||||
wsrep::const_buffer(buf, 1)) == 1);
|
||||
const wsrep::transaction_context& txc(cc.transaction());
|
||||
BOOST_REQUIRE(txc.state() == wsrep::transaction_context::s_aborted);
|
||||
}
|
||||
@ -79,7 +79,7 @@ BOOST_FIXTURE_TEST_CASE(server_context_applying_2pc_rollback,
|
||||
cc.fail_next_applying_ = true;
|
||||
char buf[1] = { 1 };
|
||||
BOOST_REQUIRE(sc.on_apply(cc, ws_handle, ws_meta,
|
||||
wsrep::data(buf, 1)) == 1);
|
||||
wsrep::const_buffer(buf, 1)) == 1);
|
||||
const wsrep::transaction_context& txc(cc.transaction());
|
||||
BOOST_REQUIRE(txc.state() == wsrep::transaction_context::s_aborted);
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "wsrep/client_context.hpp"
|
||||
#include "wsrep/server_context.hpp"
|
||||
#include "wsrep/key.hpp"
|
||||
#include "wsrep/data.hpp"
|
||||
#include "wsrep/logger.hpp"
|
||||
#include "wsrep/compiler.hpp"
|
||||
|
||||
@ -87,7 +86,7 @@ int wsrep::transaction_context::append_key(const wsrep::key& key)
|
||||
return provider_.append_key(ws_handle_, key);
|
||||
}
|
||||
|
||||
int wsrep::transaction_context::append_data(const wsrep::data& data)
|
||||
int wsrep::transaction_context::append_data(const wsrep::const_buffer& data)
|
||||
{
|
||||
|
||||
return provider_.append_data(ws_handle_, data);
|
||||
@ -149,7 +148,7 @@ int wsrep::transaction_context::before_prepare()
|
||||
}
|
||||
else
|
||||
{
|
||||
remove_fragments();
|
||||
client_context_.remove_fragments(*this);
|
||||
}
|
||||
lock.lock();
|
||||
client_context_.debug_suicide(
|
||||
@ -658,8 +657,8 @@ int wsrep::transaction_context::certify_fragment(
|
||||
flags_ |= wsrep::provider::flag::start_transaction;
|
||||
}
|
||||
|
||||
wsrep::data data;
|
||||
if (client_context_.prepare_data_for_replication(*this, data))
|
||||
wsrep::mutable_buffer data;
|
||||
if (client_context_.prepare_fragment_for_replication(*this, data))
|
||||
{
|
||||
lock.lock();
|
||||
state(lock, s_must_abort);
|
||||
@ -681,7 +680,8 @@ int wsrep::transaction_context::certify_fragment(
|
||||
sr_transaction_context.state(sr_lock, s_certifying);
|
||||
sr_lock.unlock();
|
||||
if (sr_client_context->append_fragment(
|
||||
sr_transaction_context, flags_, data))
|
||||
sr_transaction_context, flags_,
|
||||
wsrep::const_buffer(data.data(), data.size())))
|
||||
{
|
||||
lock.lock();
|
||||
state(lock, s_must_abort);
|
||||
@ -750,8 +750,7 @@ int wsrep::transaction_context::certify_commit(
|
||||
flags(flags() | wsrep::provider::flag::commit);
|
||||
lock.unlock();
|
||||
|
||||
wsrep::data data;
|
||||
if (client_context_.prepare_data_for_replication(*this, data))
|
||||
if (client_context_.prepare_data_for_replication(*this))
|
||||
{
|
||||
// Note: Error must be set by prepare_data_for_replication()
|
||||
lock.lock();
|
||||
@ -870,14 +869,9 @@ int wsrep::transaction_context::certify_commit(
|
||||
return ret;
|
||||
}
|
||||
|
||||
void wsrep::transaction_context::remove_fragments()
|
||||
{
|
||||
throw wsrep::not_implemented_error();
|
||||
}
|
||||
|
||||
void wsrep::transaction_context::clear_fragments()
|
||||
{
|
||||
throw wsrep::not_implemented_error();
|
||||
streaming_context_.cleanup();
|
||||
}
|
||||
|
||||
void wsrep::transaction_context::cleanup()
|
||||
|
@ -140,7 +140,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_context_append_key_data,
|
||||
key.append_key_part(&vals[i], sizeof(vals[i]));
|
||||
}
|
||||
BOOST_REQUIRE(cc.append_key(key) == 0);
|
||||
wsrep::data data(&vals[2], sizeof(vals[2]));
|
||||
wsrep::const_buffer data(&vals[2], sizeof(vals[2]));
|
||||
BOOST_REQUIRE(cc.append_data(data) == 0);
|
||||
BOOST_REQUIRE(cc.before_commit() == 0);
|
||||
BOOST_REQUIRE(cc.ordered_commit() == 0);
|
||||
@ -1204,3 +1204,21 @@ BOOST_FIXTURE_TEST_CASE(transaction_context_streaming_1pc_commit,
|
||||
BOOST_REQUIRE(sc.provider().commit_fragments() == 1);
|
||||
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_context_streaming_2pc_commit,
|
||||
streaming_client_fixture_row)
|
||||
{
|
||||
BOOST_REQUIRE(cc.start_transaction(1) == 0);
|
||||
BOOST_REQUIRE(cc.after_row() == 0);
|
||||
BOOST_REQUIRE(tc.streaming_context_.fragments_certified() == 1);
|
||||
BOOST_REQUIRE(cc.before_prepare() == 0);
|
||||
BOOST_REQUIRE(cc.after_prepare() == 0);
|
||||
BOOST_REQUIRE(cc.before_commit() == 0);
|
||||
BOOST_REQUIRE(cc.ordered_commit() == 0);
|
||||
BOOST_REQUIRE(cc.after_commit() == 0);
|
||||
BOOST_REQUIRE(cc.after_statement() == wsrep::client_context::asr_success);
|
||||
BOOST_REQUIRE(sc.provider().fragments() == 2);
|
||||
BOOST_REQUIRE(sc.provider().start_fragments() == 1);
|
||||
BOOST_REQUIRE(sc.provider().commit_fragments() == 1);
|
||||
|
||||
}
|
||||
|
@ -314,7 +314,7 @@ namespace
|
||||
assert(client_context);
|
||||
assert(client_context->mode() == wsrep::client_context::m_applier);
|
||||
|
||||
wsrep::data data(buf->ptr, buf->len);
|
||||
wsrep::const_buffer data(buf->ptr, buf->len);
|
||||
wsrep::ws_handle ws_handle(wsh->trx_id, wsh->opaque);
|
||||
wsrep::ws_meta ws_meta(
|
||||
wsrep::gtid(wsrep::id(meta->gtid.uuid.data,
|
||||
@ -484,9 +484,9 @@ int wsrep::wsrep_provider_v26::append_key(wsrep::ws_handle& ws_handle,
|
||||
}
|
||||
|
||||
int wsrep::wsrep_provider_v26::append_data(wsrep::ws_handle& ws_handle,
|
||||
const wsrep::data& data)
|
||||
const wsrep::const_buffer& data)
|
||||
{
|
||||
const wsrep_buf_t wsrep_buf = {data.get().ptr(), data.get().size()};
|
||||
const wsrep_buf_t wsrep_buf = {data.data(), data.size()};
|
||||
mutable_ws_handle mwsh(ws_handle);
|
||||
return (wsrep_->append_data(wsrep_, mwsh.native(), &wsrep_buf,
|
||||
1, WSREP_DATA_ORDERED, true)
|
||||
|
@ -25,7 +25,7 @@ namespace wsrep
|
||||
enum wsrep::provider::status run_applier(void*);
|
||||
int start_transaction(wsrep::ws_handle&) { return 0; }
|
||||
int append_key(wsrep::ws_handle&, const wsrep::key&);
|
||||
int append_data(wsrep::ws_handle&, const wsrep::data&);
|
||||
int append_data(wsrep::ws_handle&, const wsrep::const_buffer&);
|
||||
enum wsrep::provider::status
|
||||
certify(wsrep::client_id, wsrep::ws_handle&,
|
||||
int,
|
||||
|
Reference in New Issue
Block a user