diff --git a/server/schedulers/hot_region_config.go b/server/schedulers/hot_region_config.go index 76a33f1576b..22d7dc1f6f5 100644 --- a/server/schedulers/hot_region_config.go +++ b/server/schedulers/hot_region_config.go @@ -174,8 +174,8 @@ func (conf *hotRegionSchedulerConfig) GetEnableForTiFlash() bool { } func (conf *hotRegionSchedulerConfig) SetEnableForTiFlash(enable bool) { - conf.RLock() - defer conf.RUnlock() + conf.Lock() + defer conf.Unlock() conf.EnableForTiFlash = enable } @@ -211,7 +211,7 @@ func (conf *hotRegionSchedulerConfig) handleSetConfig(w http.ResponseWriter, r * } newc, _ := json.Marshal(conf) if !bytes.Equal(oldc, newc) { - conf.persist() + conf.persistLocked() rd.Text(w, http.StatusOK, "success") } @@ -235,11 +235,10 @@ func (conf *hotRegionSchedulerConfig) handleSetConfig(w http.ResponseWriter, r * rd.Text(w, http.StatusBadRequest, "config item not found") } -func (conf *hotRegionSchedulerConfig) persist() error { +func (conf *hotRegionSchedulerConfig) persistLocked() error { data, err := schedule.EncodeConfig(conf) if err != nil { return err - } return conf.storage.SaveScheduleConfig(HotRegionName, data) }