From ffc278866346a186cac107933467da404233b3c1 Mon Sep 17 00:00:00 2001 From: guo-shaoge Date: Sat, 17 Dec 2022 16:41:11 +0800 Subject: [PATCH 1/3] region_cache: refine GetTiFlashComputeRPCContextByConsistentHash(for detect alive) Signed-off-by: guo-shaoge --- internal/locate/region_cache.go | 17 ++++++----------- internal/locate/region_request.go | 6 +++++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/internal/locate/region_cache.go b/internal/locate/region_cache.go index 154def11..4fde8c5f 100644 --- a/internal/locate/region_cache.go +++ b/internal/locate/region_cache.go @@ -758,17 +758,12 @@ func (c *RegionCache) GetTiFlashRPCContext(bo *retry.Backoffer, id RegionVerID, // 3. Compute which tiflash_compute node should handle this region by consistent hash. // 4. Replace infos(addr/Store) that indicate where the region is stored to infos that indicate where the region will be computed. // NOTE: This function make sure the returned slice of RPCContext and the input ids correspond to each other. -func (c *RegionCache) GetTiFlashComputeRPCContextByConsistentHash(bo *retry.Backoffer, ids []RegionVerID) (res []*RPCContext, err error) { - stores, err := c.GetTiFlashComputeStores(bo) - if err != nil { - return nil, err - } - if len(stores) == 0 { - return nil, errors.New("number of tiflash_compute node is zero") - } - +func (c *RegionCache) GetTiFlashComputeRPCContextByConsistentHash(bo *retry.Backoffer, ids []RegionVerID, stores []*Store) (res []*RPCContext, err error) { hasher := consistent.New() for _, store := range stores { + if !isStoreContainLabel(store.labels, tikvrpc.EngineLabelKey, tikvrpc.EngineLabelTiFlashCompute) { + return nil, errors.New("expect store should be tiflash_compute") + } hasher.Add(store.GetAddr()) } @@ -777,12 +772,12 @@ func (c *RegionCache) GetTiFlashComputeRPCContextByConsistentHash(bo *retry.Back if err != nil { return nil, err } - rpcCtx, err := c.GetTiFlashRPCContext(bo, id, true) + rpcCtx, err := c.GetTiFlashRPCContext(bo, id, false) if err != nil { return nil, err } if rpcCtx == nil { - return nil, nil + return nil, errors.Errorf("rpcCtx is nil", zap.Any("region", id)) } var store *Store diff --git a/internal/locate/region_request.go b/internal/locate/region_request.go index b39eb5a4..6b6f9b8f 100644 --- a/internal/locate/region_request.go +++ b/internal/locate/region_request.go @@ -879,7 +879,11 @@ func (s *RegionRequestSender) getRPCContext( case tikvrpc.TiDB: return &RPCContext{Addr: s.storeAddr}, nil case tikvrpc.TiFlashCompute: - rpcCtxs, err := s.regionCache.GetTiFlashComputeRPCContextByConsistentHash(bo, []RegionVerID{regionID}) + stores, err := s.regionCache.GetTiFlashComputeStores(bo) + if err != nil { + return nil, err + } + rpcCtxs, err := s.regionCache.GetTiFlashComputeRPCContextByConsistentHash(bo, []RegionVerID{regionID}, stores) if err != nil { return nil, err } From 60119cdd7a3f4ad6ae32ccc1d1f68fb80f15d47c Mon Sep 17 00:00:00 2001 From: guo-shaoge Date: Sat, 17 Dec 2022 16:46:55 +0800 Subject: [PATCH 2/3] fix errors.Errorf Signed-off-by: guo-shaoge --- internal/locate/region_cache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/locate/region_cache.go b/internal/locate/region_cache.go index 4fde8c5f..fbf6b458 100644 --- a/internal/locate/region_cache.go +++ b/internal/locate/region_cache.go @@ -777,7 +777,7 @@ func (c *RegionCache) GetTiFlashComputeRPCContextByConsistentHash(bo *retry.Back return nil, err } if rpcCtx == nil { - return nil, errors.Errorf("rpcCtx is nil", zap.Any("region", id)) + return nil, errors.Errorf("rpcCtx is nil, region: %v", id) } var store *Store From 0bf06e87bfad0c6dd5cfd577e8faf8891b943057 Mon Sep 17 00:00:00 2001 From: guo-shaoge Date: Sun, 18 Dec 2022 13:57:23 +0800 Subject: [PATCH 3/3] update log Signed-off-by: guo-shaoge --- 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 fbf6b458..7a793a37 100644 --- a/internal/locate/region_cache.go +++ b/internal/locate/region_cache.go @@ -777,7 +777,8 @@ func (c *RegionCache) GetTiFlashComputeRPCContextByConsistentHash(bo *retry.Back return nil, err } if rpcCtx == nil { - return nil, errors.Errorf("rpcCtx is nil, region: %v", id) + logutil.Logger(context.Background()).Info("rpcCtx is nil", zap.Any("region", id.String())) + return nil, nil } var store *Store