Skip to content

Commit

Permalink
server/schedule: fix invalid store id (tikv#5315)
Browse files Browse the repository at this point in the history
close tikv#5279

fix invalid store id

Signed-off-by: LLThomas <zs033@qq.com>

Co-authored-by: 混沌DM <hundundm@gmail.com>
  • Loading branch information
LLThomas and HunDunDM authored Jul 26, 2022
1 parent e339c83 commit 59e5008
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions server/schedule/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ func (oc *OperatorController) addOperatorLocked(op *operator.Operator) bool {
for storeID := range opInfluence.StoresInfluence {
store := oc.cluster.GetStore(storeID)
if store == nil {
log.Error("invalid store ID", zap.Uint64("store-id", storeID))
return false
log.Info("missing store", zap.Uint64("store-id", storeID))
continue
}
for n, v := range storelimit.TypeNameValue {
storeLimit := store.GetStoreLimit(v)
Expand Down
20 changes: 20 additions & 0 deletions server/schedule/operator_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,3 +780,23 @@ func (suite *operatorControllerTestSuite) TestAddWaitingOperator() {
// no space left, new operator can not be added.
suite.Equal(0, controller.AddWaitingOperator(addPeerOp(0)))
}

// issue #5279
func (suite *operatorControllerTestSuite) TestInvalidStoreId() {
opt := config.NewTestOptions()
tc := mockcluster.NewCluster(suite.ctx, opt)
stream := hbstream.NewTestHeartbeatStreams(suite.ctx, tc.ID, tc, false /* no need to run */)
oc := NewOperatorController(suite.ctx, tc, stream)
// If PD and store 3 are gone, PD will not have info of store 3 after recreating it.
tc.AddRegionStore(1, 1)
tc.AddRegionStore(2, 1)
tc.AddRegionStore(4, 1)
tc.AddLeaderRegionWithRange(1, "", "", 1, 2, 3, 4)
steps := []operator.OpStep{
operator.RemovePeer{FromStore: 3, PeerID: 3, IsDownStore: false},
}
op := operator.NewTestOperator(1, &metapb.RegionEpoch{}, operator.OpRegion, steps...)
suite.True(oc.addOperatorLocked(op))
// Although store 3 does not exist in PD, PD can also send op to TiKV.
suite.Equal(pdpb.OperatorStatus_RUNNING, oc.GetOperatorStatus(1).Status)
}

0 comments on commit 59e5008

Please sign in to comment.