Skip to content

Commit 98e21b3

Browse files
committed
address comment
Signed-off-by: you06 <you1474600@gmail.com>
1 parent 5587278 commit 98e21b3

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

internal/locate/region_cache.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,7 @@ type RegionCache struct {
403403

404404
regionsNeedReload struct {
405405
sync.Mutex
406-
regions []uint64
407-
toReload map[uint64]struct{}
406+
regions []uint64
408407
}
409408
}
410409

@@ -428,7 +427,6 @@ func NewRegionCache(pdClient pd.Client) *RegionCache {
428427
c.tiflashComputeStoreMu.needReload = true
429428
c.tiflashComputeStoreMu.stores = make([]*Store, 0)
430429
c.notifyCheckCh = make(chan struct{}, 1)
431-
c.regionsNeedReload.toReload = make(map[uint64]struct{})
432430
c.ctx, c.cancelFunc = context.WithCancel(context.Background())
433431
interval := config.GetGlobalConfig().StoresRefreshInterval
434432
go c.asyncCheckAndResolveLoop(time.Duration(interval) * time.Second)
@@ -463,6 +461,7 @@ func (c *RegionCache) asyncCheckAndResolveLoop(interval time.Duration) {
463461
reloadRegionTicker.Stop()
464462
}()
465463
var needCheckStores []*Store
464+
reloadNextLoop := make(map[uint64]struct{})
466465
for {
467466
needCheckStores = needCheckStores[:0]
468467
select {
@@ -482,17 +481,17 @@ func (c *RegionCache) asyncCheckAndResolveLoop(interval time.Duration) {
482481
})
483482

484483
case <-reloadRegionTicker.C:
485-
for regionID := range c.regionsNeedReload.toReload {
484+
for regionID := range reloadNextLoop {
486485
c.reloadRegion(regionID)
487-
delete(c.regionsNeedReload.toReload, regionID)
486+
delete(reloadNextLoop, regionID)
488487
}
489488
c.regionsNeedReload.Lock()
490489
for _, regionID := range c.regionsNeedReload.regions {
491490
// will reload in next tick, wait a while for two reasons:
492491
// 1. there may an unavailable duration while recreating the connection.
493492
// 2. the store may just be started, and wait safe ts synced to avoid the
494493
// possible dataIsNotReady error.
495-
c.regionsNeedReload.toReload[regionID] = struct{}{}
494+
reloadNextLoop[regionID] = struct{}{}
496495
}
497496
c.regionsNeedReload.regions = c.regionsNeedReload.regions[:0]
498497
c.regionsNeedReload.Unlock()

0 commit comments

Comments
 (0)