Skip to content

Commit

Permalink
variable: fix data race in the variable.SetPDClientDynamicOption (#38374
Browse files Browse the repository at this point in the history
)

close #38373
  • Loading branch information
hawkingrei committed Oct 11, 2022
1 parent accff68 commit 8ea4551
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions br/pkg/restore/BUILD.bazel
Expand Up @@ -111,6 +111,8 @@ go_test(
],
embed = [":restore"],
flaky = True,
race = "on",
shard_count = 20,
deps = [
"//br/pkg/backup",
"//br/pkg/conn",
Expand Down
3 changes: 2 additions & 1 deletion domain/domain_sysvars.go
Expand Up @@ -31,7 +31,8 @@ import (
// which is overwritten here.
func (do *Domain) initDomainSysVars() {
variable.SetStatsCacheCapacity.Store(do.setStatsCacheCapacity)
variable.SetPDClientDynamicOption = do.setPDClientDynamicOption
pdClientDynamicOptionFunc := do.setPDClientDynamicOption
variable.SetPDClientDynamicOption.Store(&pdClientDynamicOptionFunc)
}

// setStatsCacheCapacity sets statsCache cap
Expand Down
4 changes: 2 additions & 2 deletions sessionctx/variable/sysvar.go
Expand Up @@ -496,13 +496,13 @@ var defaultSysVars = []*SysVar{
return strconv.FormatFloat(MaxTSOBatchWaitInterval.Load(), 'f', -1, 64), nil
},
SetGlobal: func(s *SessionVars, val string) error {
SetPDClientDynamicOption(TiDBTSOClientBatchMaxWaitTime, val)
(*SetPDClientDynamicOption.Load())(TiDBTSOClientBatchMaxWaitTime, val)
return nil
}},
{Scope: ScopeGlobal, Name: TiDBEnableTSOFollowerProxy, Value: BoolToOnOff(DefTiDBEnableTSOFollowerProxy), Type: TypeBool, GetGlobal: func(sv *SessionVars) (string, error) {
return BoolToOnOff(EnableTSOFollowerProxy.Load()), nil
}, SetGlobal: func(s *SessionVars, val string) error {
SetPDClientDynamicOption(TiDBEnableTSOFollowerProxy, val)
(*SetPDClientDynamicOption.Load())(TiDBEnableTSOFollowerProxy, val)
return nil
}},
{Scope: ScopeGlobal, Name: TiDBEnableLocalTxn, Value: BoolToOnOff(DefTiDBEnableLocalTxn), Hidden: true, Type: TypeBool, GetGlobal: func(sv *SessionVars) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion sessionctx/variable/tidb_vars.go
Expand Up @@ -1117,7 +1117,7 @@ var (
// SetStatsCacheCapacity is the func registered by domain to set statsCache memory quota.
SetStatsCacheCapacity atomic.Value
// SetPDClientDynamicOption is the func registered by domain
SetPDClientDynamicOption func(string, string) = nil
SetPDClientDynamicOption atomic.Pointer[func(string, string)]
// SwitchConcurrentDDL is the func registered by DDL to switch concurrent DDL.
SwitchConcurrentDDL func(bool) error = nil
// SwitchMDL is the func registered by DDL to switch MDL.
Expand Down

0 comments on commit 8ea4551

Please sign in to comment.