Skip to content

Commit

Permalink
schedule: Fix possible nil pointer when getting command (#5542) (#5547)
Browse files Browse the repository at this point in the history
close #5540, ref #5542

Fix possible nil pointer when getting command

Signed-off-by: Connor1996 <zbk602423539@gmail.com>

Co-authored-by: Connor1996 <zbk602423539@gmail.com>
  • Loading branch information
ti-chi-bot and Connor1996 authored Sep 22, 2022
1 parent 3cc8251 commit d4fb1a1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
12 changes: 2 additions & 10 deletions server/schedule/operator/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,7 @@ func (pl PromoteLearner) Timeout(start time.Time, regionSize int64) bool {
}

// GetCmd returns the schedule command for heartbeat response.
func (pl PromoteLearner) GetCmd(region *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse {
peer := region.GetStorePeer(pl.ToStore)
if peer == nil {
return nil
}
func (pl PromoteLearner) GetCmd(_ *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse {
return createResponse(addNode(pl.PeerID, pl.ToStore), useConfChangeV2)
}

Expand Down Expand Up @@ -537,11 +533,7 @@ func (dv DemoteVoter) Timeout(start time.Time, regionSize int64) bool {
}

// GetCmd returns the schedule command for heartbeat response.
func (dv DemoteVoter) GetCmd(region *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse {
peer := region.GetStorePeer(dv.ToStore)
if peer == nil {
return nil
}
func (dv DemoteVoter) GetCmd(_ *core.RegionInfo, useConfChangeV2 bool) *pdpb.RegionHeartbeatResponse {
return createResponse(addLearnerNode(dv.PeerID, dv.ToStore), useConfChangeV2)
}

Expand Down
1 change: 1 addition & 0 deletions server/schedule/operator/step_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,6 @@ func (suite *operatorStepTestSuite) check(step OpStep, desc string, testCases []
suite.Equal(testCase.IsFinish, step.IsFinish(region))
err := step.CheckInProgress(suite.cluster, region)
testCase.CheckInProgress(err)
_ = step.GetCmd(region, true)
}
}

0 comments on commit d4fb1a1

Please sign in to comment.