Skip to content

Commit

Permalink
This is an automated cherry-pick of #6953
Browse files Browse the repository at this point in the history
close #6950

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
mittalrishabh authored and ti-chi-bot committed Aug 29, 2023
1 parent 75bb796 commit 0439df5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
15 changes: 13 additions & 2 deletions server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1341,8 +1341,19 @@ func (s *GrpcServer) ScatterRegion(ctx context.Context, request *pdpb.ScatterReg
if err != nil {
return nil, err
}
if op != nil {
rc.GetOperatorController().AddOperator(op)

if op == nil {
return &pdpb.ScatterRegionResponse{
Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN,
"operator could not be allocated"),
}, nil
}

if !rc.GetOperatorController().AddOperator(op) {
return &pdpb.ScatterRegionResponse{
Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN,
"operator cancelled because store limit exceeded"),
}, nil
}

return &pdpb.ScatterRegionResponse{
Expand Down
12 changes: 12 additions & 0 deletions server/schedule/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,19 @@ func (oc *OperatorController) AddOperator(ops ...*operator.Operator) bool {
// but maybe user want to add operator when waiting queue is busy
if oc.exceedStoreLimitLocked(ops...) || !oc.checkAddOperator(false, ops...) {
for _, op := range ops {
<<<<<<< HEAD:server/schedule/operator_controller.go

Check failure on line 327 in server/schedule/operator_controller.go

View workflow job for this annotation

GitHub Actions / statics

syntax error: unexpected <<, expecting }
_ = op.Cancel()

Check failure on line 328 in server/schedule/operator_controller.go

View workflow job for this annotation

GitHub Actions / statics

expression in go must be function call

Check failure on line 328 in server/schedule/operator_controller.go

View workflow job for this annotation

GitHub Actions / statics

syntax error: unexpected = at end of statement
=======

Check failure on line 329 in server/schedule/operator_controller.go

View workflow job for this annotation

GitHub Actions / statics

syntax error: unexpected ==, expecting }
operatorCounter.WithLabelValues(op.Desc(), "exceed-limit").Inc()
_ = op.Cancel(ExceedStoreLimit)
oc.buryOperator(op)
}
return false

Check failure on line 334 in server/schedule/operator_controller.go

View workflow job for this annotation

GitHub Actions / statics

syntax error: non-declaration statement outside function body
}
if pass, reason := oc.checkAddOperator(false, ops...); !pass {
for _, op := range ops {
_ = op.Cancel(reason)
>>>>>>> 9aba1a298 (pkg/schedule, grpc_service : Add error code if scatter_region grpc is failed (#6953)):pkg/schedule/operator/operator_controller.go

Check failure on line 339 in server/schedule/operator_controller.go

View workflow job for this annotation

GitHub Actions / statics

invalid character U+0023 '#'
oc.buryOperator(op)
}
return false
Expand Down
41 changes: 24 additions & 17 deletions tests/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1361,25 +1361,29 @@ func (suite *clientTestSuite) TestUpdateServiceGCSafePoint() {
}

func (suite *clientTestSuite) TestScatterRegion() {
regionID := regionIDAllocator.alloc()
region := &metapb.Region{
Id: regionID,
RegionEpoch: &metapb.RegionEpoch{
ConfVer: 1,
Version: 1,
},
Peers: peers,
StartKey: []byte("fff"),
EndKey: []byte("ggg"),
}
req := &pdpb.RegionHeartbeatRequest{
Header: newHeader(suite.srv),
Region: region,
Leader: peers[0],
CreateRegion := func() uint64 {
regionID := regionIDAllocator.alloc()
region := &metapb.Region{
Id: regionID,
RegionEpoch: &metapb.RegionEpoch{
ConfVer: 1,
Version: 1,
},
Peers: peers,
StartKey: []byte("fff"),
EndKey: []byte("ggg"),
}
req := &pdpb.RegionHeartbeatRequest{
Header: newHeader(suite.srv),
Region: region,
Leader: peers[0],
}
err := suite.regionHeartbeat.Send(req)
suite.NoError(err)
return regionID
}
err := suite.regionHeartbeat.Send(req)
var regionID = CreateRegion()
regionsID := []uint64{regionID}
suite.NoError(err)
// Test interface `ScatterRegions`.
re := suite.Require()
testutil.Eventually(re, func() bool {
Expand All @@ -1401,6 +1405,9 @@ func (suite *clientTestSuite) TestScatterRegion() {

// Test interface `ScatterRegion`.
// TODO: Deprecate interface `ScatterRegion`.
// create a new region as scatter operation from previous test might be running

regionID = CreateRegion()
testutil.Eventually(re, func() bool {
err := suite.client.ScatterRegion(context.Background(), regionID)
if err != nil {
Expand Down

0 comments on commit 0439df5

Please sign in to comment.