1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-07-28 20:02:00 +03:00

Call before/after prepare from before_commit() when 1PC

before_prepare() call prepares removal SR fragments from stable
storage and the logic should be duplicated in before_commit()
otherwise.
This commit is contained in:
Teemu Ollakka
2018-06-13 13:04:33 +03:00
parent a7adcb01ba
commit f07885e204
4 changed files with 17 additions and 17 deletions

View File

@ -262,14 +262,16 @@ namespace wsrep
} }
int before_prepare() int before_prepare()
{ {
wsrep::unique_lock<wsrep::mutex> lock(mutex_);
assert(state_ == s_exec); assert(state_ == s_exec);
return transaction_.before_prepare(); return transaction_.before_prepare(lock);
} }
int after_prepare() int after_prepare()
{ {
wsrep::unique_lock<wsrep::mutex> lock(mutex_);
assert(state_ == s_exec); assert(state_ == s_exec);
return transaction_.after_prepare(); return transaction_.after_prepare(lock);
} }
int before_commit() int before_commit()

View File

@ -98,9 +98,9 @@ namespace wsrep
int after_row(); int after_row();
int before_prepare(); int before_prepare(wsrep::unique_lock<wsrep::mutex>&);
int after_prepare(); int after_prepare(wsrep::unique_lock<wsrep::mutex>&);
int before_commit(); int before_commit();

View File

@ -115,11 +115,11 @@ int wsrep::transaction_context::after_row()
return 0; return 0;
} }
int wsrep::transaction_context::before_prepare() int wsrep::transaction_context::before_prepare(
wsrep::unique_lock<wsrep::mutex>& lock)
{ {
assert(lock.owns_lock());
int ret(0); int ret(0);
wsrep::unique_lock<wsrep::mutex> lock(client_context_.mutex());
debug_log_state("before_prepare_enter"); debug_log_state("before_prepare_enter");
assert(state() == s_executing || state() == s_must_abort); assert(state() == s_executing || state() == s_must_abort);
@ -168,10 +168,11 @@ int wsrep::transaction_context::before_prepare()
return ret; return ret;
} }
int wsrep::transaction_context::after_prepare() int wsrep::transaction_context::after_prepare(
wsrep::unique_lock<wsrep::mutex>& lock)
{ {
assert(lock.owns_lock());
int ret(1); int ret(1);
wsrep::unique_lock<wsrep::mutex> lock(client_context_.mutex());
debug_log_state("after_prepare_enter"); debug_log_state("after_prepare_enter");
assert(state() == s_preparing || state() == s_must_abort); assert(state() == s_preparing || state() == s_must_abort);
if (state() == s_must_abort) if (state() == s_must_abort)
@ -185,7 +186,7 @@ int wsrep::transaction_context::after_prepare()
{ {
case wsrep::client_context::m_replicating: case wsrep::client_context::m_replicating:
ret = certify_commit(lock); ret = certify_commit(lock);
assert((ret == 0 || state() == s_committing) || assert((ret == 0 && state() == s_committing) ||
(state() == s_must_abort || (state() == s_must_abort ||
state() == s_must_replay || state() == s_must_replay ||
state() == s_cert_failed)); state() == s_cert_failed));
@ -226,12 +227,10 @@ int wsrep::transaction_context::before_commit()
} }
break; break;
case wsrep::client_context::m_replicating: case wsrep::client_context::m_replicating:
// Commit is one phase - before/after prepare was not called
if (state() == s_executing) if (state() == s_executing)
{ {
ret = certify_commit(lock); ret = before_prepare(lock) || after_prepare(lock);
assert((ret == 0 || state() == s_committing) assert((ret == 0 && state() == s_committing)
|| ||
(state() == s_must_abort || (state() == s_must_abort ||
state() == s_must_replay || state() == s_must_replay ||
@ -278,7 +277,6 @@ int wsrep::transaction_context::before_commit()
assert(0); assert(0);
break; break;
} }
} }
break; break;
case wsrep::client_context::m_applier: case wsrep::client_context::m_applier:

View File

@ -19,11 +19,11 @@ int wsrep::fake_client_context::commit()
int ret(0); int ret(0);
if (do_2pc()) if (do_2pc())
{ {
if (transaction_.before_prepare()) if (before_prepare())
{ {
ret = 1; ret = 1;
} }
else if (transaction_.after_prepare()) else if (after_prepare())
{ {
ret = 1; ret = 1;
} }