@@ -403,8 +403,7 @@ type RegionCache struct {
403
403
404
404
regionsNeedReload struct {
405
405
sync.Mutex
406
- regions []uint64
407
- toReload map [uint64 ]struct {}
406
+ regions []uint64
408
407
}
409
408
}
410
409
@@ -428,7 +427,6 @@ func NewRegionCache(pdClient pd.Client) *RegionCache {
428
427
c .tiflashComputeStoreMu .needReload = true
429
428
c .tiflashComputeStoreMu .stores = make ([]* Store , 0 )
430
429
c .notifyCheckCh = make (chan struct {}, 1 )
431
- c .regionsNeedReload .toReload = make (map [uint64 ]struct {})
432
430
c .ctx , c .cancelFunc = context .WithCancel (context .Background ())
433
431
interval := config .GetGlobalConfig ().StoresRefreshInterval
434
432
go c .asyncCheckAndResolveLoop (time .Duration (interval ) * time .Second )
@@ -463,6 +461,7 @@ func (c *RegionCache) asyncCheckAndResolveLoop(interval time.Duration) {
463
461
reloadRegionTicker .Stop ()
464
462
}()
465
463
var needCheckStores []* Store
464
+ reloadNextLoop := make (map [uint64 ]struct {})
466
465
for {
467
466
needCheckStores = needCheckStores [:0 ]
468
467
select {
@@ -482,17 +481,17 @@ func (c *RegionCache) asyncCheckAndResolveLoop(interval time.Duration) {
482
481
})
483
482
484
483
case <- reloadRegionTicker .C :
485
- for regionID := range c . regionsNeedReload . toReload {
484
+ for regionID := range reloadNextLoop {
486
485
c .reloadRegion (regionID )
487
- delete (c . regionsNeedReload . toReload , regionID )
486
+ delete (reloadNextLoop , regionID )
488
487
}
489
488
c .regionsNeedReload .Lock ()
490
489
for _ , regionID := range c .regionsNeedReload .regions {
491
490
// will reload in next tick, wait a while for two reasons:
492
491
// 1. there may an unavailable duration while recreating the connection.
493
492
// 2. the store may just be started, and wait safe ts synced to avoid the
494
493
// possible dataIsNotReady error.
495
- c . regionsNeedReload . toReload [regionID ] = struct {}{}
494
+ reloadNextLoop [regionID ] = struct {}{}
496
495
}
497
496
c .regionsNeedReload .regions = c .regionsNeedReload .regions [:0 ]
498
497
c .regionsNeedReload .Unlock ()
0 commit comments