Skip to content

Commit

Permalink
client/tso: init the ticker when TSO Follower Proxy is already enabled (
Browse files Browse the repository at this point in the history
#8948)

close #8947

Init the ticker directly when TSO Follower Proxy is already enabled.

Signed-off-by: JmPotato <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
JmPotato and ti-chi-bot[bot] authored Dec 25, 2024
1 parent 054a3d4 commit 95bfbe6
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions client/clients/tso/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down

0 comments on commit 95bfbe6

Please sign in to comment.