From a2d7d89c1d844dcd0f4cfbfdc3d48e11877d1a95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Fri, 4 Apr 2025 12:35:55 +0300 Subject: [PATCH] MDEV-36551: Add interface to report wsrep state change in Galera --- dbsim/db_client_service.hpp | 4 +++- include/wsrep/client_service.hpp | 8 +++++++- src/client_state.cpp | 4 +++- src/transaction.cpp | 6 +++++- test/mock_client_state.hpp | 6 +++++- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/dbsim/db_client_service.hpp b/dbsim/db_client_service.hpp index 15f32ef..c0071dc 100644 --- a/dbsim/db_client_service.hpp +++ b/dbsim/db_client_service.hpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Codership Oy + * Copyright (C) 2018-2025 Codership Oy * * This file is part of wsrep-lib. * @@ -94,6 +94,8 @@ namespace db void debug_sync(const char*) override { } void debug_crash(const char*) override { } + void notify_state_change() override { } + private: db::client& client_; wsrep::client_state& client_state_; diff --git a/include/wsrep/client_service.hpp b/include/wsrep/client_service.hpp index e5aa649..6fe5cbf 100644 --- a/include/wsrep/client_service.hpp +++ b/include/wsrep/client_service.hpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Codership Oy + * Copyright (C) 2018-2025 Codership Oy * * This file is part of wsrep-lib. * @@ -227,7 +227,13 @@ namespace wsrep * been enabled. */ virtual void debug_crash(const char* crash_point) = 0; + + // + // Notify state change interface + // + virtual void notify_state_change() = 0; }; + } #endif // WSREP_CLIENT_SERVICE_HPP diff --git a/src/client_state.cpp b/src/client_state.cpp index 90dbb23..a5995cd 100644 --- a/src/client_state.cpp +++ b/src/client_state.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Codership Oy + * Copyright (C) 2018-2025 Codership Oy * * This file is part of wsrep-lib. * @@ -1047,6 +1047,7 @@ void wsrep::client_state::state( } state_hist_.push_back(state_); state_ = state; + client_service_.notify_state_change(); if (state_hist_.size() > 10) { state_hist_.erase(state_hist_.begin()); @@ -1076,6 +1077,7 @@ void wsrep::client_state::mode( assert(0); } mode_ = mode; + client_service_.notify_state_change(); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/transaction.cpp b/src/transaction.cpp index c2a8a52..6647cfc 100644 --- a/src/transaction.cpp +++ b/src/transaction.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Codership Oy + * Copyright (C) 2018-2025 Codership Oy * * This file is part of wsrep-lib. * @@ -138,6 +138,7 @@ int wsrep::transaction::start_transaction( state_hist_.clear(); ws_handle_ = wsrep::ws_handle(id); flags(wsrep::provider::flag::start_transaction); + client_service_.notify_state_change(); switch (client_state_.mode()) { case wsrep::client_state::m_high_priority: @@ -167,6 +168,7 @@ int wsrep::transaction::start_transaction( id_ = ws_meta.transaction_id(); assert(client_state_.mode() == wsrep::client_state::m_high_priority); state_ = s_executing; + client_service_.notify_state_change(); state_hist_.clear(); ws_handle_ = ws_handle; ws_meta_ = ws_meta; @@ -1140,6 +1142,7 @@ void wsrep::transaction::clone_for_replay(const wsrep::transaction& other) ws_meta_ = other.ws_meta_; streaming_context_ = other.streaming_context_; state_ = s_replaying; + client_service_.notify_state_change(); } void wsrep::transaction::assign_xid(const wsrep::xid& xid) @@ -1383,6 +1386,7 @@ void wsrep::transaction::state( state_hist_.erase(state_hist_.begin()); } state_ = next_state; + client_service_.notify_state_change(); if (state_ == s_must_replay) { diff --git a/test/mock_client_state.hpp b/test/mock_client_state.hpp index aa77dd9..deb78c4 100644 --- a/test/mock_client_state.hpp +++ b/test/mock_client_state.hpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Codership Oy + * Copyright (C) 2018-2025 Codership Oy * * This file is part of wsrep-lib. * @@ -211,6 +211,10 @@ namespace wsrep // Not going to do this while unit testing } + void notify_state_change() WSREP_OVERRIDE + { + // Not going to do this while unit testing + } // // Knobs to tune the behavior