From f27f54947937cc754003992f111c9ba8411bbc6e Mon Sep 17 00:00:00 2001 From: Leandro Pacheco Date: Fri, 13 Sep 2019 18:52:17 -0300 Subject: [PATCH] poll_enter_toi timeout handlign --- include/wsrep/client_state.hpp | 3 ++- src/client_state.cpp | 40 +++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/include/wsrep/client_state.hpp b/include/wsrep/client_state.hpp index 119b974..40a0e33 100644 --- a/include/wsrep/client_state.hpp +++ b/include/wsrep/client_state.hpp @@ -1025,7 +1025,8 @@ namespace wsrep const wsrep::const_buffer& buffer, wsrep::ws_meta& meta, int flags, - std::chrono::time_point wait_until); + std::chrono::time_point wait_until, + bool& timed_out); void enter_toi_common(wsrep::unique_lock&); void leave_toi_common(); diff --git a/src/client_state.cpp b/src/client_state.cpp index 9f75e80..2140533 100644 --- a/src/client_state.cpp +++ b/src/client_state.cpp @@ -339,7 +339,8 @@ wsrep::client_state::poll_enter_toi( const wsrep::const_buffer& buffer, wsrep::ws_meta& meta, int flags, - std::chrono::time_point wait_until) + std::chrono::time_point wait_until, + bool& timed_out) { WSREP_LOG_DEBUG(debug_log_level(), wsrep::log::debug_level_client_state, @@ -348,6 +349,7 @@ wsrep::client_state::poll_enter_toi( << "," << wait_until.time_since_epoch().count()); enum wsrep::provider::status status; + timed_out = false; do { lock.unlock(); @@ -372,13 +374,13 @@ wsrep::client_state::poll_enter_toi( ::usleep(100000); } lock.lock(); + timed_out = !(wait_until.time_since_epoch().count() && + wsrep::clock::now() < wait_until); } while ((status == wsrep::provider::error_certification_failed || status == wsrep::provider::error_connection_failed) && - wait_until.time_since_epoch().count() && - wsrep::clock::now() < wait_until && + not timed_out && not client_service_.interrupted(lock)); - /** @todo should report timeout error if wait times out */ return status; } @@ -401,12 +403,14 @@ int wsrep::client_state::enter_toi_local(const wsrep::key_array& keys, wsrep::unique_lock lock(mutex_); + bool timed_out; auto const status(poll_enter_toi( lock, keys, buffer, toi_meta_, wsrep::provider::flag::start_transaction | wsrep::provider::flag::commit, - wait_until)); + wait_until, + timed_out)); switch (status) { case wsrep::provider::success: @@ -420,7 +424,11 @@ int wsrep::client_state::enter_toi_local(const wsrep::key_array& keys, ret = 1; break; default: - override_error(e_error_during_commit, status); + if (timed_out) { + override_error(e_timeout_error); + } else { + override_error(e_error_during_commit, status); + } ret = 1; break; } @@ -541,11 +549,13 @@ int wsrep::client_state::begin_nbo_phase_one( assert(toi_mode_ == m_undefined); int ret; + bool timed_out; auto const status(poll_enter_toi( lock, keys, buffer, toi_meta_, wsrep::provider::flag::start_transaction, - wait_until)); + wait_until, + timed_out)); switch (status) { case wsrep::provider::success: @@ -558,7 +568,11 @@ int wsrep::client_state::begin_nbo_phase_one( ret = 1; break; default: - override_error(e_error_during_commit, status); + if (timed_out) { + override_error(e_timeout_error); + } else { + override_error(e_error_during_commit, status); + } ret = 1; break; } @@ -627,12 +641,14 @@ int wsrep::client_state::begin_nbo_phase_two( // an input param containing gtid of NBO begin. // Output stored in nbo_meta_ is copied to toi_meta_ for // phase two end. + bool timed_out; enum wsrep::provider::status status( poll_enter_toi(lock, keys, wsrep::const_buffer(), nbo_meta_, wsrep::provider::flag::commit, - wait_until)); + wait_until, + timed_out)); int ret; switch (status) { @@ -642,7 +658,11 @@ int wsrep::client_state::begin_nbo_phase_two( toi_mode_ = m_local; break; default: - override_error(e_error_during_commit, status); + if (timed_out) { + override_error(e_timeout_error); + } else { + override_error(e_error_during_commit, status); + } // Failed to grab TOI for completing NBO in order. This means that // the operation cannot be ended in total order, so we end the // NBO mode and let the DBMS to deal with the error.