Skip to content

Commit 0a621b4

Browse files
authored
scheduler: fix data race test in evict_stopping_store scheduler (#9828)
close #9812 change the stopping state to atomic variable Signed-off-by: hujiatao0 <hhjjtt110@gmail.com>
1 parent 746e71d commit 0a621b4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

pkg/core/store.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type StoreInfo struct {
6363
pauseLeaderTransferOut atomic.Int64 // not allow to be used as source of transfer leader
6464
slowStoreEvicted atomic.Int64 // this store has been evicted as a slow store, should not transfer leader to it
6565
slowTrendEvicted atomic.Int64 // this store has been evicted as a slow store by trend, should not transfer leader to it
66+
stoppingStoreEvicted atomic.Int64 // this store has been evicted as a stopping store, should not transfer leader to it
6667
leaderCount int
6768
regionCount int
6869
learnerCount int
@@ -137,6 +138,7 @@ func (s *StoreInfo) Clone(opts ...StoreCreateOption) *StoreInfo {
137138
store.pauseLeaderTransferOut.Store(s.pauseLeaderTransferOut.Load())
138139
store.slowStoreEvicted.Store(s.slowStoreEvicted.Load())
139140
store.slowTrendEvicted.Store(s.slowTrendEvicted.Load())
141+
store.stoppingStoreEvicted.Store(s.stoppingStoreEvicted.Load())
140142
for _, opt := range opts {
141143
if opt != nil {
142144
opt(store)
@@ -183,6 +185,7 @@ func (s *StoreInfo) ShallowClone(opts ...StoreCreateOption) *StoreInfo {
183185
store.pauseLeaderTransferOut.Store(s.pauseLeaderTransferOut.Load())
184186
store.slowStoreEvicted.Store(s.slowStoreEvicted.Load())
185187
store.slowTrendEvicted.Store(s.slowTrendEvicted.Load())
188+
store.stoppingStoreEvicted.Store(s.stoppingStoreEvicted.Load())
186189
for _, opt := range opts {
187190
opt(store)
188191
}
@@ -208,7 +211,7 @@ func (s *StoreInfo) EvictedAsSlowStore() bool {
208211

209212
// EvictedAsStoppingStore returns if the store should be evicted as a stopping store.
210213
func (s *StoreInfo) EvictedAsStoppingStore() bool {
211-
return s.rawStats.IsStopping
214+
return s.stoppingStoreEvicted.Load() > 0
212215
}
213216

214217
// IsEvictedAsSlowTrend returns if the store should be evicted as a slow store by trend.

pkg/core/store_option.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func SlowStoreEvicted() StoreCreateOption {
146146
// leader to the store
147147
func StoppingStoreEvicted() StoreCreateOption {
148148
return func(store *StoreInfo) {
149-
store.rawStats.IsStopping = true
149+
store.stoppingStoreEvicted.Add(1)
150150
}
151151
}
152152

@@ -175,7 +175,7 @@ func SlowStoreRecovered() StoreCreateOption {
175175
// StoppingStoreRecovered cleans the evicted state of a store.
176176
func StoppingStoreRecovered() StoreCreateOption {
177177
return func(store *StoreInfo) {
178-
store.rawStats.IsStopping = false
178+
store.stoppingStoreEvicted.Add(-1)
179179
}
180180
}
181181

0 commit comments

Comments
 (0)