Skip to content

Commit

Permalink
*: fix race in hot region config (#4167) (#4176)
Browse files Browse the repository at this point in the history
Signed-off-by: HunDunDM <[email protected]>
  • Loading branch information
HunDunDM committed Sep 28, 2021
1 parent 15cf76e commit 897734a
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions server/schedulers/hot_region_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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")
}

Expand All @@ -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)
}

0 comments on commit 897734a

Please sign in to comment.