File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323
2424#include < chrono>
2525#include < cstdint>
26+ #include < functional>
27+ #include < memory>
28+ #include < vector>
2629
2730namespace pulsar {
2831
@@ -61,7 +64,9 @@ class PULSAR_PUBLIC AutoClusterFailover final : public ServiceInfoProvider {
6164 * - failoverThreshold: the number of consecutive failed probes required before switching away from
6265 * the current cluster.
6366 * - switchBackThreshold: the number of consecutive successful probes to the primary required before
64- * switching back from a secondary.
67+ * switching back from a secondary while that secondary remains available. If the active secondary
68+ * becomes unavailable and the primary is available, the implementation may switch back to the
69+ * primary immediately, regardless of this threshold.
6570 */
6671 class Builder {
6772 public:
@@ -80,7 +85,9 @@ class PULSAR_PUBLIC AutoClusterFailover final : public ServiceInfoProvider {
8085 return *this ;
8186 }
8287
83- // Set the number of consecutive successful primary probes required before switching back. Default: 1.
88+ // Set the number of consecutive successful primary probes required before switching back from a
89+ // healthy secondary. If the active secondary becomes unavailable and the primary is available,
90+ // the implementation may switch back immediately regardless of this threshold. Default: 1.
8491 Builder& withSwitchBackThreshold (uint32_t threshold) {
8592 config_.switchBackThreshold = threshold;
8693 return *this ;
Original file line number Diff line number Diff line change @@ -60,20 +60,18 @@ class AutoClusterFailoverImpl : public std::enable_shared_from_this<AutoClusterF
6060
6161 ~AutoClusterFailoverImpl () {
6262 using namespace std ::chrono_literals;
63- if (!thread_.joinable () || !future_. valid () ) {
63+ if (!thread_.joinable ()) {
6464 return ;
6565 }
6666
6767 cancelTimer (*timer_);
6868 workGuard_.reset ();
6969 ioContext_.stop ();
7070
71- if (future_.wait_for (1s) != std::future_status::ready) {
72- LOG_WARN (" AutoClusterFailoverImpl is not stopped within 3 seconds, skip it" );
73- thread_.detach ();
74- } else {
75- thread_.join ();
71+ if (future_.wait_for (3s) != std::future_status::ready) {
72+ LOG_WARN (" AutoClusterFailoverImpl is not stopped within 3 seconds, waiting for it to finish" );
7673 }
74+ thread_.join ();
7775 }
7876
7977 auto primary () const noexcept { return config_.primary ; }
@@ -367,7 +365,7 @@ class AutoClusterFailoverImpl : public std::enable_shared_from_this<AutoClusterF
367365 return ;
368366 }
369367
370- LOG_DEBUG (" Detected primary after secondary is available "
368+ LOG_DEBUG (" Detected primary while secondary is unavailable "
371369 << self->config_ .primary .serviceUrl () << " availability: " << primaryAvailable);
372370 if (primaryAvailable) {
373371 self->switchTo (&self->config_ .primary );
You can’t perform that action at this time.
0 commit comments