Skip to content

Commit 62bd408

Browse files
author
Daniele Sciascia
committed
Remove duplicate logic from after_statement
Remove bf abort handling `client_state::after_statement()`, since the same logic already appears later in `transaction::after_statement()`. Also, introduce `transaction::after_statement()` overload which takes a lock.
1 parent 7dafce8 commit 62bd408

File tree

3 files changed

+12
-28
lines changed

3 files changed

+12
-28
lines changed

include/wsrep/transaction.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ namespace wsrep
192192
int before_statement();
193193

194194
int after_statement();
195+
int after_statement(wsrep::unique_lock<wsrep::mutex>&);
195196

196197
void after_command_must_abort(wsrep::unique_lock<wsrep::mutex>&);
197198

src/client_state.cpp

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ int wsrep::client_state::before_command(bool keep_command_error)
168168
}
169169

170170
// Clean up the transaction and return error.
171-
lock.unlock();
172-
(void)transaction_.after_statement();
173-
lock.lock();
171+
(void)transaction_.after_statement(lock);
174172

175173
assert(transaction_.active() == false);
176174
assert(transaction_.state() == wsrep::transaction::s_aborted);
@@ -199,9 +197,7 @@ void wsrep::client_state::after_command_before_result()
199197
// hook.
200198
if (not keep_command_error_)
201199
{
202-
lock.unlock();
203-
(void)transaction_.after_statement();
204-
lock.lock();
200+
(void)transaction_.after_statement(lock);
205201
}
206202

207203
assert(transaction_.state() == wsrep::transaction::s_aborted);
@@ -266,37 +262,18 @@ int wsrep::client_state::after_statement()
266262
debug_log_state("after_statement: enter");
267263
assert(state() == s_exec);
268264
assert(mode() == m_local);
269-
270-
if (transaction_.active() &&
271-
transaction_.state() == wsrep::transaction::s_must_abort)
272-
{
273-
lock.unlock();
274-
client_service_.bf_rollback();
275-
lock.lock();
276-
assert(transaction_.state() == wsrep::transaction::s_aborted);
277-
// Error may be set already. For example, if fragment size
278-
// exceeded the maximum size in certify_fragment(), then
279-
// we already have wsrep::e_error_during_commit
280-
if (current_error() == wsrep::e_success)
281-
{
282-
override_error(wsrep::e_deadlock_error);
283-
}
284-
}
285-
lock.unlock();
286-
287-
(void)transaction_.after_statement();
265+
(void)transaction_.after_statement(lock);
288266
if (current_error() == wsrep::e_deadlock_error)
289267
{
290268
if (mode_ == m_local)
291269
{
292270
debug_log_state("after_statement: may_retry");
293-
return 1;
294271
}
295272
else
296273
{
297274
debug_log_state("after_statement: error");
298-
return 1;
299275
}
276+
return 1;
300277
}
301278
debug_log_state("after_statement: success");
302279
return 0;

src/transaction.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,10 +815,16 @@ void wsrep::transaction::remove_fragments_in_storage_service_scope(
815815
}
816816

817817
int wsrep::transaction::after_statement()
818+
{
819+
wsrep::unique_lock<wsrep::mutex> lock(client_state_.mutex());
820+
return after_statement(lock);
821+
}
822+
823+
int wsrep::transaction::after_statement(wsrep::unique_lock<wsrep::mutex>& lock)
818824
{
819825
int ret(0);
820-
wsrep::unique_lock<wsrep::mutex> lock(client_state_.mutex());
821826
debug_log_state("after_statement_enter");
827+
assert(lock.owns_lock());
822828
assert(client_state_.mode() == wsrep::client_state::m_local);
823829
assert(state() == s_executing ||
824830
state() == s_prepared ||

0 commit comments

Comments
 (0)