Skip to content

Commit

Permalink
*: fix race in hot region config (#4167)
Browse files Browse the repository at this point in the history
* fix race in hot region config

Signed-off-by: Ryan Leung <rleungx@gmail.com>

* address the comment

Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx authored Sep 27, 2021
1 parent 455a2f9 commit 7c76c98
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions server/schedulers/hot_region_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,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 @@ -310,7 +310,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 @@ -334,7 +334,7 @@ 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
Expand All @@ -344,6 +344,8 @@ func (conf *hotRegionSchedulerConfig) persist() error {

func (conf *hotRegionSchedulerConfig) checkQuerySupport(cluster opt.Cluster) bool {
querySupport := cluster.IsFeatureSupported(versioninfo.HotScheduleWithQuery)
conf.Lock()
defer conf.Unlock()
if querySupport != conf.lastQuerySupported {
log.Info("query supported changed",
zap.Bool("last-query-support", conf.lastQuerySupported),
Expand Down

0 comments on commit 7c76c98

Please sign in to comment.