Skip to content

Commit

Permalink
server: use old interface for scatter region (#4766)
Browse files Browse the repository at this point in the history
close #4763

server: use old interface for scatter region

Signed-off-by: nolouch <nolouch@gmail.com>
  • Loading branch information
nolouch authored Mar 28, 2022
1 parent 7baf94c commit 86e8d08
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1203,11 +1203,13 @@ func (s *GrpcServer) ScatterRegion(ctx context.Context, request *pdpb.ScatterReg
FinishedPercentage: uint64(percentage),
}, nil
}

region := rc.GetRegion(request.GetRegion().GetId())
// TODO: Deprecate it use `request.GetRegionsID`.
//nolint
region := rc.GetRegion(request.GetRegionId())
if region == nil {
if request.GetRegion() == nil {
return nil, errors.Errorf("region %d not found", request.GetRegion().GetId())
//nolint
return nil, errors.Errorf("region %d not found", request.GetRegionId())
}
region = core.NewRegionInfo(request.GetRegion(), request.GetLeader())
}
Expand Down
17 changes: 17 additions & 0 deletions tests/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ func (s *testClientSuite) TestScatterRegion(c *C) {
err := s.regionHeartbeat.Send(req)
regionsID := []uint64{regionID}
c.Assert(err, IsNil)
// Test interface `ScatterRegions`.
testutil.WaitUntil(c, func() bool {
scatterResp, err := s.client.ScatterRegions(context.Background(), regionsID, pd.WithGroup("test"), pd.WithRetry(1))
if c.Check(err, NotNil) {
Expand All @@ -1161,6 +1162,22 @@ func (s *testClientSuite) TestScatterRegion(c *C) {
}
return c.Check(resp.GetRegionId(), Equals, regionID) && c.Check(string(resp.GetDesc()), Equals, "scatter-region") && c.Check(resp.GetStatus(), Equals, pdpb.OperatorStatus_RUNNING)
}, testutil.WithSleepInterval(1*time.Second))

// Test interface `ScatterRegion`.
// TODO: Deprecate interface `ScatterRegion`.
testutil.WaitUntil(c, func() bool {
err := s.client.ScatterRegion(context.Background(), regionID)
if c.Check(err, NotNil) {
fmt.Println(err)
return false
}
resp, err := s.client.GetOperator(context.Background(), regionID)
if c.Check(err, NotNil) {
return false
}
return c.Check(resp.GetRegionId(), Equals, regionID) && c.Check(string(resp.GetDesc()), Equals, "scatter-region") && c.Check(resp.GetStatus(), Equals, pdpb.OperatorStatus_RUNNING)
}, testutil.WithSleepInterval(1*time.Second))

c.Succeed()
}

Expand Down

0 comments on commit 86e8d08

Please sign in to comment.