From 6a17207b7f44379cdcd73d69203c1a37b901c9d3 Mon Sep 17 00:00:00 2001 From: Daniele Sciascia Date: Fri, 19 Jan 2024 14:20:05 +0100 Subject: [PATCH] Add method client_service::is_prepared_xa() --- dbsim/db_client_service.hpp | 5 +++++ include/wsrep/client_service.hpp | 10 ++++++++++ src/client_state.cpp | 3 +-- test/mock_client_state.hpp | 5 +++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/dbsim/db_client_service.hpp b/dbsim/db_client_service.hpp index be6f9ad..15f32ef 100644 --- a/dbsim/db_client_service.hpp +++ b/dbsim/db_client_service.hpp @@ -82,6 +82,11 @@ namespace db return false; } + bool is_prepared_xa() override + { + return false; + } + bool is_xa_rollback() override { return false; diff --git a/include/wsrep/client_service.hpp b/include/wsrep/client_service.hpp index d47396d..e5aa649 100644 --- a/include/wsrep/client_service.hpp +++ b/include/wsrep/client_service.hpp @@ -194,6 +194,16 @@ namespace wsrep */ virtual bool is_explicit_xa() = 0; + /** + * Returns true if the client has an ongoing XA transaction + * in prepared state. + * Notice: one could simply check if wsrep::transaction is + * in s_prepared state. However, wsrep::transaction does not + * transition to prepared state for read-only / empty + * transactions. + */ + virtual bool is_prepared_xa() = 0; + /** * Returns true if the currently executing command is * a rollback for XA. This is used to avoid setting a diff --git a/src/client_state.cpp b/src/client_state.cpp index 99c4222..48501fd 100644 --- a/src/client_state.cpp +++ b/src/client_state.cpp @@ -68,8 +68,7 @@ void wsrep::client_state::close() keep_command_error_ = false; lock.unlock(); if (transaction_.active() && - (mode_ != m_local || - transaction_.state() != wsrep::transaction::s_prepared)) + (mode_ != m_local || !client_service_.is_prepared_xa())) { client_service_.bf_rollback(); transaction_.after_statement(); diff --git a/test/mock_client_state.hpp b/test/mock_client_state.hpp index 73b2775..89d38e3 100644 --- a/test/mock_client_state.hpp +++ b/test/mock_client_state.hpp @@ -176,6 +176,11 @@ namespace wsrep return false; } + bool is_prepared_xa() WSREP_OVERRIDE + { + return false; + } + bool is_xa_rollback() WSREP_OVERRIDE { return false;