1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-12-08 22:28:32 +03:00

Removed is_autocommi() from client_service interface as it is not

quite useful as there might not be enough information for it
after the statement has been processed. Better to handle retrying
on DBMS side. Also removed after_statement_result enumeration and
return plain int from after_statement().
This commit is contained in:
Teemu Ollakka
2018-07-06 19:48:48 +03:00
parent 3ff322386c
commit af18a10a49
6 changed files with 35 additions and 61 deletions

View File

@@ -20,11 +20,6 @@ namespace db
, client_state_(client_state)
{ }
bool is_autocommit() const override
{
return client_state_.is_autocommit();
}
bool do_2pc() const override
{
return client_state_.do_2pc();

View File

@@ -25,11 +25,6 @@ namespace wsrep
public:
client_service() { }
/**
*
*/
virtual bool is_autocommit() const = 0;
/**
* Return true if two pahase commit is required for transaction
* to commit.

View File

@@ -223,28 +223,13 @@ namespace wsrep
*/
int before_statement();
/**
* Return values for after_statement() method.
*/
enum after_statement_result
{
/** Statement was executed succesfully */
asr_success,
/** Statement execution encountered an error, the transaction
* was rolled back */
asr_error,
/** Statement execution encountered an error, the transaction
was rolled back. However the statement was self contained
(e.g. autocommit statement) so it can be retried. */
asr_may_retry
};
/**
* After statement execution operations.
*
* * Check for must_replay state
* * Do rollback if requested
*/
enum after_statement_result after_statement();
int after_statement();
/** @} */
/**

View File

@@ -189,8 +189,7 @@ int wsrep::client_state::before_statement()
return 0;
}
enum wsrep::client_state::after_statement_result
wsrep::client_state::after_statement()
int wsrep::client_state::after_statement()
{
// wsrep::unique_lock<wsrep::mutex> lock(mutex_);
debug_log_state("after_statement: enter");
@@ -206,16 +205,16 @@ wsrep::client_state::after_statement()
if (mode_ == m_replicating)
{
debug_log_state("after_statement: may_retry");
return asr_may_retry;
return 1;
}
else
{
debug_log_state("after_statement: error");
return asr_error;
return 1;
}
}
debug_log_state("after_statement: success");
return asr_success;
return 0;
}
int wsrep::client_state::enable_streaming(

View File

@@ -52,7 +52,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(transaction_1pc, T,
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_executing);
// Verify that the commit can be succesfully executed in separate command
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
cc.after_command_before_result();
cc.after_command_after_result();
BOOST_REQUIRE(cc.current_error() == wsrep::e_success);
@@ -341,7 +341,7 @@ BOOST_FIXTURE_TEST_CASE(
BOOST_REQUIRE(cc.before_commit());
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_must_replay);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_error);
BOOST_REQUIRE(cc.after_statement() );
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_aborted);
BOOST_REQUIRE(cc.current_error() == wsrep::e_deadlock_error);
BOOST_REQUIRE(tc.active() == false);
@@ -418,7 +418,7 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(
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() == wsrep::client_state::asr_error);
BOOST_REQUIRE(cc.after_statement() );
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.ordered() == false);
BOOST_REQUIRE(tc.certified() == false);
@@ -849,7 +849,7 @@ BOOST_FIXTURE_TEST_CASE(
BOOST_REQUIRE(cc.current_error() == wsrep::e_deadlock_error);
BOOST_REQUIRE(cc.before_rollback() == 0);
BOOST_REQUIRE(cc.after_rollback() == 0);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_may_retry);
BOOST_REQUIRE(cc.after_statement());
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_aborted);
BOOST_REQUIRE(cc.state() == wsrep::client_state::s_exec);
@@ -986,7 +986,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_row_streaming_1pc_commit,
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_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(sc.provider().fragments() == 2);
BOOST_REQUIRE(sc.provider().start_fragments() == 1);
BOOST_REQUIRE(sc.provider().commit_fragments() == 1);
@@ -1008,7 +1008,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_row_batch_streaming_1pc_commit,
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_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(sc.provider().fragments() == 2);
BOOST_REQUIRE(sc.provider().start_fragments() == 1);
BOOST_REQUIRE(sc.provider().commit_fragments() == 1);
@@ -1024,14 +1024,14 @@ BOOST_FIXTURE_TEST_CASE(
BOOST_REQUIRE(cc.start_transaction(1) == 0);
BOOST_REQUIRE(cc.after_row() == 0);
BOOST_REQUIRE(tc.streaming_context_.fragments_certified() == 1);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
BOOST_REQUIRE(cc.after_row() == 0);
BOOST_REQUIRE(tc.streaming_context_.fragments_certified() == 2);
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_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(sc.provider().fragments() == 3);
BOOST_REQUIRE(sc.provider().start_fragments() == 1);
BOOST_REQUIRE(sc.provider().commit_fragments() == 1);
@@ -1048,7 +1048,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_row_streaming_rollback,
BOOST_REQUIRE(tc.streaming_context_.fragments_certified() == 1);
BOOST_REQUIRE(cc.before_rollback() == 0);
BOOST_REQUIRE(cc.after_rollback() == 0);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(sc.provider().fragments() == 2);
BOOST_REQUIRE(sc.provider().start_fragments() == 1);
BOOST_REQUIRE(sc.provider().rollback_fragments() == 1);
@@ -1068,7 +1068,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_row_streaming_cert_fail_non_commit,
sc.provider().certify_result_ = wsrep::provider::success;
BOOST_REQUIRE(cc.before_rollback() == 0);
BOOST_REQUIRE(cc.after_rollback() == 0);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(sc.provider().fragments() == 2);
BOOST_REQUIRE(sc.provider().start_fragments() == 1);
BOOST_REQUIRE(sc.provider().rollback_fragments() == 1);
@@ -1089,7 +1089,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_row_streaming_cert_fail_commit,
sc.provider().certify_result_ = wsrep::provider::success;
BOOST_REQUIRE(cc.before_rollback() == 0);
BOOST_REQUIRE(cc.after_rollback() == 0);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_error);
BOOST_REQUIRE(cc.after_statement() );
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_aborted);
BOOST_REQUIRE(sc.provider().fragments() == 2);
BOOST_REQUIRE(sc.provider().start_fragments() == 1);
@@ -1112,7 +1112,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_row_streaming_bf_abort_committing,
BOOST_REQUIRE(cc.before_rollback() == 0);
BOOST_REQUIRE(cc.after_rollback() == 0);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_must_replay);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_committed);
BOOST_REQUIRE(sc.provider().fragments() == 2);
BOOST_REQUIRE(sc.provider().start_fragments() == 1);
@@ -1131,7 +1131,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_byte_streaming_1pc_commit,
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_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(sc.provider().fragments() == 2);
BOOST_REQUIRE(sc.provider().start_fragments() == 1);
BOOST_REQUIRE(sc.provider().commit_fragments() == 1);
@@ -1153,7 +1153,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_byte_batch_streaming_1pc_commit,
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_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(sc.provider().fragments() == 2);
BOOST_REQUIRE(sc.provider().start_fragments() == 1);
BOOST_REQUIRE(sc.provider().commit_fragments() == 1);
@@ -1169,13 +1169,13 @@ BOOST_FIXTURE_TEST_CASE(transaction_statement_streaming_1pc_commit,
BOOST_REQUIRE(cc.start_transaction(1) == 0);
BOOST_REQUIRE(cc.after_row() == 0);
BOOST_REQUIRE(tc.streaming_context_.fragments_certified() == 0);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(tc.streaming_context_.fragments_certified() == 1);
BOOST_REQUIRE(cc.before_statement() == 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_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(sc.provider().fragments() == 2);
BOOST_REQUIRE(sc.provider().start_fragments() == 1);
BOOST_REQUIRE(sc.provider().commit_fragments() == 1);
@@ -1190,18 +1190,18 @@ BOOST_FIXTURE_TEST_CASE(transaction_statement_batch_streaming_1pc_commit,
BOOST_REQUIRE(cc.start_transaction(1) == 0);
BOOST_REQUIRE(cc.after_row() == 0);
BOOST_REQUIRE(tc.streaming_context_.fragments_certified() == 0);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(tc.streaming_context_.fragments_certified() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
BOOST_REQUIRE(cc.after_row() == 0);
BOOST_REQUIRE(tc.streaming_context_.fragments_certified() == 0);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(tc.streaming_context_.fragments_certified() == 1);
BOOST_REQUIRE(cc.before_statement() == 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_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(sc.provider().fragments() == 2);
BOOST_REQUIRE(sc.provider().start_fragments() == 1);
BOOST_REQUIRE(sc.provider().commit_fragments() == 1);
@@ -1217,7 +1217,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_statement_streaming_cert_fail,
BOOST_REQUIRE(cc.after_row() == 0);
BOOST_REQUIRE(tc.streaming_context_.fragments_certified() == 0);
sc.provider().certify_result_ = wsrep::provider::error_certification_failed;
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_error);
BOOST_REQUIRE(cc.after_statement());
BOOST_REQUIRE(cc.current_error() == wsrep::e_deadlock_error);
BOOST_REQUIRE(sc.provider().fragments() == 0);
BOOST_REQUIRE(sc.provider().start_fragments() == 0);

View File

@@ -24,7 +24,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_2pc,
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_ordered_commit);
BOOST_REQUIRE(cc.after_commit() == 0);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_committed);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.ordered() == false);
BOOST_REQUIRE(tc.certified() == false);
@@ -51,7 +51,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() == wsrep::client_state::asr_error);
BOOST_REQUIRE(cc.after_statement() );
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.ordered() == false);
BOOST_REQUIRE(tc.certified() == false);
@@ -80,7 +80,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() == wsrep::client_state::asr_error);
BOOST_REQUIRE(cc.after_statement() );
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.ordered() == false);
BOOST_REQUIRE(tc.certified() == false);
@@ -108,7 +108,7 @@ BOOST_FIXTURE_TEST_CASE(
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_must_replay);
BOOST_REQUIRE(cc.after_rollback() == 0);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_must_replay);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.ordered() == false);
BOOST_REQUIRE(tc.certified() == false);
@@ -140,7 +140,7 @@ BOOST_FIXTURE_TEST_CASE(
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_must_replay);
BOOST_REQUIRE(cc.after_rollback() == 0);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_must_replay);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.ordered() == false);
BOOST_REQUIRE(tc.certified() == false);
@@ -172,7 +172,7 @@ BOOST_FIXTURE_TEST_CASE(
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_must_replay);
BOOST_REQUIRE(cc.after_rollback() == 0);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_must_replay);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(tc.ordered() == false);
BOOST_REQUIRE(tc.certified() == false);
@@ -195,7 +195,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_streaming_2pc_commit,
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_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(sc.provider().fragments() == 2);
BOOST_REQUIRE(sc.provider().start_fragments() == 1);
BOOST_REQUIRE(sc.provider().commit_fragments() == 1);
@@ -207,7 +207,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_streaming_2pc_commit_two_statements,
BOOST_REQUIRE(cc.start_transaction(1) == 0);
BOOST_REQUIRE(cc.after_row() == 0);
BOOST_REQUIRE(tc.streaming_context_.fragments_certified() == 1);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(cc.before_statement() == 0);
BOOST_REQUIRE(cc.after_row() == 0);
BOOST_REQUIRE(tc.streaming_context_.fragments_certified() == 2);
@@ -216,7 +216,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_streaming_2pc_commit_two_statements,
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_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(sc.provider().fragments() == 3);
BOOST_REQUIRE(sc.provider().start_fragments() == 1);
BOOST_REQUIRE(sc.provider().commit_fragments() == 1);
@@ -239,7 +239,7 @@ BOOST_FIXTURE_TEST_CASE(transaction_2pc_applying,
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_ordered_commit);
BOOST_REQUIRE(cc.after_commit() == 0);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_committed);
BOOST_REQUIRE(cc.after_statement() == wsrep::client_state::asr_success);
BOOST_REQUIRE(cc.after_statement() == 0);
BOOST_REQUIRE(tc.state() == wsrep::transaction::s_committed);
BOOST_REQUIRE(tc.active() == false);
BOOST_REQUIRE(cc.current_error() == wsrep::e_success);