Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

region_cache: refine GetTiFlashComputeRPCContextByConsistentHash #644

Merged
merged 3 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions internal/locate/region_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand All @@ -777,11 +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 {
logutil.Logger(context.Background()).Info("rpcCtx is nil", zap.Any("region", id.String()))
return nil, nil
}

Expand Down
6 changes: 5 additions & 1 deletion internal/locate/region_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
guo-shaoge marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}
Expand Down