From 94106ea8162b6d624f6c761207f36a45b2226504 Mon Sep 17 00:00:00 2001 From: zyguan Date: Wed, 3 Apr 2024 18:01:49 +0800 Subject: [PATCH 1/2] region_cache: filter out unresolved stores when GetTiFlashStores Signed-off-by: zyguan --- internal/locate/region_cache.go | 2 +- internal/locate/store_cache.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/locate/region_cache.go b/internal/locate/region_cache.go index ce6582beae..2bd19b2231 100644 --- a/internal/locate/region_cache.go +++ b/internal/locate/region_cache.go @@ -2194,7 +2194,7 @@ func (c *RegionCache) PDClient() pd.Client { // GetTiFlashStores returns the information of all tiflash nodes. 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() From 1f29642753d5b21e2b69f787829be6e6e161a431 Mon Sep 17 00:00:00 2001 From: zyguan Date: Thu, 4 Apr 2024 01:45:50 +0800 Subject: [PATCH 2/2] address comment Signed-off-by: zyguan --- internal/locate/region_cache.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/locate/region_cache.go b/internal/locate/region_cache.go index 2bd19b2231..e8000f78c9 100644 --- a/internal/locate/region_cache.go +++ b/internal/locate/region_cache.go @@ -2191,7 +2191,8 @@ 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) && s.getResolveState() == resolved