From 8f0e112c47fd01aaba94d2c8bc93985013d43a43 Mon Sep 17 00:00:00 2001 From: Teemu Ollakka Date: Thu, 21 Jun 2018 16:50:44 +0300 Subject: [PATCH] Renamed invalid to undefined. More utility functions. --- include/wsrep/client_id.hpp | 2 +- include/wsrep/client_state.hpp | 30 ++++++++++++++++++++++++++++- include/wsrep/gtid.hpp | 6 ++++++ include/wsrep/provider.hpp | 1 + include/wsrep/seqno.hpp | 4 ++++ include/wsrep/streaming_context.hpp | 6 +++--- include/wsrep/transaction.hpp | 2 +- include/wsrep/transaction_id.hpp | 2 +- src/transaction.cpp | 4 ++-- 9 files changed, 48 insertions(+), 9 deletions(-) diff --git a/include/wsrep/client_id.hpp b/include/wsrep/client_id.hpp index 4cd12e2..5d71d15 100644 --- a/include/wsrep/client_id.hpp +++ b/include/wsrep/client_id.hpp @@ -19,7 +19,7 @@ namespace wsrep : id_(static_cast(id)) { } type get() const { return id_; } - static type invalid() { return -1; } + static type undefined() { return -1; } private: type id_; }; diff --git a/include/wsrep/client_state.hpp b/include/wsrep/client_state.hpp index a998daf..182408c 100644 --- a/include/wsrep/client_state.hpp +++ b/include/wsrep/client_state.hpp @@ -488,6 +488,10 @@ namespace wsrep return transaction_; } + const wsrep::ws_meta& toi_meta() const + { + return toi_meta_; + } /** * Set debug logging level. * @@ -589,7 +593,8 @@ namespace wsrep wsrep::client_error current_error_; }; - static inline const char* to_string(enum wsrep::client_state::state state) + static inline const char* to_c_string( + enum wsrep::client_state::state state) { switch (state) { @@ -601,6 +606,29 @@ namespace wsrep } return "unknown"; } + + static inline std::string to_string(enum wsrep::client_state::state state) + { + return to_c_string(state); + } + + static inline const char* to_c_string(enum wsrep::client_state::mode mode) + { + switch (mode) + { + case wsrep::client_state::m_local: return "local"; + case wsrep::client_state::m_replicating: return "replicating"; + case wsrep::client_state::m_high_priority: return "high priority"; + case wsrep::client_state::m_toi: return "toi"; + } + return "unknown"; + } + + static inline std::string to_string(enum wsrep::client_state::mode mode) + { + return to_c_string(mode); + } + class client_state_switch { public: diff --git a/include/wsrep/gtid.hpp b/include/wsrep/gtid.hpp index 89d08c2..30a94fb 100644 --- a/include/wsrep/gtid.hpp +++ b/include/wsrep/gtid.hpp @@ -29,6 +29,12 @@ namespace wsrep { return (seqno_.is_undefined() && id_.is_undefined()); } + static wsrep::gtid undefined() + { + static const wsrep::gtid ret(wsrep::id::undefined(), + wsrep::seqno::undefined()); + return ret; + } private: wsrep::id id_; wsrep::seqno seqno_; diff --git a/include/wsrep/provider.hpp b/include/wsrep/provider.hpp index 790c21e..97b8e17 100644 --- a/include/wsrep/provider.hpp +++ b/include/wsrep/provider.hpp @@ -92,6 +92,7 @@ namespace wsrep , flags_(flags) { } + const wsrep::gtid& gtid() const { return gtid_; } const wsrep::id& group_id() const { return gtid_.id(); diff --git a/include/wsrep/seqno.hpp b/include/wsrep/seqno.hpp index 7e30cda..0fbfdc6 100644 --- a/include/wsrep/seqno.hpp +++ b/include/wsrep/seqno.hpp @@ -58,6 +58,10 @@ namespace wsrep { return (seqno_ == other.seqno_); } + bool operator!=(seqno other) const + { + return !(seqno_ == other.seqno_); + } seqno operator+(seqno other) const { return (seqno(seqno_ + other.seqno_)); diff --git a/include/wsrep/streaming_context.hpp b/include/wsrep/streaming_context.hpp index bbf0c9c..2bb4a87 100644 --- a/include/wsrep/streaming_context.hpp +++ b/include/wsrep/streaming_context.hpp @@ -59,14 +59,14 @@ namespace wsrep void rolled_back(wsrep::transaction_id id) { - assert(rollback_replicated_for_ == wsrep::transaction_id::invalid()); + assert(rollback_replicated_for_ == wsrep::transaction_id::undefined()); rollback_replicated_for_ = id; } bool rolled_back() const { return (rollback_replicated_for_ != - wsrep::transaction_id::invalid()); + wsrep::transaction_id::undefined()); } size_t unit_counter() const { return unit_counter_; } @@ -80,7 +80,7 @@ namespace wsrep void cleanup() { fragments_.clear(); - rollback_replicated_for_ = wsrep::transaction_id::invalid(); + rollback_replicated_for_ = wsrep::transaction_id::undefined(); bytes_certified_ = 0; unit_counter_ = 0; } diff --git a/include/wsrep/transaction.hpp b/include/wsrep/transaction.hpp index e3dc040..c8499c8 100644 --- a/include/wsrep/transaction.hpp +++ b/include/wsrep/transaction.hpp @@ -52,7 +52,7 @@ namespace wsrep { return id_; } bool active() const - { return (id_ != wsrep::transaction_id::invalid()); } + { return (id_ != wsrep::transaction_id::undefined()); } void state(wsrep::unique_lock&, enum state); diff --git a/include/wsrep/transaction_id.hpp b/include/wsrep/transaction_id.hpp index 9bbf19d..066f200 100644 --- a/include/wsrep/transaction_id.hpp +++ b/include/wsrep/transaction_id.hpp @@ -24,7 +24,7 @@ namespace wsrep : id_(static_cast(id)) { } type get() const { return id_; } - static unsigned long long invalid() { return type(-1); } + static unsigned long long undefined() { return type(-1); } bool operator<(const transaction_id& other) const { return (id_ < other.id_); diff --git a/src/transaction.cpp b/src/transaction.cpp index 3923dab..828662d 100644 --- a/src/transaction.cpp +++ b/src/transaction.cpp @@ -26,7 +26,7 @@ wsrep::transaction::transaction( : server_service_(client_state.server_state().server_service()) , client_service_(client_state.client_service()) , client_state_(client_state) - , id_(transaction_id::invalid()) + , id_(transaction_id::undefined()) , state_(s_executing) , state_hist_() , bf_abort_state_(s_executing) @@ -952,7 +952,7 @@ void wsrep::transaction::cleanup() assert(is_streaming() == false); assert(state() == s_committed || state() == s_aborted); debug_log_state("cleanup_enter"); - id_ = wsrep::transaction_id::invalid(); + id_ = wsrep::transaction_id::undefined(); ws_handle_ = wsrep::ws_handle(); // Keep the state history for troubleshooting. Reset at start_transaction(). // state_hist_.clear();