Skip to content

Commit

Permalink
avoid potential data race
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Sep 24, 2024
1 parent acb4244 commit 457da3d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/schedule/checker/rule_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/tikv/pd/pkg/schedule/operator"
"github.com/tikv/pd/pkg/schedule/placement"
"github.com/tikv/pd/pkg/schedule/types"
"github.com/tikv/pd/pkg/utils/syncutil"
"github.com/tikv/pd/pkg/versioninfo"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -650,6 +651,7 @@ func (c *RuleChecker) handleFilterState(region *core.RegionInfo, filterByTempSta
}

type recorder struct {
syncutil.RWMutex
offlineLeaderCounter map[uint64]uint64
lastUpdateTime time.Time
}
Expand All @@ -662,10 +664,14 @@ func newRecord() *recorder {
}

func (o *recorder) getOfflineLeaderCount(storeID uint64) uint64 {
o.RLock()
defer o.RUnlock()
return o.offlineLeaderCounter[storeID]
}

func (o *recorder) incOfflineLeaderCount(storeID uint64) {
o.Lock()
defer o.Unlock()
o.offlineLeaderCounter[storeID] += 1
o.lastUpdateTime = time.Now()
}
Expand Down

0 comments on commit 457da3d

Please sign in to comment.