diff --git a/go.mod b/go.mod index ce79f065e..f2e28411d 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/opentracing/opentracing-go v1.2.0 github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00 github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989 - github.com/pingcap/kvproto v0.0.0-20221129023506-621ec37aac7a + github.com/pingcap/kvproto v0.0.0-20221130022225-6c56ac56fe5f github.com/pingcap/log v1.1.1-0.20221015072633-39906604fb81 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.11.0 diff --git a/go.sum b/go.sum index 2ae88f5f4..17f5bd6c2 100644 --- a/go.sum +++ b/go.sum @@ -155,8 +155,8 @@ github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00/go.mod h1:4qGtCB 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-20221026112947-f8d61344b172/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= -github.com/pingcap/kvproto v0.0.0-20221129023506-621ec37aac7a h1:LzIZsQpXQlj8yF7+yvyOg680OaPq7bmPuDuszgXfHsw= -github.com/pingcap/kvproto v0.0.0-20221129023506-621ec37aac7a/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= +github.com/pingcap/kvproto v0.0.0-20221130022225-6c56ac56fe5f h1:46ZD6xzQWJ8Jkeal/U7SqkX030Mgs8DAn6QV/9zbqOQ= +github.com/pingcap/kvproto v0.0.0-20221130022225-6c56ac56fe5f/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= github.com/pingcap/log v1.1.1-0.20221015072633-39906604fb81 h1:URLoJ61DmmY++Sa/yyPEQHG2s/ZBeV1FbIswHEMrdoY= github.com/pingcap/log v1.1.1-0.20221015072633-39906604fb81/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 511cdb153..31b410edc 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.20220729040631-518f63d66278 github.com/pingcap/failpoint v0.0.0-20220423142525-ae43b7f4e5c3 - github.com/pingcap/kvproto v0.0.0-20221129023506-621ec37aac7a + github.com/pingcap/kvproto v0.0.0-20221130022225-6c56ac56fe5f github.com/pingcap/tidb v1.1.0-beta.0.20221101102559-97add26c8f84 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.0 diff --git a/integration_tests/go.sum b/integration_tests/go.sum index a74cbace6..1c00ed000 100644 --- a/integration_tests/go.sum +++ b/integration_tests/go.sum @@ -408,8 +408,8 @@ github.com/pingcap/fn v0.0.0-20200306044125-d5540d389059 h1:Pe2LbxRmbTfAoKJ65bZL 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-20221026112947-f8d61344b172/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= -github.com/pingcap/kvproto v0.0.0-20221129023506-621ec37aac7a h1:LzIZsQpXQlj8yF7+yvyOg680OaPq7bmPuDuszgXfHsw= -github.com/pingcap/kvproto v0.0.0-20221129023506-621ec37aac7a/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= +github.com/pingcap/kvproto v0.0.0-20221130022225-6c56ac56fe5f h1:46ZD6xzQWJ8Jkeal/U7SqkX030Mgs8DAn6QV/9zbqOQ= +github.com/pingcap/kvproto v0.0.0-20221130022225-6c56ac56fe5f/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= github.com/pingcap/log v0.0.0-20200511115504-543df19646ad/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8= github.com/pingcap/log v1.1.1-0.20221015072633-39906604fb81 h1:URLoJ61DmmY++Sa/yyPEQHG2s/ZBeV1FbIswHEMrdoY= github.com/pingcap/log v1.1.1-0.20221015072633-39906604fb81/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4= diff --git a/internal/locate/region_cache.go b/internal/locate/region_cache.go index 5a353a815..ad72bfe16 100644 --- a/internal/locate/region_cache.go +++ b/internal/locate/region_cache.go @@ -806,10 +806,11 @@ func (c *RegionCache) GetTiFlashComputeRPCContextByConsistentHash(bo *retry.Back // KeyLocation is the region and range that a key is located. type KeyLocation struct { - Region RegionVerID - StartKey []byte - EndKey []byte - Buckets *metapb.Buckets + Region RegionVerID + StartKey []byte + EndKey []byte + Buckets *metapb.Buckets + RawRegion *Region } // Contains checks if key is in [StartKey, EndKey). @@ -915,10 +916,11 @@ func (c *RegionCache) LocateKey(bo *retry.Backoffer, key []byte) (*KeyLocation, return nil, err } return &KeyLocation{ - Region: r.VerID(), - StartKey: r.StartKey(), - EndKey: r.EndKey(), - Buckets: r.getStore().buckets, + Region: r.VerID(), + StartKey: r.StartKey(), + EndKey: r.EndKey(), + Buckets: r.getStore().buckets, + RawRegion: r, }, nil } @@ -930,10 +932,11 @@ func (c *RegionCache) LocateEndKey(bo *retry.Backoffer, key []byte) (*KeyLocatio return nil, err } return &KeyLocation{ - Region: r.VerID(), - StartKey: r.StartKey(), - EndKey: r.EndKey(), - Buckets: r.getStore().buckets, + Region: r.VerID(), + StartKey: r.StartKey(), + EndKey: r.EndKey(), + Buckets: r.getStore().buckets, + RawRegion: r, }, nil } @@ -1100,10 +1103,11 @@ func (c *RegionCache) LocateRegionByID(bo *retry.Backoffer, regionID uint64) (*K } } loc := &KeyLocation{ - Region: r.VerID(), - StartKey: r.StartKey(), - EndKey: r.EndKey(), - Buckets: r.getStore().buckets, + Region: r.VerID(), + StartKey: r.StartKey(), + EndKey: r.EndKey(), + Buckets: r.getStore().buckets, + RawRegion: r, } return loc, nil } @@ -1117,10 +1121,11 @@ func (c *RegionCache) LocateRegionByID(bo *retry.Backoffer, regionID uint64) (*K c.insertRegionToCache(r) c.mu.Unlock() return &KeyLocation{ - Region: r.VerID(), - StartKey: r.StartKey(), - EndKey: r.EndKey(), - Buckets: r.getStore().buckets, + Region: r.VerID(), + StartKey: r.StartKey(), + EndKey: r.EndKey(), + Buckets: r.getStore().buckets, + RawRegion: r, }, nil } @@ -1774,7 +1779,7 @@ func (c *RegionCache) OnRegionEpochNotMatch(bo *retry.Backoffer, ctx *RPCContext } else { initLeaderStoreID = ctx.Store.storeID } - region.switchWorkLeaderToPeer(region.getPeerOnStore(initLeaderStoreID)) + region.switchWorkLeaderToPeer(region.GetPeerOnStore(initLeaderStoreID)) newRegions = append(newRegions, region) if ctx.Region == region.VerID() { needInvalidateOld = false @@ -2126,7 +2131,8 @@ func (r *Region) findElectableStoreID() uint64 { return 0 } -func (r *Region) getPeerOnStore(storeID uint64) *metapb.Peer { +// GetPeerOnStore get the peer in the given store id. +func (r *Region) GetPeerOnStore(storeID uint64) *metapb.Peer { for _, p := range r.meta.Peers { if p.StoreId == storeID { return p diff --git a/internal/locate/region_request3_test.go b/internal/locate/region_request3_test.go index a9f495bf5..4feb97f70 100644 --- a/internal/locate/region_request3_test.go +++ b/internal/locate/region_request3_test.go @@ -319,7 +319,7 @@ func (s *testRegionRequestToThreeStoresSuite) TestReplicaSelector() { // Verify that the store matches the peer and epoch. for _, replica := range replicaSelector.replicas { s.Equal(replica.store.storeID, replica.peer.GetStoreId()) - s.Equal(replica.peer, region.getPeerOnStore(replica.store.storeID)) + s.Equal(replica.peer, region.GetPeerOnStore(replica.store.storeID)) s.True(replica.attempts == 0) for i, store := range regionStore.stores {