Skip to content

Commit 29ead01

Browse files
add failed_regions_id for scatter regions response (#9167)
close #9088 Signed-off-by: gmhdbjd <[email protected]> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
1 parent 4a1d775 commit 29ead01

File tree

9 files changed

+41
-15
lines changed

9 files changed

+41
-15
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ require (
3535
github.com/pingcap/errcode v0.3.0
3636
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c
3737
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86
38-
github.com/pingcap/kvproto v0.0.0-20250521074834-db74bf0e3ac1
38+
github.com/pingcap/kvproto v0.0.0-20250604104108-d780eebb4f38
3939
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
4040
github.com/pingcap/sysutil v1.0.1-0.20230407040306-fb007c5aff21
4141
github.com/pingcap/tidb-dashboard v0.0.0-20250219061340-d62018124ae2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c/go.mod h1:X2r9ue
392392
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 h1:tdMsjOqUR7YXHoBitzdebTvOjs/swniBTOLy5XiMtuE=
393393
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86/go.mod h1:exzhVYca3WRtd6gclGNErRWb1qEgff3LYta0LvRmON4=
394394
github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w=
395-
github.com/pingcap/kvproto v0.0.0-20250521074834-db74bf0e3ac1 h1:peVY7sHw2RCDH8lEHEVMYe4M7GXyeXRKR8QDc5f5dM4=
396-
github.com/pingcap/kvproto v0.0.0-20250521074834-db74bf0e3ac1/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
395+
github.com/pingcap/kvproto v0.0.0-20250604104108-d780eebb4f38 h1:V088U5aznaPX6SK5Oyznb7LhrBicuaYsdI9bb4Fzjq4=
396+
github.com/pingcap/kvproto v0.0.0-20250604104108-d780eebb4f38/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
397397
github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM=
398398
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw=
399399
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=

pkg/mcs/scheduling/server/grpc_service.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ func (s *Service) ScatterRegions(_ context.Context, request *schedulingpb.Scatte
216216
return &schedulingpb.ScatterRegionsResponse{Header: header}, nil
217217
}
218218
percentage := 100
219+
failedRegionIDs := make([]uint64, 0, len(failures))
219220
if len(failures) > 0 {
220221
percentage = 100 - 100*len(failures)/(opsCount+len(failures))
221222
log.Debug("scatter regions", zap.Errors("failures", func() []error {
@@ -225,10 +226,14 @@ func (s *Service) ScatterRegions(_ context.Context, request *schedulingpb.Scatte
225226
}
226227
return r
227228
}()))
229+
for regionID := range failures {
230+
failedRegionIDs = append(failedRegionIDs, regionID)
231+
}
228232
}
229233
return &schedulingpb.ScatterRegionsResponse{
230234
Header: wrapHeader(),
231235
FinishedPercentage: uint64(percentage),
236+
FailedRegionsId: failedRegionIDs,
232237
}, nil
233238
}
234239

server/grpc_service.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import (
3232
"go.uber.org/multierr"
3333
"go.uber.org/zap"
3434
"google.golang.org/grpc"
35+
"google.golang.org/grpc/codes"
36+
"google.golang.org/grpc/status"
3537

3638
"github.com/pingcap/errors"
3739
"github.com/pingcap/failpoint"
@@ -2111,13 +2113,14 @@ func (s *GrpcServer) ScatterRegion(ctx context.Context, request *pdpb.ScatterReg
21112113
}
21122114

21132115
if len(request.GetRegionsId()) > 0 {
2114-
percentage, err := scatterRegions(rc, request.GetRegionsId(), request.GetGroup(), int(request.GetRetryLimit()), request.GetSkipStoreLimit())
2116+
percentage, failedRegionsID, err := scatterRegions(rc, request.GetRegionsId(), request.GetGroup(), int(request.GetRetryLimit()), request.GetSkipStoreLimit())
21152117
if err != nil {
21162118
return nil, err
21172119
}
21182120
return &pdpb.ScatterRegionResponse{
21192121
Header: wrapHeader(),
21202122
FinishedPercentage: uint64(percentage),
2123+
FailedRegionsId: failedRegionsID,
21212124
}, nil
21222125
}
21232126
// TODO: Deprecate it use `request.GetRegionsID`.
@@ -2486,6 +2489,7 @@ func convertScatterResponse(resp *schedulingpb.ScatterRegionsResponse) *pdpb.Sca
24862489
return &pdpb.ScatterRegionResponse{
24872490
Header: convertHeader(resp.GetHeader()),
24882491
FinishedPercentage: resp.GetFinishedPercentage(),
2492+
FailedRegionsId: resp.GetFailedRegionsId(),
24892493
}
24902494
}
24912495

@@ -2598,7 +2602,7 @@ func (s *GrpcServer) SplitAndScatterRegions(ctx context.Context, request *pdpb.S
25982602
return &pdpb.SplitAndScatterRegionsResponse{Header: notBootstrappedHeader()}, nil
25992603
}
26002604
splitFinishedPercentage, newRegionIDs := rc.GetRegionSplitter().SplitRegions(ctx, request.GetSplitKeys(), int(request.GetRetryLimit()))
2601-
scatterFinishedPercentage, err := scatterRegions(rc, newRegionIDs, request.GetGroup(), int(request.GetRetryLimit()), false)
2605+
scatterFinishedPercentage, _, err := scatterRegions(rc, newRegionIDs, request.GetGroup(), int(request.GetRetryLimit()), false)
26022606
if err != nil {
26032607
return nil, err
26042608
}
@@ -2610,13 +2614,15 @@ func (s *GrpcServer) SplitAndScatterRegions(ctx context.Context, request *pdpb.S
26102614
}, nil
26112615
}
26122616

2613-
// scatterRegions add operators to scatter regions and return the processed percentage and error
2614-
func scatterRegions(cluster *cluster.RaftCluster, regionsID []uint64, group string, retryLimit int, skipStoreLimit bool) (int, error) {
2617+
// scatterRegions add operators to scatter regions
2618+
// returns the percentage of successfully scattered regions and the IDs of failed regions
2619+
func scatterRegions(cluster *cluster.RaftCluster, regionsID []uint64, group string, retryLimit int, skipStoreLimit bool) (int, []uint64, error) {
26152620
opsCount, failures, err := cluster.GetRegionScatterer().ScatterRegionsByID(regionsID, group, retryLimit, skipStoreLimit)
26162621
if err != nil {
2617-
return 0, err
2622+
return 0, nil, err
26182623
}
26192624
percentage := 100
2625+
var failedRegionIDs []uint64
26202626
if len(failures) > 0 {
26212627
percentage = 100 - 100*len(failures)/(opsCount+len(failures))
26222628
log.Debug("scatter regions", zap.Errors("failures", func() []error {
@@ -2626,8 +2632,11 @@ func scatterRegions(cluster *cluster.RaftCluster, regionsID []uint64, group stri
26262632
}
26272633
return r
26282634
}()))
2635+
for regionID := range failures {
2636+
failedRegionIDs = append(failedRegionIDs, regionID)
2637+
}
26292638
}
2630-
return percentage, nil
2639+
return percentage, failedRegionIDs, nil
26312640
}
26322641

26332642
// GetDCLocationInfo implements gRPC PDServer.
@@ -2944,3 +2953,13 @@ func (s *GrpcServer) rateLimitCheck() (done ratelimit.DoneFunc, err error) {
29442953
}
29452954
return
29462955
}
2956+
2957+
// SetGlobalGCBarrier implements gRPC PDServer.
2958+
func (*GrpcServer) SetGlobalGCBarrier(context.Context, *pdpb.SetGlobalGCBarrierRequest) (*pdpb.SetGlobalGCBarrierResponse, error) {
2959+
return nil, status.Errorf(codes.Unimplemented, "SetGlobalGCBarrier is not implemented yet, waiting for https://github.com/tikv/pd/pull/9361")
2960+
}
2961+
2962+
// DeleteGlobalGCBarrier implements gRPC PDServer.
2963+
func (*GrpcServer) DeleteGlobalGCBarrier(context.Context, *pdpb.DeleteGlobalGCBarrierRequest) (*pdpb.DeleteGlobalGCBarrierResponse, error) {
2964+
return nil, status.Errorf(codes.Unimplemented, "DeleteGlobalGCBarrier is not implemented yet, waiting for https://github.com/tikv/pd/pull/9361")
2965+
}

tests/integrations/client/client_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,8 +1303,10 @@ func (suite *clientStatelessTestSuite) TestScatterRegion() {
13031303
return false
13041304
}
13051305
if scatterResp.FinishedPercentage != uint64(100) {
1306+
re.Contains(scatterResp.FailedRegionsId, regionID)
13061307
return false
13071308
}
1309+
re.Empty(scatterResp.FailedRegionsId)
13081310
resp, err := suite.client.GetOperator(context.Background(), regionID)
13091311
if err != nil {
13101312
return false

tests/integrations/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/go-sql-driver/mysql v1.7.0
1515
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c
1616
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86
17-
github.com/pingcap/kvproto v0.0.0-20250521074834-db74bf0e3ac1
17+
github.com/pingcap/kvproto v0.0.0-20250604104108-d780eebb4f38
1818
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
1919
github.com/prometheus/client_golang v1.20.5
2020
github.com/prometheus/client_model v0.6.1

tests/integrations/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@ github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c/go.mod h1:X2r9ue
385385
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 h1:tdMsjOqUR7YXHoBitzdebTvOjs/swniBTOLy5XiMtuE=
386386
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86/go.mod h1:exzhVYca3WRtd6gclGNErRWb1qEgff3LYta0LvRmON4=
387387
github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w=
388-
github.com/pingcap/kvproto v0.0.0-20250521074834-db74bf0e3ac1 h1:peVY7sHw2RCDH8lEHEVMYe4M7GXyeXRKR8QDc5f5dM4=
389-
github.com/pingcap/kvproto v0.0.0-20250521074834-db74bf0e3ac1/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
388+
github.com/pingcap/kvproto v0.0.0-20250604104108-d780eebb4f38 h1:V088U5aznaPX6SK5Oyznb7LhrBicuaYsdI9bb4Fzjq4=
389+
github.com/pingcap/kvproto v0.0.0-20250604104108-d780eebb4f38/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
390390
github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM=
391391
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw=
392392
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=

tools/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/mattn/go-shellwords v1.0.12
2323
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c
2424
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86
25-
github.com/pingcap/kvproto v0.0.0-20250521074834-db74bf0e3ac1
25+
github.com/pingcap/kvproto v0.0.0-20250604104108-d780eebb4f38
2626
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
2727
github.com/pmezard/go-difflib v1.0.0
2828
github.com/prometheus/client_golang v1.20.5

tools/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c/go.mod h1:X2r9ue
390390
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 h1:tdMsjOqUR7YXHoBitzdebTvOjs/swniBTOLy5XiMtuE=
391391
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86/go.mod h1:exzhVYca3WRtd6gclGNErRWb1qEgff3LYta0LvRmON4=
392392
github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w=
393-
github.com/pingcap/kvproto v0.0.0-20250521074834-db74bf0e3ac1 h1:peVY7sHw2RCDH8lEHEVMYe4M7GXyeXRKR8QDc5f5dM4=
394-
github.com/pingcap/kvproto v0.0.0-20250521074834-db74bf0e3ac1/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
393+
github.com/pingcap/kvproto v0.0.0-20250604104108-d780eebb4f38 h1:V088U5aznaPX6SK5Oyznb7LhrBicuaYsdI9bb4Fzjq4=
394+
github.com/pingcap/kvproto v0.0.0-20250604104108-d780eebb4f38/go.mod h1:rXxWk2UnwfUhLXha1jxRWPADw9eMZGWEWCg92Tgmb/8=
395395
github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM=
396396
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw=
397397
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=

0 commit comments

Comments
 (0)