mirror of
https://github.com/codership/wsrep-lib.git
synced 2025-07-28 20:02:00 +03:00
Add support for custom provider implementation
- Add a set_provider_factory() method to server_state to allow injecting provider factory which will be called when the provider is loaded. Other related changes: - Implement to_string() helper method for id class. - Fix id ostream operator human readable id printing. - Pass victim client_service as an argument to provider::bf_abort() to allow passing victim context to custom provider. - Implement prev() helper method for seqno class. - Make server_state recover_streaming_appliers_if_not_recovered() public. In some recovery scenarios the method must be called outside of server_state internal code paths. - Add storage_service requires_globals() method. The storage service implementation may override this to return false if changing to storage service context does not require store/reset globals. - Change view final() to also require that the view status is not primary for the view to be final. Also change the method name to is_final() to avoid confusion with C++ final identifier. - Fixes to server state handling in disconnecting and disconnected states. - Keep TOI meta data over whole TOI critical section. Co-authored-by: Denis Protivensky <denis.protivensky@galeracluster.com>
This commit is contained in:
@ -37,6 +37,15 @@ BOOST_AUTO_TEST_CASE(id_test_uuid)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(id_test_string)
|
||||
{
|
||||
std::string id_str("node1");
|
||||
wsrep::id id(id_str);
|
||||
std::ostringstream os;
|
||||
os << id;
|
||||
BOOST_REQUIRE(id_str == os.str());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(id_test_string_max)
|
||||
{
|
||||
std::string id_str("1234567890123456");
|
||||
wsrep::id id(id_str);
|
||||
|
@ -117,9 +117,8 @@ namespace wsrep
|
||||
{
|
||||
++group_seqno_;
|
||||
wsrep::gtid gtid(group_id_, wsrep::seqno(group_seqno_));
|
||||
ws_meta = wsrep::ws_meta(gtid, stid,
|
||||
wsrep::seqno(group_seqno_ - 1),
|
||||
flags);
|
||||
ws_meta = wsrep::ws_meta(
|
||||
gtid, stid, wsrep::seqno(group_seqno_ - 1), flags);
|
||||
return wsrep::provider::success;
|
||||
}
|
||||
else
|
||||
@ -135,9 +134,8 @@ namespace wsrep
|
||||
{
|
||||
++group_seqno_;
|
||||
wsrep::gtid gtid(group_id_, wsrep::seqno(group_seqno_));
|
||||
ws_meta = wsrep::ws_meta(gtid, stid,
|
||||
wsrep::seqno(group_seqno_ - 1),
|
||||
flags);
|
||||
ws_meta = wsrep::ws_meta(
|
||||
gtid, stid, wsrep::seqno(group_seqno_ - 1), flags);
|
||||
ret = wsrep::provider::error_bf_abort;
|
||||
}
|
||||
bf_abort_map_.erase(it);
|
||||
@ -215,8 +213,8 @@ namespace wsrep
|
||||
wsrep::gtid(group_id_, wsrep::seqno(group_seqno_)),
|
||||
wsrep::stid(server_id_, tc.id(), cc.id()),
|
||||
wsrep::seqno(group_seqno_ - 1),
|
||||
wsrep::provider::flag::start_transaction |
|
||||
wsrep::provider::flag::commit);
|
||||
wsrep::provider::flag::start_transaction
|
||||
| wsrep::provider::flag::commit);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -245,12 +243,10 @@ namespace wsrep
|
||||
{
|
||||
++group_seqno_;
|
||||
wsrep::gtid gtid(group_id_, wsrep::seqno(group_seqno_));
|
||||
wsrep::stid stid(server_id_,
|
||||
wsrep::transaction_id::undefined(),
|
||||
wsrep::stid stid(server_id_, wsrep::transaction_id::undefined(),
|
||||
client_id);
|
||||
toi_meta = wsrep::ws_meta(gtid, stid,
|
||||
wsrep::seqno(group_seqno_ - 1),
|
||||
flags);
|
||||
wsrep::seqno(group_seqno_ - 1), flags);
|
||||
++toi_write_sets_;
|
||||
if (flags & wsrep::provider::flag::start_transaction)
|
||||
++toi_start_transaction_;
|
||||
@ -260,6 +256,7 @@ namespace wsrep
|
||||
}
|
||||
|
||||
enum wsrep::provider::status leave_toi(wsrep::client_id,
|
||||
const wsrep::ws_meta&,
|
||||
const wsrep::mutable_buffer&)
|
||||
WSREP_OVERRIDE
|
||||
{ return wsrep::provider::success; }
|
||||
@ -315,6 +312,7 @@ namespace wsrep
|
||||
enum wsrep::provider::status
|
||||
bf_abort(wsrep::seqno bf_seqno,
|
||||
wsrep::transaction_id trx_id,
|
||||
wsrep::client_service&,
|
||||
wsrep::seqno& victim_seqno)
|
||||
WSREP_OVERRIDE
|
||||
{
|
||||
|
@ -258,12 +258,31 @@ namespace wsrep
|
||||
rollback_mode)
|
||||
, mutex_()
|
||||
, cond_()
|
||||
, provider_(*this)
|
||||
{ }
|
||||
, provider_()
|
||||
{
|
||||
set_provider_factory([&](wsrep::server_state&,
|
||||
const std::string&,
|
||||
const std::string&,
|
||||
const wsrep::provider::services&)
|
||||
{
|
||||
// The provider object is destroyed upon server state
|
||||
// destruction, so using a raw pointer is safe.
|
||||
provider_ = new wsrep::mock_provider(*this);
|
||||
return std::unique_ptr<wsrep::provider>(provider_);
|
||||
});
|
||||
|
||||
wsrep::mock_provider& provider() const WSREP_OVERRIDE
|
||||
{ return provider_; }
|
||||
const int ret WSREP_UNUSED = load_provider("mock", "");
|
||||
assert(ret == 0);
|
||||
assert(provider_ != nullptr);
|
||||
}
|
||||
|
||||
mock_server_state(const mock_server_state&) = delete;
|
||||
mock_server_state& operator=(const mock_server_state&) = delete;
|
||||
|
||||
wsrep::mock_provider& provider() const
|
||||
{
|
||||
return *provider_;
|
||||
}
|
||||
// mock connected state for tests without overriding the connect()
|
||||
// method.
|
||||
int mock_connect(const std::string& own_id,
|
||||
@ -308,7 +327,7 @@ namespace wsrep
|
||||
private:
|
||||
wsrep::default_mutex mutex_;
|
||||
wsrep::default_condition_variable cond_;
|
||||
mutable wsrep::mock_provider provider_;
|
||||
wsrep::mock_provider* provider_;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -41,11 +41,12 @@ void wsrep_test::bf_abort_in_total_order(wsrep::client_state& cc)
|
||||
}
|
||||
// BF abort method to abort transactions via provider
|
||||
void wsrep_test::bf_abort_provider(wsrep::mock_server_state& sc,
|
||||
const wsrep::transaction& tc,
|
||||
const wsrep::client_state& victim_cs,
|
||||
wsrep::seqno bf_seqno)
|
||||
{
|
||||
wsrep::seqno victim_seqno;
|
||||
sc.provider().bf_abort(bf_seqno, tc.id(), victim_seqno);
|
||||
sc.provider().bf_abort(bf_seqno, victim_cs.transaction().id(), victim_cs.client_service(),
|
||||
victim_seqno);
|
||||
(void)victim_seqno;
|
||||
}
|
||||
|
||||
@ -63,13 +64,10 @@ void wsrep_test::terminate_streaming_applier(
|
||||
mc.before_command();
|
||||
wsrep::mock_high_priority_service hps(sc, &mc, false);
|
||||
wsrep::ws_handle ws_handle(transaction_id, (void*)(1));
|
||||
wsrep::ws_meta ws_meta(wsrep::gtid(wsrep::id("cluster1"),
|
||||
wsrep::seqno(100)),
|
||||
wsrep::stid(server_id,
|
||||
transaction_id,
|
||||
wsrep::client_id(1)),
|
||||
wsrep::seqno(0),
|
||||
wsrep::provider::flag::rollback);
|
||||
wsrep::ws_meta ws_meta(
|
||||
wsrep::gtid(wsrep::id("cluster1"), wsrep::seqno(100)),
|
||||
wsrep::stid(server_id, transaction_id, wsrep::client_id(1)),
|
||||
wsrep::seqno(0), wsrep::provider::flag::rollback);
|
||||
wsrep::const_buffer data(0, 0);
|
||||
sc.on_apply(hps, ws_handle, ws_meta, data);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ namespace wsrep_test
|
||||
|
||||
// BF abort method to abort transactions via provider
|
||||
void bf_abort_provider(wsrep::mock_server_state& sc,
|
||||
const wsrep::transaction& tc,
|
||||
const wsrep::client_state& victim_cs,
|
||||
wsrep::seqno bf_seqno);
|
||||
|
||||
// BF abort in total order
|
||||
|
@ -188,7 +188,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
|
||||
BOOST_REQUIRE(tc.id() == wsrep::transaction_id(1));
|
||||
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
|
||||
|
||||
wsrep_test::bf_abort_provider(sc, tc, wsrep::seqno::undefined());
|
||||
wsrep_test::bf_abort_provider(sc, cc, wsrep::seqno::undefined());
|
||||
|
||||
// Run before commit
|
||||
BOOST_REQUIRE(cc.before_commit());
|
||||
@ -454,7 +454,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
|
||||
BOOST_REQUIRE(tc.id() == wsrep::transaction_id(1));
|
||||
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
|
||||
|
||||
wsrep_test::bf_abort_provider(sc, tc, wsrep::seqno(1));
|
||||
wsrep_test::bf_abort_provider(sc, cc, wsrep::seqno(1));
|
||||
|
||||
// Run before commit
|
||||
BOOST_REQUIRE(cc.before_commit());
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2019 Codership Oy <info@codership.com>
|
||||
* Copyright (C) 2018-2021 Codership Oy <info@codership.com>
|
||||
*
|
||||
* This file is part of wsrep-lib.
|
||||
*
|
||||
@ -22,8 +22,7 @@
|
||||
//
|
||||
// Test a succesful 2PC transaction lifecycle
|
||||
//
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_2pc,
|
||||
replicating_client_fixture_2pc)
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_2pc, replicating_client_fixture_2pc)
|
||||
{
|
||||
cc.start_transaction(wsrep::transaction_id(1));
|
||||
BOOST_REQUIRE(tc.active());
|
||||
@ -52,9 +51,8 @@ BOOST_FIXTURE_TEST_CASE(transaction_2pc,
|
||||
//
|
||||
// Test a 2PC transaction which gets BF aborted before before_prepare
|
||||
//
|
||||
BOOST_FIXTURE_TEST_CASE(
|
||||
transaction_2pc_bf_before_before_prepare,
|
||||
replicating_client_fixture_2pc)
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_2pc_bf_before_before_prepare,
|
||||
replicating_client_fixture_2pc)
|
||||
{
|
||||
cc.start_transaction(wsrep::transaction_id(1));
|
||||
BOOST_REQUIRE(tc.active());
|
||||
@ -69,7 +67,7 @@ BOOST_FIXTURE_TEST_CASE(
|
||||
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_aborting);
|
||||
BOOST_REQUIRE(cc.after_rollback() == 0);
|
||||
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_aborted);
|
||||
BOOST_REQUIRE(cc.after_statement() );
|
||||
BOOST_REQUIRE(cc.after_statement());
|
||||
BOOST_REQUIRE(tc.active() == false);
|
||||
BOOST_REQUIRE(tc.ordered() == false);
|
||||
BOOST_REQUIRE(tc.certified() == false);
|
||||
@ -79,9 +77,8 @@ BOOST_FIXTURE_TEST_CASE(
|
||||
//
|
||||
// Test a 2PC transaction which gets BF aborted before before_prepare
|
||||
//
|
||||
BOOST_FIXTURE_TEST_CASE(
|
||||
transaction_2pc_bf_before_after_prepare,
|
||||
replicating_client_fixture_2pc)
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_2pc_bf_before_after_prepare,
|
||||
replicating_client_fixture_2pc)
|
||||
{
|
||||
cc.start_transaction(wsrep::transaction_id(1));
|
||||
BOOST_REQUIRE(tc.active());
|
||||
@ -110,9 +107,8 @@ BOOST_FIXTURE_TEST_CASE(
|
||||
// Test a 2PC transaction which gets BF aborted after_prepare() and
|
||||
// the rollback takes place before entering before_commit().
|
||||
//
|
||||
BOOST_FIXTURE_TEST_CASE(
|
||||
transaction_2pc_bf_after_after_prepare,
|
||||
replicating_client_fixture_2pc)
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_2pc_bf_after_after_prepare,
|
||||
replicating_client_fixture_2pc)
|
||||
{
|
||||
cc.start_transaction(wsrep::transaction_id(1));
|
||||
BOOST_REQUIRE(tc.active());
|
||||
@ -139,9 +135,8 @@ BOOST_FIXTURE_TEST_CASE(
|
||||
// Test a 2PC transaction which gets BF aborted between after_prepare()
|
||||
// and before_commit()
|
||||
//
|
||||
BOOST_FIXTURE_TEST_CASE(
|
||||
transaction_2pc_bf_before_before_commit,
|
||||
replicating_client_fixture_2pc)
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_2pc_bf_before_before_commit,
|
||||
replicating_client_fixture_2pc)
|
||||
{
|
||||
cc.start_transaction(wsrep::transaction_id(1));
|
||||
BOOST_REQUIRE(tc.active());
|
||||
@ -168,14 +163,12 @@ BOOST_FIXTURE_TEST_CASE(
|
||||
BOOST_REQUIRE(cc.current_error() == wsrep::e_success);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Test a 2PC transaction which gets BF aborted when trying to grab
|
||||
// commit order.
|
||||
//
|
||||
BOOST_FIXTURE_TEST_CASE(
|
||||
transaction_2pc_bf_during_commit_order_enter,
|
||||
replicating_client_fixture_2pc)
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_2pc_bf_during_commit_order_enter,
|
||||
replicating_client_fixture_2pc)
|
||||
{
|
||||
cc.start_transaction(wsrep::transaction_id(1));
|
||||
BOOST_REQUIRE(tc.active());
|
||||
@ -183,7 +176,8 @@ BOOST_FIXTURE_TEST_CASE(
|
||||
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
|
||||
BOOST_REQUIRE(cc.before_prepare() == 0);
|
||||
BOOST_REQUIRE(cc.after_prepare() == 0);
|
||||
sc.provider().commit_order_enter_result_ = wsrep::provider::error_bf_abort;
|
||||
sc.provider().commit_order_enter_result_
|
||||
= wsrep::provider::error_bf_abort;
|
||||
BOOST_REQUIRE(cc.before_commit());
|
||||
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_must_replay);
|
||||
BOOST_REQUIRE(cc.will_replay_called() == true);
|
||||
@ -205,7 +199,6 @@ BOOST_FIXTURE_TEST_CASE(
|
||||
// STREAMING REPLICATION //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_streaming_2pc_commit,
|
||||
streaming_client_fixture_row)
|
||||
{
|
||||
@ -251,8 +244,9 @@ BOOST_FIXTURE_TEST_CASE(transaction_streaming_2pc_commit_two_statements,
|
||||
// internally. This will cause the transaction to leave before_prepare()
|
||||
// in aborted state.
|
||||
//
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_streaming_2pc_bf_abort_during_fragment_removal,
|
||||
streaming_client_fixture_row)
|
||||
BOOST_FIXTURE_TEST_CASE(
|
||||
transaction_streaming_2pc_bf_abort_during_fragment_removal,
|
||||
streaming_client_fixture_row)
|
||||
{
|
||||
BOOST_REQUIRE(cc.start_transaction(wsrep::transaction_id(1)) == 0);
|
||||
BOOST_REQUIRE(cc.after_row() == 0);
|
||||
@ -270,8 +264,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_streaming_2pc_bf_abort_during_fragment_remov
|
||||
// APPLYING //
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_2pc_applying,
|
||||
applying_client_fixture_2pc)
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_2pc_applying, applying_client_fixture_2pc)
|
||||
{
|
||||
BOOST_REQUIRE(cc.before_prepare() == 0);
|
||||
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_preparing);
|
||||
|
@ -1,11 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2025 Codership Oy <info@codership.com>
|
||||
*
|
||||
* This file is part of wsrep-lib.
|
||||
*
|
||||
* Wsrep-lib is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Wsrep-lib is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with wsrep-lib. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "client_state_fixture.hpp"
|
||||
#include <iostream>
|
||||
|
||||
//
|
||||
// Test a successful XA transaction lifecycle
|
||||
//
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_xa,
|
||||
replicating_client_fixture_sync_rm)
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_xa, replicating_client_fixture_sync_rm)
|
||||
{
|
||||
wsrep::xid xid(1, 9, 0, "test xid");
|
||||
|
||||
@ -47,7 +64,6 @@ BOOST_FIXTURE_TEST_CASE(transaction_xa,
|
||||
BOOST_REQUIRE(cc.current_error() == wsrep::e_success);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Test detaching of XA transactions
|
||||
//
|
||||
@ -119,7 +135,6 @@ BOOST_FIXTURE_TEST_CASE(transaction_xa_detach_rollback_by_xid,
|
||||
server_service.release_high_priority_service(hps);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Test XA replay
|
||||
//
|
||||
@ -214,8 +229,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_xa_replay_after_command_after_result,
|
||||
//
|
||||
// Test a successful XA transaction lifecycle (applying side)
|
||||
//
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_xa_applying,
|
||||
applying_client_fixture)
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_xa_applying, applying_client_fixture)
|
||||
{
|
||||
wsrep::xid xid(1, 9, 0, "test xid");
|
||||
|
||||
@ -249,8 +263,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_xa_applying,
|
||||
//
|
||||
// Test a successful XA transaction lifecycle
|
||||
//
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_xa_sr,
|
||||
streaming_client_fixture_byte)
|
||||
BOOST_FIXTURE_TEST_CASE(transaction_xa_sr, streaming_client_fixture_byte)
|
||||
{
|
||||
wsrep::xid xid(1, 9, 0, "test xid");
|
||||
|
||||
|
Reference in New Issue
Block a user