From 44c756ff7d27764b3c281c4fba4b758c2da6da89 Mon Sep 17 00:00:00 2001 From: cfzjywxk Date: Tue, 7 Mar 2023 22:57:06 +0800 Subject: [PATCH 1/3] upgrade client-go dependency, fix compatible issues --- go.mod | 2 +- go.sum | 4 ++-- store/copr/batch_coprocessor.go | 13 +++++++------ store/copr/coprocessor.go | 3 ++- store/copr/mpp.go | 11 +---------- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index f430e2a886070..6fbf77520fdb7 100644 --- a/go.mod +++ b/go.mod @@ -92,7 +92,7 @@ require ( github.com/stretchr/testify v1.8.2 github.com/tdakkota/asciicheck v0.1.1 github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 - github.com/tikv/client-go/v2 v2.0.6-0.20230302054057-3f7860f10959 + github.com/tikv/client-go/v2 v2.0.7-0.20230307075841-4037273b3ca7 github.com/tikv/pd/client v0.0.0-20230301094509-c82b237672a0 github.com/timakin/bodyclose v0.0.0-20221125081123-e39cf3fc478e github.com/twmb/murmur3 v1.1.6 diff --git a/go.sum b/go.sum index 54863dbe98028..3461f9199370b 100644 --- a/go.sum +++ b/go.sum @@ -938,8 +938,8 @@ github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJf github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU= github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a h1:J/YdBZ46WKpXsxsW93SG+q0F8KI+yFrcIDT4c/RNoc4= github.com/tiancaiamao/gp v0.0.0-20221230034425-4025bc8a4d4a/go.mod h1:h4xBhSNtOeEosLJ4P7JyKXX7Cabg7AVkWCK5gV2vOrM= -github.com/tikv/client-go/v2 v2.0.6-0.20230302054057-3f7860f10959 h1:3BQR4RmBxu391t3z/q9h7BjDTS3cuRn8dfgYgMWk57s= -github.com/tikv/client-go/v2 v2.0.6-0.20230302054057-3f7860f10959/go.mod h1:HdCAbFaUCsjI4n5vlCJ0rGpMfIHoD1o6UlA1rwD9u1o= +github.com/tikv/client-go/v2 v2.0.7-0.20230307075841-4037273b3ca7 h1:u3ZBOP7xD9c8FtaUyXXvcby3HZ+9LmgD+m8Sod6orP8= +github.com/tikv/client-go/v2 v2.0.7-0.20230307075841-4037273b3ca7/go.mod h1:HdCAbFaUCsjI4n5vlCJ0rGpMfIHoD1o6UlA1rwD9u1o= github.com/tikv/pd/client v0.0.0-20230301094509-c82b237672a0 h1:1fomIvN2iiKT5uZbe2E6uNHZnRzmS6O47D/PJ9BAuPw= github.com/tikv/pd/client v0.0.0-20230301094509-c82b237672a0/go.mod h1:4wjAY2NoMn4wx5+hZrEhrSGBs3jvKb+lxfUt+thHFQ4= github.com/timakin/bodyclose v0.0.0-20221125081123-e39cf3fc478e h1:MV6KaVu/hzByHP0UvJ4HcMGE/8a6A4Rggc/0wx2AvJo= diff --git a/store/copr/batch_coprocessor.go b/store/copr/batch_coprocessor.go index 273b97a0c2a13..043c8caf30386 100644 --- a/store/copr/batch_coprocessor.go +++ b/store/copr/batch_coprocessor.go @@ -327,7 +327,7 @@ func balanceBatchCopTask(ctx context.Context, kvStore *kvStore, originalTasks [] storeTaskMap[taskStoreID] = batchTask } } else { - stores := cache.RegionCache.GetTiFlashStores() + stores := cache.RegionCache.GetTiFlashStores(tikv.LabelFilterNoTiFlashWriteNode) aliveStores := filterAliveStores(ctx, stores, ttl, kvStore) for _, s := range aliveStores { storeTaskMap[s.StoreID()] = &batchCopTask{ @@ -775,7 +775,7 @@ func buildBatchCopTasksCore(bo *backoff.Backoffer, store *kvStore, rangesForEach storeTaskMap := make(map[string]*batchCopTask) needRetry := false for _, task := range tasks { - rpcCtx, err := cache.GetTiFlashRPCContext(bo.TiKVBackoffer(), task.region, isMPP) + rpcCtx, err := cache.GetTiFlashRPCContext(bo.TiKVBackoffer(), task.region, isMPP, tikv.LabelFilterNoTiFlashWriteNode) if err != nil { return nil, errors.Trace(err) } @@ -790,7 +790,7 @@ func buildBatchCopTasksCore(bo *backoff.Backoffer, store *kvStore, rangesForEach // Then `splitRegion` will reloads these regions. continue } - allStores := cache.GetAllValidTiFlashStores(task.region, rpcCtx.Store) + allStores := cache.GetAllValidTiFlashStores(task.region, rpcCtx.Store, tikv.LabelFilterNoTiFlashWriteNode) if batchCop, ok := storeTaskMap[rpcCtx.Addr]; ok { batchCop.regionInfos = append(batchCop.regionInfos, RegionInfo{Region: task.region, Meta: rpcCtx.Meta, Ranges: task.ranges, AllStores: allStores, PartitionIndex: task.partitionIndex}) } else { @@ -1256,10 +1256,11 @@ func buildBatchCopTasksConsistentHashForPD(bo *backoff.Backoffer, } getStoreElapsed = time.Since(getStoreStart) - rpcCtxs, err := cache.GetTiFlashComputeRPCContextByConsistentHash(bo.TiKVBackoffer(), regionIDs, stores) - if err != nil { - return nil, err + storesStr := make([]string, 0, len(stores)) + for _, s := range stores { + storesStr = append(storesStr, s.GetAddr()) } + rpcCtxs, err := getTiFlashComputeRPCContextByConsistentHash(regionIDs, storesStr) if rpcCtxs == nil { logutil.BgLogger().Info("buildBatchCopTasksConsistentHashForPD retry because rcpCtx is nil", zap.Int("retryNum", retryNum)) err := bo.Backoff(tikv.BoTiFlashRPC(), errors.New("Cannot find region with TiFlash peer")) diff --git a/store/copr/coprocessor.go b/store/copr/coprocessor.go index dc6656e7dfb53..09085c40a390e 100644 --- a/store/copr/coprocessor.go +++ b/store/copr/coprocessor.go @@ -1174,7 +1174,8 @@ func (worker *copIteratorWorker) handleTaskOnce(bo *Backoffer, task *copTask, ch worker.logTimeCopTask(costTime, task, bo, copResp) } storeID := strconv.FormatUint(req.Context.GetPeer().GetStoreId(), 10) - metrics.TiKVCoprocessorHistogram.WithLabelValues(storeID, strconv.FormatBool(staleRead)).Observe(costTime.Seconds()) + isInternal := util.IsRequestSourceInternal(&task.requestSource) + metrics.TiKVCoprocessorHistogram.WithLabelValues(storeID, strconv.FormatBool(staleRead), strconv.FormatBool(isInternal)).Observe(costTime.Seconds()) if copResp != nil { tidbmetrics.DistSQLCoprRespBodySize.WithLabelValues(storeAddr).Observe(float64(len(copResp.Data))) } diff --git a/store/copr/mpp.go b/store/copr/mpp.go index 3b4efc96b2c2d..dffecaa337888 100644 --- a/store/copr/mpp.go +++ b/store/copr/mpp.go @@ -54,15 +54,6 @@ func (c *batchCopTask) GetAddress() string { return c.storeAddr } -func (c *MPPClient) selectAllTiFlashStore() []kv.MPPTaskMeta { - resultTasks := make([]kv.MPPTaskMeta, 0) - for _, s := range c.store.GetRegionCache().GetTiFlashStores() { - task := &batchCopTask{storeAddr: s.GetAddr(), cmdType: tikvrpc.CmdMPPTask} - resultTasks = append(resultTasks, task) - } - return resultTasks -} - // ConstructMPPTasks receives ScheduleRequest, which are actually collects of kv ranges. We allocates MPPTaskMeta for them and returns. func (c *MPPClient) ConstructMPPTasks(ctx context.Context, req *kv.MPPBuildTasksRequest, ttl time.Duration) ([]kv.MPPTaskMeta, error) { ctx = context.WithValue(ctx, tikv.TxnStartKey(), req.StartTS) @@ -79,7 +70,7 @@ func (c *MPPClient) ConstructMPPTasks(ctx context.Context, req *kv.MPPBuildTasks tasks, err = buildBatchCopTasksForPartitionedTable(ctx, bo, c.store, rangesForEachPartition, kv.TiFlash, true, ttl, true, 20, partitionIDs) } else { if req.KeyRanges == nil { - return c.selectAllTiFlashStore(), nil + return nil, errors.New("KeyRanges in MPPBuildTasksRequest is nil") } ranges := NewKeyRanges(req.KeyRanges) tasks, err = buildBatchCopTasksForNonPartitionedTable(ctx, bo, c.store, ranges, kv.TiFlash, true, ttl, true, 20) From 840a78f2bb227c1d3a896f8aadbd6fd2e81f571d Mon Sep 17 00:00:00 2001 From: cfzjywxk Date: Tue, 7 Mar 2023 23:01:53 +0800 Subject: [PATCH 2/3] update DEPS --- DEPS.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DEPS.bzl b/DEPS.bzl index 2fde29327c4f2..9b0fcf9a8f5d1 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -4101,8 +4101,8 @@ def go_deps(): name = "com_github_tikv_client_go_v2", build_file_proto_mode = "disable_global", importpath = "github.com/tikv/client-go/v2", - sum = "h1:3BQR4RmBxu391t3z/q9h7BjDTS3cuRn8dfgYgMWk57s=", - version = "v2.0.6-0.20230302054057-3f7860f10959", + sum = "h1:u3ZBOP7xD9c8FtaUyXXvcby3HZ+9LmgD+m8Sod6orP8=", + version = "v2.0.7-0.20230307075841-4037273b3ca7", ) go_repository( name = "com_github_tikv_pd", From dc0c68153b89dddeedc8941c237f670e6089ca3e Mon Sep 17 00:00:00 2001 From: cfzjywxk Date: Wed, 8 Mar 2023 10:15:31 +0800 Subject: [PATCH 3/3] Update store/copr/coprocessor.go Co-authored-by: you06 --- store/copr/coprocessor.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/store/copr/coprocessor.go b/store/copr/coprocessor.go index 09085c40a390e..0f6c50cc4ac3d 100644 --- a/store/copr/coprocessor.go +++ b/store/copr/coprocessor.go @@ -1175,7 +1175,11 @@ func (worker *copIteratorWorker) handleTaskOnce(bo *Backoffer, task *copTask, ch } storeID := strconv.FormatUint(req.Context.GetPeer().GetStoreId(), 10) isInternal := util.IsRequestSourceInternal(&task.requestSource) - metrics.TiKVCoprocessorHistogram.WithLabelValues(storeID, strconv.FormatBool(staleRead), strconv.FormatBool(isInternal)).Observe(costTime.Seconds()) + scope := metrics.LblGeneral + if isInternal { + scope = metrics.LblInternal + } + metrics.TiKVCoprocessorHistogram.WithLabelValues(storeID, strconv.FormatBool(staleRead), scope).Observe(costTime.Seconds()) if copResp != nil { tidbmetrics.DistSQLCoprRespBodySize.WithLabelValues(storeAddr).Observe(float64(len(copResp.Data))) }