From 95bfbe69ae1b48bac2b76b0f229cc030ac89a0ae Mon Sep 17 00:00:00 2001 From: JmPotato Date: Wed, 25 Dec 2024 16:03:03 +0800 Subject: [PATCH] client/tso: init the ticker when TSO Follower Proxy is already enabled (#8948) close tikv/pd#8947 Init the ticker directly when TSO Follower Proxy is already enabled. Signed-off-by: JmPotato Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- client/clients/tso/dispatcher.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/client/clients/tso/dispatcher.go b/client/clients/tso/dispatcher.go index bdac8096f85..58722088886 100644 --- a/client/clients/tso/dispatcher.go +++ b/client/clients/tso/dispatcher.go @@ -477,14 +477,22 @@ func (td *tsoDispatcher) connectionCtxsUpdater() { ) log.Info("[tso] start tso connection contexts updater") - setNewUpdateTicker := func(ticker *time.Ticker) { + setNewUpdateTicker := func(interval time.Duration) { if updateTicker.C != nil { updateTicker.Stop() } - updateTicker = ticker + if interval == 0 { + updateTicker = &time.Ticker{} + } else { + updateTicker = time.NewTicker(interval) + } + } + // If the TSO Follower Proxy is enabled, set the update interval to the member update interval. + if option.GetEnableTSOFollowerProxy() { + setNewUpdateTicker(sd.MemberUpdateInterval) } // Set to nil before returning to ensure that the existing ticker can be GC. - defer setNewUpdateTicker(nil) + defer setNewUpdateTicker(0) for { provider.updateConnectionCtxs(ctx, connectionCtxs) @@ -499,13 +507,11 @@ func (td *tsoDispatcher) connectionCtxsUpdater() { if enableTSOFollowerProxy && updateTicker.C == nil { // Because the TSO Follower Proxy is enabled, // the periodic check needs to be performed. - setNewUpdateTicker(time.NewTicker(sd.MemberUpdateInterval)) + setNewUpdateTicker(sd.MemberUpdateInterval) } else if !enableTSOFollowerProxy && updateTicker.C != nil { // Because the TSO Follower Proxy is disabled, // the periodic check needs to be turned off. - setNewUpdateTicker(&time.Ticker{}) - } else { - continue + setNewUpdateTicker(0) } case <-updateTicker.C: // Triggered periodically when the TSO Follower Proxy is enabled.