Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change EnableTSOFollowerProxy may not take effect #8947

Closed
rleungx opened this issue Dec 25, 2024 · 0 comments · Fixed by #8948
Closed

Change EnableTSOFollowerProxy may not take effect #8947

rleungx opened this issue Dec 25, 2024 · 0 comments · Fixed by #8948
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. severity/moderate type/bug The issue is confirmed as a bug.

Comments

@rleungx
Copy link
Member

rleungx commented Dec 25, 2024

Bug Report

pd/client/tso_dispatcher.go

Lines 333 to 402 in c1ee9cf

func (c *tsoClient) handleDispatcher(
dispatcherCtx context.Context,
dc string,
tbc *tsoBatchController,
) {
var (
err error
streamURL string
stream tsoStream
streamCtx context.Context
cancel context.CancelFunc
// url -> connectionContext
connectionCtxs sync.Map
)
defer func() {
log.Info("[tso] exit tso dispatcher", zap.String("dc-location", dc))
// Cancel all connections.
connectionCtxs.Range(func(_, cc any) bool {
cc.(*tsoConnectionContext).cancel()
return true
})
// Clear the tso batch controller.
tbc.clear()
c.wg.Done()
}()
// Call updateTSOConnectionCtxs once to init the connectionCtxs first.
c.updateTSOConnectionCtxs(dispatcherCtx, dc, &connectionCtxs)
// Only the Global TSO needs to watch the updateTSOConnectionCtxsCh to sense the
// change of the cluster when TSO Follower Proxy is enabled.
// TODO: support TSO Follower Proxy for the Local TSO.
if dc == globalDCLocation {
go func() {
var updateTicker = &time.Ticker{}
setNewUpdateTicker := func(ticker *time.Ticker) {
if updateTicker.C != nil {
updateTicker.Stop()
}
updateTicker = ticker
}
// Set to nil before returning to ensure that the existing ticker can be GC.
defer setNewUpdateTicker(nil)
for {
select {
case <-dispatcherCtx.Done():
return
case <-c.option.enableTSOFollowerProxyCh:
enableTSOFollowerProxy := c.option.getEnableTSOFollowerProxy()
log.Info("[tso] tso follower proxy status changed",
zap.String("dc-location", dc),
zap.Bool("enable", enableTSOFollowerProxy))
if enableTSOFollowerProxy && updateTicker.C == nil {
// Because the TSO Follower Proxy is enabled,
// the periodic check needs to be performed.
setNewUpdateTicker(time.NewTicker(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 {
// The status of TSO Follower Proxy does not change, and updateTSOConnectionCtxs is not triggered
continue
}
case <-updateTicker.C:
case <-c.updateTSOConnectionCtxsCh:
}
c.updateTSOConnectionCtxs(dispatcherCtx, dc, &connectionCtxs)
}
}()
}

If the option is true at line 359, it might connect to the follower. After that, the option is changed to false at line 380. This change may not take effect since the enableTSOFollowerProxy is false and updateTicker.C is nil.

It's better to initialize the ticker before stepping into the loop.

@rleungx rleungx added the type/bug The issue is confirmed as a bug. label Dec 25, 2024
@JmPotato JmPotato added severity/moderate affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. labels Dec 25, 2024
@ti-chi-bot ti-chi-bot bot closed this as completed in 95bfbe6 Dec 25, 2024
ti-chi-bot pushed a commit to ti-chi-bot/pd that referenced this issue Jan 26, 2025
ti-chi-bot bot added a commit that referenced this issue Jan 27, 2025
#8948) (#9025)

close #8947

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

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

Co-authored-by: okJiang <[email protected]>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
ti-chi-bot pushed a commit to ti-chi-bot/pd that referenced this issue Feb 11, 2025
ti-chi-bot bot added a commit that referenced this issue Feb 11, 2025
#8948) (#9058)

close #8947

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

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

Co-authored-by: JmPotato <[email protected]>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. severity/moderate type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants