Skip to content

Commit

Permalink
fix race in hot region config
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Sep 27, 2021
1 parent 455a2f9 commit d4c793b
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 @@ -343,6 +343,8 @@ func (conf *hotRegionSchedulerConfig) persist() error {
}

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

0 comments on commit d4c793b

Please sign in to comment.