1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-07-30 07:23:07 +03:00
- populate and pass real error description buffer to provider in case
   of applying error
 - return 0 from server_state::on_apply() if error voting confirmed
   consistency
 - remove fragments and rollback after fragment applying failure
 - always release streaming applier on commit or rollback
This commit is contained in:
Alexey Yurchenko
2019-04-30 19:00:48 +03:00
parent fd66bdef0b
commit 0f676bd893
22 changed files with 470 additions and 187 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Codership Oy <info@codership.com>
* Copyright (C) 2018-2019 Codership Oy <info@codership.com>
*
* This file is part of wsrep-lib.
*
@ -19,6 +19,7 @@
#include "mock_high_priority_service.hpp"
#include "mock_server_state.hpp"
#include <sstream>
int wsrep::mock_high_priority_service::start_transaction(
const wsrep::ws_handle& ws_handle, const wsrep::ws_meta& ws_meta)
@ -34,13 +35,25 @@ int wsrep::mock_high_priority_service::adopt_transaction(
}
int wsrep::mock_high_priority_service::apply_write_set(
const wsrep::ws_meta&,
const wsrep::const_buffer&)
const wsrep::ws_meta& meta,
const wsrep::const_buffer&,
wsrep::mutable_buffer& err)
{
assert(client_state_->toi_meta().seqno().is_undefined());
assert(client_state_->transaction().state() == wsrep::transaction::s_executing ||
client_state_->transaction().state() == wsrep::transaction::s_replaying);
return (fail_next_applying_ ? 1 : 0);
if (fail_next_applying_)
{
std::ostringstream os;
os << "failed " << meta;
err.push_back(os.str());
assert(err.size() > 0);
return 1;
}
else
{
return 0;
};
}
int wsrep::mock_high_priority_service::commit(
@ -69,14 +82,29 @@ int wsrep::mock_high_priority_service::rollback(
}
int wsrep::mock_high_priority_service::apply_toi(const wsrep::ws_meta&,
const wsrep::const_buffer&)
const wsrep::const_buffer&,
wsrep::mutable_buffer&)
{
assert(client_state_->transaction().active() == false);
assert(client_state_->toi_meta().seqno().is_undefined() == false);
return (fail_next_toi_ ? 1 : 0);
}
void wsrep::mock_high_priority_service::adopt_apply_error(
wsrep::mutable_buffer& err)
{
client_state_->adopt_apply_error(err);
}
void wsrep::mock_high_priority_service::after_apply()
{
client_state_->after_applying();
}
int wsrep::mock_high_priority_service::log_dummy_write_set(
const wsrep::ws_handle&,
const wsrep::ws_meta&,
wsrep::mutable_buffer& err)
{
return err.size() > 0;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Codership Oy <info@codership.com>
* Copyright (C) 2018-2019 Codership Oy <info@codership.com>
*
* This file is part of wsrep-lib.
*
@ -47,7 +47,8 @@ namespace wsrep
{ return client_state_->transaction(); }
int adopt_transaction(const wsrep::transaction&) WSREP_OVERRIDE;
int apply_write_set(const wsrep::ws_meta&,
const wsrep::const_buffer&) WSREP_OVERRIDE;
const wsrep::const_buffer&,
wsrep::mutable_buffer&) WSREP_OVERRIDE;
int append_fragment_and_commit(
const wsrep::ws_handle&,
const wsrep::ws_meta&,
@ -59,21 +60,23 @@ namespace wsrep
WSREP_OVERRIDE;
int rollback(const wsrep::ws_handle&, const wsrep::ws_meta&) WSREP_OVERRIDE;
int apply_toi(const wsrep::ws_meta&,
const wsrep::const_buffer&) WSREP_OVERRIDE;
const wsrep::const_buffer&,
wsrep::mutable_buffer&) WSREP_OVERRIDE;
void adopt_apply_error(wsrep::mutable_buffer& err) WSREP_OVERRIDE;
void after_apply() WSREP_OVERRIDE;
void store_globals() WSREP_OVERRIDE { }
void reset_globals() WSREP_OVERRIDE { }
void switch_execution_context(wsrep::high_priority_service&)
WSREP_OVERRIDE { }
int log_dummy_write_set(const wsrep::ws_handle&,
const wsrep::ws_meta&)
WSREP_OVERRIDE { return 0; }
const wsrep::ws_meta&,
wsrep::mutable_buffer&) WSREP_OVERRIDE;
bool is_replaying() const WSREP_OVERRIDE { return replaying_; }
void debug_crash(const char*) WSREP_OVERRIDE { /* Not in unit tests*/}
wsrep::mock_client_state* client_state()
wsrep::client_state& client_state()
{
return client_state_;
return *client_state_;
}
bool do_2pc_;
bool fail_next_applying_;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Codership Oy <info@codership.com>
* Copyright (C) 2018-2019 Codership Oy <info@codership.com>
*
* This file is part of wsrep-lib.
*
@ -172,12 +172,15 @@ namespace wsrep
}
int commit_order_leave(const wsrep::ws_handle& ws_handle,
const wsrep::ws_meta& ws_meta)
const wsrep::ws_meta& ws_meta,
const wsrep::mutable_buffer& err)
WSREP_OVERRIDE
{
BOOST_REQUIRE(ws_handle.opaque());
BOOST_REQUIRE(ws_meta.seqno().is_undefined() == false);
return commit_order_leave_result_;
return err.size() > 0 ?
wsrep::provider::error_fatal :
commit_order_leave_result_;
}
int release(wsrep::ws_handle& )
@ -195,7 +198,8 @@ namespace wsrep
wsrep::mock_high_priority_service& high_priority_service(
*static_cast<wsrep::mock_high_priority_service*>(hps));
wsrep::mock_client_state& cc(
*high_priority_service.client_state());
static_cast<wsrep::mock_client_state&>(
high_priority_service.client_state()));
wsrep::high_priority_context high_priority_context(cc);
const wsrep::transaction& tc(cc.transaction());
wsrep::ws_meta ws_meta;
@ -238,7 +242,8 @@ namespace wsrep
int)
WSREP_OVERRIDE
{ return wsrep::provider::success; }
enum wsrep::provider::status leave_toi(wsrep::client_id)
enum wsrep::provider::status leave_toi(wsrep::client_id,
const wsrep::mutable_buffer&)
WSREP_OVERRIDE
{ return wsrep::provider::success; }

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Codership Oy <info@codership.com>
* Copyright (C) 2018-2019 Codership Oy <info@codership.com>
*
* This file is part of wsrep-lib.
*
@ -102,7 +102,7 @@ namespace wsrep
{
mock_high_priority_service* mhps(
static_cast<mock_high_priority_service*>(high_priority_service));
wsrep::mock_client* cs(static_cast<wsrep::mock_client*>(
wsrep::mock_client* cs(&static_cast<wsrep::mock_client&>(
mhps->client_state()));
cs->after_command_before_result();
cs->after_command_after_result();

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Codership Oy <info@codership.com>
* Copyright (C) 2018-2019 Codership Oy <info@codership.com>
*
* This file is part of wsrep-lib.
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Codership Oy <info@codership.com>
* Copyright (C) 2018-2019 Codership Oy <info@codership.com>
*
* This file is part of wsrep-lib.
*
@ -239,6 +239,8 @@ BOOST_FIXTURE_TEST_CASE(server_state_applying_2pc,
BOOST_FIXTURE_TEST_CASE(server_state_applying_1pc_rollback,
applying_server_fixture)
{
/* make sure default success result is flipped to error_fatal */
ss.provider().commit_order_leave_result_ = wsrep::provider::success;
hps.fail_next_applying_ = true;
char buf[1] = { 1 };
BOOST_REQUIRE(ss.on_apply(hps, ws_handle, ws_meta,
@ -252,6 +254,8 @@ BOOST_FIXTURE_TEST_CASE(server_state_applying_1pc_rollback,
BOOST_FIXTURE_TEST_CASE(server_state_applying_2pc_rollback,
applying_server_fixture)
{
/* make sure default success result is flipped to error_fatal */
ss.provider().commit_order_leave_result_ = wsrep::provider::success;
hps.do_2pc_ = true;
hps.fail_next_applying_ = true;
char buf[1] = { 1 };

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Codership Oy <info@codership.com>
* Copyright (C) 2018-2019 Codership Oy <info@codership.com>
*
* This file is part of wsrep-lib.
*

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Codership Oy <info@codership.com>
* Copyright (C) 2018-2019 Codership Oy <info@codership.com>
*
* This file is part of wsrep-lib.
*