1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-08-05 04:01:12 +03:00

Extract before_prepare_local()/before_prepare_high_priority()

This commit is contained in:
Teemu Ollakka
2023-04-04 14:55:51 +03:00
parent 55a0bd6469
commit a36bae31d8
2 changed files with 114 additions and 88 deletions

View File

@@ -238,6 +238,8 @@ namespace wsrep
wsrep::provider& provider();
void flags(int flags) { flags_ = flags; }
int before_prepare_local(wsrep::unique_lock<wsrep::mutex>&);
int before_prepare_high_priority(wsrep::unique_lock<wsrep::mutex>&);
int before_commit_local(wsrep::unique_lock<wsrep::mutex>&);
int before_commit_high_priority(wsrep::unique_lock<wsrep::mutex>&);
// Return true if the transaction must abort, is aborting,

View File

@@ -225,6 +225,8 @@ int wsrep::transaction::prepare_for_ordering(
int wsrep::transaction::assign_read_view(const wsrep::gtid* const gtid)
{
assert(active());
assert(client_state_.mode() == wsrep::client_state::m_local);
try
{
return provider().assign_read_view(ws_handle_, gtid);
@@ -239,6 +241,7 @@ int wsrep::transaction::assign_read_view(const wsrep::gtid* const gtid)
int wsrep::transaction::append_key(const wsrep::key& key)
{
assert(active());
assert(client_state_.mode() == wsrep::client_state::m_local);
try
{
debug_log_key_append(key);
@@ -255,11 +258,13 @@ int wsrep::transaction::append_key(const wsrep::key& key)
int wsrep::transaction::append_data(const wsrep::const_buffer& data)
{
assert(active());
assert(client_state_.mode() == wsrep::client_state::m_local);
return provider().append_data(ws_handle_, data);
}
int wsrep::transaction::after_row()
{
assert(client_state_.mode() == wsrep::client_state::m_local);
wsrep::unique_lock<wsrep::mutex> lock(client_state_.mutex());
debug_log_state("after_row_enter");
int ret(0);
@@ -272,25 +277,21 @@ int wsrep::transaction::after_row()
return ret;
}
int wsrep::transaction::before_prepare(
int wsrep::transaction::before_prepare_local(
wsrep::unique_lock<wsrep::mutex>& lock)
{
assert(lock.owns_lock());
int ret(0);
debug_log_state("before_prepare_enter");
assert(client_state_.mode() == wsrep::client_state::m_local);
assert(state() == s_executing || state() == s_must_abort ||
state() == s_replaying);
if (state() == s_must_abort)
{
assert(client_state_.mode() == wsrep::client_state::m_local);
client_state_.override_error(wsrep::e_deadlock_error);
return 1;
}
switch (client_state_.mode())
{
case wsrep::client_state::m_local:
int ret = 0;
if (is_streaming())
{
client_service_.debug_crash(
@@ -298,8 +299,7 @@ int wsrep::transaction::before_prepare(
lock.unlock();
if (client_service_.statement_allowed_for_streaming() == false)
{
client_state_.override_error(
wsrep::e_error_during_commit,
client_state_.override_error(wsrep::e_error_during_commit,
wsrep::provider::error_not_allowed);
ret = 1;
}
@@ -345,33 +345,53 @@ int wsrep::transaction::before_prepare(
ret = certify_commit(lock);
}
assert((ret == 0 && state() == s_preparing) ||
(state() == s_must_abort ||
state() == s_must_replay ||
state() == s_cert_failed));
assert((ret == 0 && state() == s_preparing)
|| (state() == s_must_abort || state() == s_must_replay
|| state() == s_cert_failed));
if (ret)
{
assert(state() == s_must_replay ||
client_state_.current_error());
assert(state() == s_must_replay || client_state_.current_error());
ret = 1;
}
}
return ret;
}
break;
case wsrep::client_state::m_high_priority:
int wsrep::transaction::before_prepare_high_priority(
wsrep::unique_lock<wsrep::mutex>& lock)
{
assert(lock.owns_lock());
assert(client_state_.mode() == wsrep::client_state::m_high_priority);
assert(state() == s_executing || state() == s_replaying);
// Note: fragment removal is done from applying
// context for high priority mode.
if (is_xa())
{
assert(state() == s_executing ||
state() == s_replaying);
assert(state() == s_executing || state() == s_replaying);
if (state() == s_replaying)
{
break;
return 0;
}
}
state(lock, s_preparing);
return 0;
}
int wsrep::transaction::before_prepare(
wsrep::unique_lock<wsrep::mutex>& lock)
{
assert(lock.owns_lock());
int ret(0);
debug_log_state("before_prepare_enter");
switch (client_state_.mode())
{
case wsrep::client_state::m_local:
ret = before_prepare_local(lock);
break;
case wsrep::client_state::m_high_priority:
ret = before_prepare_high_priority(lock);
break;
default:
assert(0);
@@ -441,6 +461,8 @@ int wsrep::transaction::after_prepare(
int wsrep::transaction::before_commit_local(
wsrep::unique_lock<wsrep::mutex>& lock)
{
assert(lock.owns_lock());
int ret = 1;
assert(state() == s_executing || state() == s_prepared
|| state() == s_committing || state() == s_must_abort
@@ -512,6 +534,8 @@ int wsrep::transaction::before_commit_local(
int wsrep::transaction::before_commit_high_priority(
wsrep::unique_lock<wsrep::mutex>& lock)
{
assert(lock.owns_lock());
int ret = 1;
assert(certified());
assert(ordered());