From 1246ed947f74404357359557e4585ab9a6d0dfb5 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Wed, 25 Dec 2024 14:55:15 +0800 Subject: [PATCH] Init the ticker when TSO Follower Proxy is already enabled Signed-off-by: JmPotato --- client/clients/tso/dispatcher.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/client/clients/tso/dispatcher.go b/client/clients/tso/dispatcher.go index bdac8096f85..320976f8326 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,11 +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{}) + setNewUpdateTicker(0) } else { continue }