From 8bfce04189671eb1f06e0fa83dff8c880f31088f Mon Sep 17 00:00:00 2001 From: Daniele Sciascia Date: Fri, 8 Apr 2022 14:44:22 +0200 Subject: [PATCH] Fix cleanup for non-prepared XA transactions Cleanup XA transaction which is marked as prepared in DBMS, but not in wsrep-lib side. This may happen if the DBMS runs with wsrep disabled. --- include/wsrep/client_state.hpp | 2 +- src/transaction.cpp | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/wsrep/client_state.hpp b/include/wsrep/client_state.hpp index b502cbd..138bf5f 100644 --- a/include/wsrep/client_state.hpp +++ b/include/wsrep/client_state.hpp @@ -633,7 +633,7 @@ namespace wsrep void xa_detach() { assert(mode_ == m_local); - assert(state_ == s_none || state_ == s_exec); + assert(state_ == s_none || state_ == s_exec || state_ == s_quitting); transaction_.xa_detach(); } diff --git a/src/transaction.cpp b/src/transaction.cpp index 5b30b88..764b183 100644 --- a/src/transaction.cpp +++ b/src/transaction.cpp @@ -1193,11 +1193,15 @@ int wsrep::transaction::commit_or_rollback_by_xid(const wsrep::xid& xid, void wsrep::transaction::xa_detach() { debug_log_state("xa_detach enter"); - assert(state() == s_prepared); - wsrep::server_state& server_state(client_state_.server_state()); - server_state.convert_streaming_client_to_applier(&client_state_); - client_service_.store_globals(); - client_service_.cleanup_transaction(); + assert(state() == s_prepared || + client_state_.state() == wsrep::client_state::s_quitting); + if (state() == s_prepared) + { + wsrep::server_state& server_state(client_state_.server_state()); + server_state.convert_streaming_client_to_applier(&client_state_); + client_service_.store_globals(); + client_service_.cleanup_transaction(); + } wsrep::unique_lock lock(client_state_.mutex_); streaming_context_.cleanup(); state(lock, s_aborting);