Skip to content

Commit

Permalink
fix DATA RACE
Browse files Browse the repository at this point in the history
  • Loading branch information
qw4990 committed Feb 17, 2020
1 parent bad915b commit 8b199eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,8 @@ func (t *OpenTracing) ToTracingConfig() *tracing.Configuration {

func init() {
conf := defaultConf
globalConfHandler = &constantConfHandler{&conf}
globalConfHandler = new(constantConfHandler)
globalConfHandler.SetConfig(&conf)
if checkBeforeDropLDFlag == "1" {
CheckTableBeforeDrop = true
}
Expand Down
10 changes: 6 additions & 4 deletions config/config_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,25 @@ func NewConfHandler(localConf *Config, reloadFunc ConfReloadFunc,
if strings.ToLower(localConf.Store) == "tikv" && localConf.EnableDynamicConfig {
return newPDConfHandler(localConf, reloadFunc, newPDCliFunc)
}
return &constantConfHandler{localConf}, nil
cch := new(constantConfHandler)
cch.curConf.Store(localConf)
return cch, nil
}

// constantConfHandler is used when EnableDynamicConfig is false.
// The conf in it will always be the configuration that initialized when TiDB is started.
type constantConfHandler struct {
conf *Config
curConf atomic.Value
}

func (cch *constantConfHandler) Start() {}

func (cch *constantConfHandler) Close() {}

func (cch *constantConfHandler) GetConfig() *Config { return cch.conf }
func (cch *constantConfHandler) GetConfig() *Config { return cch.curConf.Load().(*Config) }

func (cch *constantConfHandler) SetConfig(conf *Config) error {
cch.conf = conf
cch.curConf.Store(conf)
return nil
}

Expand Down

0 comments on commit 8b199eb

Please sign in to comment.