Skip to content

Change EnableTSOFollowerProxy may not take effect #8947

@rleungx

Description

@rleungx

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-5.4This bug affects the 5.4.x(LTS) versions.affects-6.1This bug affects the 6.1.x(LTS) versions.affects-6.5This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.affects-8.5This bug affects the 8.5.x(LTS) versions.severity/moderatetype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions