From 2f723e2902ea6a4b6229c0be9790d97fa06ee849 Mon Sep 17 00:00:00 2001 From: bufferflies <1045931706@qq.com> Date: Mon, 24 Jul 2023 11:47:50 +0800 Subject: [PATCH 1/5] bucket_version_not_match Signed-off-by: bufferflies <1045931706@qq.com> --- go.mod | 4 +++ go.sum | 1 + internal/locate/region_cache.go | 47 ++++++++++++++++++++++++------- internal/locate/region_request.go | 13 +++++++++ 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 9d88b2185..1d253c416 100644 --- a/go.mod +++ b/go.mod @@ -61,3 +61,7 @@ require ( gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace ( + github.com/pingcap/kvproto v0.0.0-20230530111525-e4919c190b46 => github.com/bufferflies/kvproto v0.0.0-20230721065214-b8832b150494 +) \ No newline at end of file diff --git a/go.sum b/go.sum index 6ce2dbee7..532b5e3ab 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,7 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bufferflies/kvproto v0.0.0-20230721065214-b8832b150494/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= diff --git a/internal/locate/region_cache.go b/internal/locate/region_cache.go index a5fb471af..009b847fc 100644 --- a/internal/locate/region_cache.go +++ b/internal/locate/region_cache.go @@ -627,16 +627,17 @@ func (c *RegionCache) SetPDClient(client pd.Client) { // RPCContext contains data that is needed to send RPC to a region. type RPCContext struct { - Region RegionVerID - Meta *metapb.Region - Peer *metapb.Peer - AccessIdx AccessIndex - Store *Store - Addr string - AccessMode accessMode - ProxyStore *Store // nil means proxy is not used - ProxyAddr string // valid when ProxyStore is not nil - TiKVNum int // Number of TiKV nodes among the region's peers. Assuming non-TiKV peers are all TiFlash peers. + Region RegionVerID + Meta *metapb.Region + Peer *metapb.Peer + AccessIdx AccessIndex + Store *Store + Addr string + AccessMode accessMode + ProxyStore *Store // nil means proxy is not used + ProxyAddr string // valid when ProxyStore is not nil + TiKVNum int // Number of TiKV nodes among the region's peers. Assuming non-TiKV peers are all TiFlash peers. + BucketVersion uint64 contextPatcher contextPatcher // kvrpcpb.Context fields that need to be overridden } @@ -1945,6 +1946,12 @@ func (c *RegionCache) getStoresByLabels(labels []*metapb.StoreLabel) []*Store { return s } +// OnBucketVersionNotMatch removes the old buckets meta if the version is stale. +func (c *RegionCache) OnBucketVersionNotMatch(bo *retry.Backoffer, ctx *RPCContext, latestVersion uint64, keys [][]byte) (bool, error) { + c.UpdateBucketsIfNeeded(ctx.Region, latestVersion) + return false, nil +} + // OnRegionEpochNotMatch removes the old region and inserts new regions into the cache. // It returns whether retries the request because it's possible the region epoch is ahead of TiKV's due to slow appling. func (c *RegionCache) OnRegionEpochNotMatch(bo *retry.Backoffer, ctx *RPCContext, currentRegions []*metapb.Region) (bool, error) { @@ -2093,6 +2100,26 @@ func (c *RegionCache) InvalidateTiFlashComputeStores() { c.tiflashComputeStoreMu.needReload = true } +// UpdateBucketOnError updates the buckets of the region in the cache if meets the buckets version not match. +func (c *RegionCache) UpdateBucketOnError(regionID RegionVerID, version uint64, keys [][]byte) { + r := c.GetCachedRegionWithRLock(regionID) + if r == nil { + return + } + + buckets := r.getStore().buckets + var bucketsVer uint64 + if buckets != nil { + bucketsVer = buckets.GetVersion() + } + if bucketsVer < version { + c.mu.Lock() + buckets.Version = version + buckets.Keys = keys + c.mu.Unlock() + } +} + // UpdateBucketsIfNeeded queries PD to update the buckets of the region in the cache if // the latestBucketsVer is newer than the cached one. func (c *RegionCache) UpdateBucketsIfNeeded(regionID RegionVerID, latestBucketsVer uint64) { diff --git a/internal/locate/region_request.go b/internal/locate/region_request.go index 9d3193431..da969fee1 100644 --- a/internal/locate/region_request.go +++ b/internal/locate/region_request.go @@ -1828,6 +1828,19 @@ func (s *RegionRequestSender) onRegionError( return retry, err } + if bucketVersionNotMatch := regionErr.GetBucketVersionNotMatch(); bucketVersionNotMatch != nil { + logutil.BgLogger().Debug( + "tikv reports `BucketVersionNotMatch` retry later", + zap.Stringer("EpochNotMatch", bucketVersionNotMatch), + zap.Stringer("ctx", ctx), + ) + retry, err := s.regionCache.OnBucketVersionNotMatch(bo, ctx, bucketVersionNotMatch.Version, bucketVersionNotMatch.Keys) + if !retry && s.replicaSelector != nil { + s.replicaSelector.invalidateRegion() + } + return retry, err + } + if serverIsBusy := regionErr.GetServerIsBusy(); serverIsBusy != nil { if s.replicaSelector != nil { return s.replicaSelector.onServerIsBusy(bo, ctx, req, serverIsBusy) From 24fab99880f85da671aaa5c9237156e62177fe90 Mon Sep 17 00:00:00 2001 From: bufferflies <1045931706@qq.com> Date: Thu, 27 Jul 2023 21:33:15 +0800 Subject: [PATCH 2/5] add unit test Signed-off-by: bufferflies <1045931706@qq.com> --- go.mod | 4 +--- go.sum | 3 +-- integration_tests/go.mod | 1 + integration_tests/go.sum | 4 ++-- internal/locate/region_cache.go | 21 ++++++++++++++++++--- internal/locate/region_cache_test.go | 9 +++++++++ internal/locate/region_request.go | 10 ++++------ internal/locate/region_request_test.go | 4 ++++ 8 files changed, 40 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 1d253c416..2a4d63653 100644 --- a/go.mod +++ b/go.mod @@ -62,6 +62,4 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace ( - github.com/pingcap/kvproto v0.0.0-20230530111525-e4919c190b46 => github.com/bufferflies/kvproto v0.0.0-20230721065214-b8832b150494 -) \ No newline at end of file +replace github.com/pingcap/kvproto v0.0.0-20230530111525-e4919c190b46 => github.com/bufferflies/kvproto v0.0.0-20230721065214-b8832b150494 diff --git a/go.sum b/go.sum index 532b5e3ab..80fb26551 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,7 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/bufferflies/kvproto v0.0.0-20230721065214-b8832b150494 h1:pPXQs+lTu4tncZj7bfkTJsxGsIRvr5Ijll5/AtEKJag= github.com/bufferflies/kvproto v0.0.0-20230721065214-b8832b150494/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -148,8 +149,6 @@ github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c h1:CgbKAHto5CQgW github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c/go.mod h1:4qGtCB0QK0wBzKtFEGDhxXnSnbQApw1gc9siScUl8ew= github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989 h1:surzm05a8C9dN8dIUmo4Be2+pMRb6f55i+UIYrluu2E= github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989/go.mod h1:O17XtbryoCJhkKGbT62+L2OlrniwqiGLSqrmdHCMzZw= -github.com/pingcap/kvproto v0.0.0-20230530111525-e4919c190b46 h1:GBlml2UIrI9IR3DdBnUWNeXizK4PwJhYPO7eWgCNErg= -github.com/pingcap/kvproto v0.0.0-20230530111525-e4919c190b46/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc= github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw= github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/integration_tests/go.mod b/integration_tests/go.mod index 7c379e3ea..e76b7d819 100644 --- a/integration_tests/go.mod +++ b/integration_tests/go.mod @@ -113,6 +113,7 @@ require ( replace ( github.com/go-ldap/ldap/v3 => github.com/YangKeao/ldap/v3 v3.4.5-0.20230421065457-369a3bab1117 + github.com/pingcap/kvproto v0.0.0-20230703085931-3788ab4ee6b3 => github.com/bufferflies/kvproto v0.0.0-20230721065214-b8832b150494 github.com/pingcap/tidb => github.com/defined2014/tidb v1.1.0-beta.0.20230712071811-87a5c15e9c7d github.com/pingcap/tidb/parser => github.com/defined2014/tidb/parser v0.0.0-20230712071811-87a5c15e9c7d github.com/tikv/client-go/v2 => ../ diff --git a/integration_tests/go.sum b/integration_tests/go.sum index 8e8d6f8f0..5debef0ec 100644 --- a/integration_tests/go.sum +++ b/integration_tests/go.sum @@ -51,6 +51,8 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/blacktear23/go-proxyprotocol v1.0.6 h1:eTt6UMpEnq59NjON49b3Cay8Dm0sCs1nDliwgkyEsRM= +github.com/bufferflies/kvproto v0.0.0-20230721065214-b8832b150494 h1:pPXQs+lTu4tncZj7bfkTJsxGsIRvr5Ijll5/AtEKJag= +github.com/bufferflies/kvproto v0.0.0-20230721065214-b8832b150494/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc= github.com/carlmjohnson/flagext v0.21.0 h1:/c4uK3ie786Z7caXLcIMvePNSSiH3bQVGDvmGLMme60= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -365,8 +367,6 @@ github.com/pingcap/fn v1.0.0 h1:CyA6AxcOZkQh52wIqYlAmaVmF6EvrcqFywP463pjA8g= github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989 h1:surzm05a8C9dN8dIUmo4Be2+pMRb6f55i+UIYrluu2E= github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989/go.mod h1:O17XtbryoCJhkKGbT62+L2OlrniwqiGLSqrmdHCMzZw= github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w= -github.com/pingcap/kvproto v0.0.0-20230703085931-3788ab4ee6b3 h1:TN9FcS+r19rKyrsPJDPfcXWkztVHfbpZ9Xkic6kE+v0= -github.com/pingcap/kvproto v0.0.0-20230703085931-3788ab4ee6b3/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc= github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM= github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4= github.com/pingcap/log v1.1.1-0.20230317032135-a0d097d16e22 h1:2SOzvGvE8beiC1Y4g9Onkvu6UmuBBOeWRGQEjJaT/JY= diff --git a/internal/locate/region_cache.go b/internal/locate/region_cache.go index 009b847fc..3a919929e 100644 --- a/internal/locate/region_cache.go +++ b/internal/locate/region_cache.go @@ -1947,9 +1947,24 @@ func (c *RegionCache) getStoresByLabels(labels []*metapb.StoreLabel) []*Store { } // OnBucketVersionNotMatch removes the old buckets meta if the version is stale. -func (c *RegionCache) OnBucketVersionNotMatch(bo *retry.Backoffer, ctx *RPCContext, latestVersion uint64, keys [][]byte) (bool, error) { - c.UpdateBucketsIfNeeded(ctx.Region, latestVersion) - return false, nil +func (c *RegionCache) OnBucketVersionNotMatch(ctx *RPCContext, version uint64, keys [][]byte) { + r := c.GetCachedRegionWithRLock(ctx.Region) + if r == nil { + println("reigon not found") + return + } + + buckets := r.getStore().buckets + if buckets == nil || buckets.GetVersion() < version { + oldStore := r.getStore() + store := oldStore.clone() + store.buckets = &metapb.Buckets{ + Version: version, + Keys: keys, + RegionId: r.meta.GetId(), + } + r.compareAndSwapStore(oldStore, store) + } } // OnRegionEpochNotMatch removes the old region and inserts new regions into the cache. diff --git a/internal/locate/region_cache_test.go b/internal/locate/region_cache_test.go index 619da2d2e..6226a1c60 100644 --- a/internal/locate/region_cache_test.go +++ b/internal/locate/region_cache_test.go @@ -1646,6 +1646,15 @@ func (s *testRegionCacheSuite) TestShouldNotRetryFlashback() { shouldRetry, err = reqSend.onRegionError(s.bo, ctx, nil, &errorpb.Error{FlashbackNotPrepared: &errorpb.FlashbackNotPrepared{}}) s.Error(err) s.False(shouldRetry) + + shouldRetry, err = reqSend.onRegionError(s.bo, ctx, nil, &errorpb.Error{BucketVersionNotMatch: &errorpb.BucketVersionNotMatch{Keys: [][]byte{[]byte("a")}, Version: 1}}) + s.Nil(err) + s.False(shouldRetry) + ctx.Region.GetID() + key, err := s.cache.LocateKey(s.bo, []byte("a")) + s.Nil(err) + s.Equal(key.Buckets.Keys, [][]byte{[]byte("a")}) + s.Equal(key.Buckets.Version, uint64(1)) } func (s *testRegionCacheSuite) TestBackgroundCacheGC() { diff --git a/internal/locate/region_request.go b/internal/locate/region_request.go index da969fee1..dce0f6008 100644 --- a/internal/locate/region_request.go +++ b/internal/locate/region_request.go @@ -1831,14 +1831,12 @@ func (s *RegionRequestSender) onRegionError( if bucketVersionNotMatch := regionErr.GetBucketVersionNotMatch(); bucketVersionNotMatch != nil { logutil.BgLogger().Debug( "tikv reports `BucketVersionNotMatch` retry later", - zap.Stringer("EpochNotMatch", bucketVersionNotMatch), + zap.Stringer("bucketVersionNotMatch", bucketVersionNotMatch), zap.Stringer("ctx", ctx), ) - retry, err := s.regionCache.OnBucketVersionNotMatch(bo, ctx, bucketVersionNotMatch.Version, bucketVersionNotMatch.Keys) - if !retry && s.replicaSelector != nil { - s.replicaSelector.invalidateRegion() - } - return retry, err + // bucket version is not match, we should split this cop request again. + s.regionCache.OnBucketVersionNotMatch(ctx, bucketVersionNotMatch.Version, bucketVersionNotMatch.Keys) + return false, nil } if serverIsBusy := regionErr.GetServerIsBusy(); serverIsBusy != nil { diff --git a/internal/locate/region_request_test.go b/internal/locate/region_request_test.go index 42c8ceb34..0b936e807 100644 --- a/internal/locate/region_request_test.go +++ b/internal/locate/region_request_test.go @@ -291,6 +291,10 @@ func (c *cancelContextClient) SendRequest(ctx context.Context, addr string, req // mockTikvGrpcServer mock a tikv gprc server for testing. type mockTikvGrpcServer struct{} +func (s *mockTikvGrpcServer) ReportMPPTaskStatus(ctx context.Context, request *mpp.ReportTaskStatusRequest) (*mpp.ReportTaskStatusResponse, error) { + return nil, errors.New("unreachable") +} + var _ tikvpb.TikvServer = &mockTikvGrpcServer{} // KvGet commands with mvcc/txn supported. From 21449c37a420455923904c08d1f9b7d467b4d734 Mon Sep 17 00:00:00 2001 From: bufferflies <1045931706@qq.com> Date: Thu, 3 Aug 2023 15:59:08 +0800 Subject: [PATCH 3/5] update kv proto Signed-off-by: bufferflies <1045931706@qq.com> --- go.mod | 2 +- go.sum | 4 ++-- integration_tests/go.mod | 2 +- integration_tests/go.sum | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 2a4d63653..1885c2533 100644 --- a/go.mod +++ b/go.mod @@ -62,4 +62,4 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/pingcap/kvproto v0.0.0-20230530111525-e4919c190b46 => github.com/bufferflies/kvproto v0.0.0-20230721065214-b8832b150494 +replace github.com/pingcap/kvproto v0.0.0-20230530111525-e4919c190b46 => github.com/bufferflies/kvproto v0.0.0-20230803075552-24f552d99840 diff --git a/go.sum b/go.sum index 80fb26551..93149ab2b 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/bufferflies/kvproto v0.0.0-20230721065214-b8832b150494 h1:pPXQs+lTu4tncZj7bfkTJsxGsIRvr5Ijll5/AtEKJag= -github.com/bufferflies/kvproto v0.0.0-20230721065214-b8832b150494/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc= +github.com/bufferflies/kvproto v0.0.0-20230803075552-24f552d99840 h1:fBte2Jw0IZZCz3XzWc/N6OuD1mCNhDrhTkx3OmXnzcU= +github.com/bufferflies/kvproto v0.0.0-20230803075552-24f552d99840/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= diff --git a/integration_tests/go.mod b/integration_tests/go.mod index e76b7d819..1c7a52ee7 100644 --- a/integration_tests/go.mod +++ b/integration_tests/go.mod @@ -113,7 +113,7 @@ require ( replace ( github.com/go-ldap/ldap/v3 => github.com/YangKeao/ldap/v3 v3.4.5-0.20230421065457-369a3bab1117 - github.com/pingcap/kvproto v0.0.0-20230703085931-3788ab4ee6b3 => github.com/bufferflies/kvproto v0.0.0-20230721065214-b8832b150494 + github.com/pingcap/kvproto v0.0.0-20230703085931-3788ab4ee6b3 => github.com/bufferflies/kvproto v0.0.0-20230803075552-24f552d99840 github.com/pingcap/tidb => github.com/defined2014/tidb v1.1.0-beta.0.20230712071811-87a5c15e9c7d github.com/pingcap/tidb/parser => github.com/defined2014/tidb/parser v0.0.0-20230712071811-87a5c15e9c7d github.com/tikv/client-go/v2 => ../ diff --git a/integration_tests/go.sum b/integration_tests/go.sum index 5debef0ec..e4c598d13 100644 --- a/integration_tests/go.sum +++ b/integration_tests/go.sum @@ -51,8 +51,8 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/blacktear23/go-proxyprotocol v1.0.6 h1:eTt6UMpEnq59NjON49b3Cay8Dm0sCs1nDliwgkyEsRM= -github.com/bufferflies/kvproto v0.0.0-20230721065214-b8832b150494 h1:pPXQs+lTu4tncZj7bfkTJsxGsIRvr5Ijll5/AtEKJag= -github.com/bufferflies/kvproto v0.0.0-20230721065214-b8832b150494/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc= +github.com/bufferflies/kvproto v0.0.0-20230803075552-24f552d99840 h1:fBte2Jw0IZZCz3XzWc/N6OuD1mCNhDrhTkx3OmXnzcU= +github.com/bufferflies/kvproto v0.0.0-20230803075552-24f552d99840/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc= github.com/carlmjohnson/flagext v0.21.0 h1:/c4uK3ie786Z7caXLcIMvePNSSiH3bQVGDvmGLMme60= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= From b530abf50d50cf8c86fe2088888e474251362799 Mon Sep 17 00:00:00 2001 From: bufferflies <1045931706@qq.com> Date: Mon, 21 Aug 2023 11:29:10 +0800 Subject: [PATCH 4/5] update kvprotoc Signed-off-by: bufferflies <1045931706@qq.com> --- go.mod | 4 +--- go.sum | 4 ++-- integration_tests/go.mod | 3 +-- integration_tests/go.sum | 4 ++-- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 1885c2533..0d702f63a 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989 - github.com/pingcap/kvproto v0.0.0-20230530111525-e4919c190b46 + github.com/pingcap/kvproto v0.0.0-20230818065851-7b612d935bf9 github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.15.1 @@ -61,5 +61,3 @@ require ( gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) - -replace github.com/pingcap/kvproto v0.0.0-20230530111525-e4919c190b46 => github.com/bufferflies/kvproto v0.0.0-20230803075552-24f552d99840 diff --git a/go.sum b/go.sum index 93149ab2b..0fbd76ea1 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,6 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/bufferflies/kvproto v0.0.0-20230803075552-24f552d99840 h1:fBte2Jw0IZZCz3XzWc/N6OuD1mCNhDrhTkx3OmXnzcU= -github.com/bufferflies/kvproto v0.0.0-20230803075552-24f552d99840/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= @@ -149,6 +147,8 @@ github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c h1:CgbKAHto5CQgW github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c/go.mod h1:4qGtCB0QK0wBzKtFEGDhxXnSnbQApw1gc9siScUl8ew= github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989 h1:surzm05a8C9dN8dIUmo4Be2+pMRb6f55i+UIYrluu2E= github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989/go.mod h1:O17XtbryoCJhkKGbT62+L2OlrniwqiGLSqrmdHCMzZw= +github.com/pingcap/kvproto v0.0.0-20230818065851-7b612d935bf9 h1:VDoZ18CAXoTUNTCxfl4BjQSD5rJQri8QlH8nu0ZuHeg= +github.com/pingcap/kvproto v0.0.0-20230818065851-7b612d935bf9/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc= github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw= github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/integration_tests/go.mod b/integration_tests/go.mod index 1c7a52ee7..02edba920 100644 --- a/integration_tests/go.mod +++ b/integration_tests/go.mod @@ -6,7 +6,7 @@ require ( github.com/ninedraft/israce v0.0.3 github.com/pingcap/errors v0.11.5-0.20221009092201-b66cddb77c32 github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c - github.com/pingcap/kvproto v0.0.0-20230703085931-3788ab4ee6b3 + github.com/pingcap/kvproto v0.0.0-20230818065851-7b612d935bf9 github.com/pingcap/tidb v1.1.0-beta.0.20230619015310-8b1006f1af04 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 @@ -113,7 +113,6 @@ require ( replace ( github.com/go-ldap/ldap/v3 => github.com/YangKeao/ldap/v3 v3.4.5-0.20230421065457-369a3bab1117 - github.com/pingcap/kvproto v0.0.0-20230703085931-3788ab4ee6b3 => github.com/bufferflies/kvproto v0.0.0-20230803075552-24f552d99840 github.com/pingcap/tidb => github.com/defined2014/tidb v1.1.0-beta.0.20230712071811-87a5c15e9c7d github.com/pingcap/tidb/parser => github.com/defined2014/tidb/parser v0.0.0-20230712071811-87a5c15e9c7d github.com/tikv/client-go/v2 => ../ diff --git a/integration_tests/go.sum b/integration_tests/go.sum index e4c598d13..b38705438 100644 --- a/integration_tests/go.sum +++ b/integration_tests/go.sum @@ -51,8 +51,6 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/blacktear23/go-proxyprotocol v1.0.6 h1:eTt6UMpEnq59NjON49b3Cay8Dm0sCs1nDliwgkyEsRM= -github.com/bufferflies/kvproto v0.0.0-20230803075552-24f552d99840 h1:fBte2Jw0IZZCz3XzWc/N6OuD1mCNhDrhTkx3OmXnzcU= -github.com/bufferflies/kvproto v0.0.0-20230803075552-24f552d99840/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc= github.com/carlmjohnson/flagext v0.21.0 h1:/c4uK3ie786Z7caXLcIMvePNSSiH3bQVGDvmGLMme60= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -367,6 +365,8 @@ github.com/pingcap/fn v1.0.0 h1:CyA6AxcOZkQh52wIqYlAmaVmF6EvrcqFywP463pjA8g= github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989 h1:surzm05a8C9dN8dIUmo4Be2+pMRb6f55i+UIYrluu2E= github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989/go.mod h1:O17XtbryoCJhkKGbT62+L2OlrniwqiGLSqrmdHCMzZw= github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w= +github.com/pingcap/kvproto v0.0.0-20230818065851-7b612d935bf9 h1:VDoZ18CAXoTUNTCxfl4BjQSD5rJQri8QlH8nu0ZuHeg= +github.com/pingcap/kvproto v0.0.0-20230818065851-7b612d935bf9/go.mod h1:r0q/CFcwvyeRhKtoqzmWMBebrtpIziQQ9vR+JKh1knc= github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM= github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4= github.com/pingcap/log v1.1.1-0.20230317032135-a0d097d16e22 h1:2SOzvGvE8beiC1Y4g9Onkvu6UmuBBOeWRGQEjJaT/JY= From 2e569e4d40c2846d0e70306dfc3c960ef065a3cc Mon Sep 17 00:00:00 2001 From: bufferflies <1045931706@qq.com> Date: Mon, 21 Aug 2023 14:21:15 +0800 Subject: [PATCH 5/5] address comment Signed-off-by: bufferflies <1045931706@qq.com> --- internal/locate/region_cache.go | 21 --------------------- internal/locate/region_request.go | 2 +- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/internal/locate/region_cache.go b/internal/locate/region_cache.go index d50ca3f02..56444ac09 100644 --- a/internal/locate/region_cache.go +++ b/internal/locate/region_cache.go @@ -1952,7 +1952,6 @@ func (c *RegionCache) getStoresByLabels(labels []*metapb.StoreLabel) []*Store { func (c *RegionCache) OnBucketVersionNotMatch(ctx *RPCContext, version uint64, keys [][]byte) { r := c.GetCachedRegionWithRLock(ctx.Region) if r == nil { - println("reigon not found") return } @@ -2117,26 +2116,6 @@ func (c *RegionCache) InvalidateTiFlashComputeStores() { c.tiflashComputeStoreMu.needReload = true } -// UpdateBucketOnError updates the buckets of the region in the cache if meets the buckets version not match. -func (c *RegionCache) UpdateBucketOnError(regionID RegionVerID, version uint64, keys [][]byte) { - r := c.GetCachedRegionWithRLock(regionID) - if r == nil { - return - } - - buckets := r.getStore().buckets - var bucketsVer uint64 - if buckets != nil { - bucketsVer = buckets.GetVersion() - } - if bucketsVer < version { - c.mu.Lock() - buckets.Version = version - buckets.Keys = keys - c.mu.Unlock() - } -} - // UpdateBucketsIfNeeded queries PD to update the buckets of the region in the cache if // the latestBucketsVer is newer than the cached one. func (c *RegionCache) UpdateBucketsIfNeeded(regionID RegionVerID, latestBucketsVer uint64) { diff --git a/internal/locate/region_request.go b/internal/locate/region_request.go index 030c999e0..fc4e51bba 100644 --- a/internal/locate/region_request.go +++ b/internal/locate/region_request.go @@ -2039,7 +2039,7 @@ func (s *RegionRequestSender) onRegionError( } if bucketVersionNotMatch := regionErr.GetBucketVersionNotMatch(); bucketVersionNotMatch != nil { - logutil.BgLogger().Debug( + logutil.Logger(bo.GetCtx()).Debug( "tikv reports `BucketVersionNotMatch` retry later", zap.Stringer("bucketVersionNotMatch", bucketVersionNotMatch), zap.Stringer("ctx", ctx),