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) (#9025)

close #8947

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

Signed-off-by: okJiang <819421878@qq.com>

Co-authored-by: okJiang <819421878@qq.com>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 27, 2025
1 parent fd9f899 commit 4c786e6
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,14 +731,22 @@ func (c *client) handleDispatcher(
if dc == globalDCLocation {
go func() {
var updateTicker = &time.Ticker{}
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 c.option.getEnableTSOFollowerProxy() {
setNewUpdateTicker(memberUpdateInterval)
}
// Set to nil before returning to ensure that the existing ticker can be GC.
defer setNewUpdateTicker(nil)
defer setNewUpdateTicker(0)

for {
select {
Expand All @@ -749,11 +757,11 @@ func (c *client) handleDispatcher(
if enableTSOFollowerProxy && updateTicker.C == nil {
// Because the TSO Follower Proxy is enabled,
// the periodic check needs to be performed.
setNewUpdateTicker(time.NewTicker(memberUpdateInterval))
setNewUpdateTicker(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 {
// The status of TSO Follower Proxy does not change, and updateConnectionCtxs is not triggered
continue
Expand Down

0 comments on commit 4c786e6

Please sign in to comment.