From abc9bb28786664cc3bd41507c003ca9c6e71509a Mon Sep 17 00:00:00 2001 From: zyguan Date: Thu, 4 Apr 2024 12:33:34 +0800 Subject: [PATCH] region_cache: filter out unresolved stores when GetTiFlashStores (#1262) * region_cache: filter out unresolved stores when GetTiFlashStores Signed-off-by: zyguan * address comment Signed-off-by: zyguan --------- Signed-off-by: zyguan --- internal/locate/region_cache.go | 5 +++-- internal/locate/store_cache.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/locate/region_cache.go b/internal/locate/region_cache.go index ce6582beae..e8000f78c9 100644 --- a/internal/locate/region_cache.go +++ b/internal/locate/region_cache.go @@ -2191,10 +2191,11 @@ func (c *RegionCache) PDClient() pd.Client { 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 { 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 }) } diff --git a/internal/locate/store_cache.go b/internal/locate/store_cache.go index 235cbd0a1d..5defacbe40 100644 --- a/internal/locate/store_cache.go +++ b/internal/locate/store_cache.go @@ -411,7 +411,7 @@ func (s *Store) reResolve(c storeCache) (bool, error) { if store == nil || store.GetState() == metapb.StoreState_Tombstone { // store has be removed in PD, we should invalidate all regions using those 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) s.setResolveState(tombstone) metrics.RegionCacheCounterWithInvalidateStoreRegionsOK.Inc()