region_cache: filter out unresolved stores when GetTiFlashStores (#1262)

* region_cache: filter out unresolved stores when GetTiFlashStores

Signed-off-by: zyguan <zhongyangguan@gmail.com>

* address comment

Signed-off-by: zyguan <zhongyangguan@gmail.com>

---------

Signed-off-by: zyguan <zhongyangguan@gmail.com>
This commit is contained in:
zyguan 2024-04-04 12:33:34 +08:00 committed by GitHub
parent 5a4905d2f5
commit abc9bb2878
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 3 deletions

View File

@ -2191,10 +2191,11 @@ func (c *RegionCache) PDClient() pd.Client {
return c.pdClient return c.pdClient
} }
// GetTiFlashStores returns the information of all tiflash nodes. // GetTiFlashStores returns the information of all tiflash nodes. Like `GetAllStores`, the method only returns resolved
// stores so that users won't be bothered by tombstones. (related issue: https://github.com/pingcap/tidb/issues/46602)
func (c *RegionCache) GetTiFlashStores(labelFilter LabelFilter) []*Store { func (c *RegionCache) GetTiFlashStores(labelFilter LabelFilter) []*Store {
return c.filterStores(nil, func(s *Store) bool { return c.filterStores(nil, func(s *Store) bool {
return s.storeType == tikvrpc.TiFlash && labelFilter(s.labels) return s.storeType == tikvrpc.TiFlash && labelFilter(s.labels) && s.getResolveState() == resolved
}) })
} }

View File

@ -411,7 +411,7 @@ func (s *Store) reResolve(c storeCache) (bool, error) {
if store == nil || store.GetState() == metapb.StoreState_Tombstone { if store == nil || store.GetState() == metapb.StoreState_Tombstone {
// store has be removed in PD, we should invalidate all regions using those store. // store has be removed in PD, we should invalidate all regions using those store.
logutil.BgLogger().Info("invalidate regions in removed store", logutil.BgLogger().Info("invalidate regions in removed store",
zap.Uint64("store", s.storeID), zap.String("add", s.addr)) zap.Uint64("store", s.storeID), zap.String("addr", s.addr))
atomic.AddUint32(&s.epoch, 1) atomic.AddUint32(&s.epoch, 1)
s.setResolveState(tombstone) s.setResolveState(tombstone)
metrics.RegionCacheCounterWithInvalidateStoreRegionsOK.Inc() metrics.RegionCacheCounterWithInvalidateStoreRegionsOK.Inc()