Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

operator: fix the AddLearner config version judgment #1732

Merged
merged 1 commit into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/schedule/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ type AddLearner struct {

// ConfVerChanged returns true if the conf version has been changed by this step
func (al AddLearner) ConfVerChanged(region *core.RegionInfo) bool {
if p := region.GetStoreLearner(al.ToStore); p != nil {
if p := region.GetStorePeer(al.ToStore); p != nil {
return p.GetId() == al.PeerID
}
return false
Expand Down
43 changes: 38 additions & 5 deletions server/schedule/operator_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ func (t *testOperatorControllerSuite) TestDispatchUnfinishedStep(c *C) {
// The next allocated peer should have peerid 3, so we add this peer
// to store 3
steps := []operator.OpStep{
operator.AddPeer{3, 3},
operator.AddLearner{ToStore: 3, PeerID: 3},
operator.PromoteLearner{ToStore: 3, PeerID: 3},
operator.TransferLeader{ToStore: 3},
operator.RemovePeer{FromStore: 1},
}

// Create an operator
Expand All @@ -266,9 +269,9 @@ func (t *testOperatorControllerSuite) TestDispatchUnfinishedStep(c *C) {
// region2 has peer 3 in pending state, so the AddPeer step
// is left unfinished
region2 := region.Clone(
core.WithAddPeer(&metapb.Peer{Id: 3, StoreId: 3}),
core.WithAddPeer(&metapb.Peer{Id: 3, StoreId: 3, IsLearner: true}),
core.WithPendingPeers([]*metapb.Peer{
{Id: 3, StoreId: 3, IsLearner: false},
{Id: 3, StoreId: 3, IsLearner: true},
}),
core.WithIncConfVer(),
)
Expand All @@ -288,12 +291,42 @@ func (t *testOperatorControllerSuite) TestDispatchUnfinishedStep(c *C) {

// Finish the step by clearing the pending state
region3 := region.Clone(
core.WithAddPeer(&metapb.Peer{Id: 3, StoreId: 3}),
core.WithAddPeer(&metapb.Peer{Id: 3, StoreId: 3, IsLearner: true}),
core.WithIncConfVer(),
)
c.Assert(steps[0].IsFinish(region3), Equals, true)
controller.Dispatch(region3, DispatchFromHeartBeat)
c.Assert(op.ConfVerChanged(region3), Equals, 1)
c.Assert(len(stream.MsgCh()), Equals, 2)

region4 := region3.Clone(
core.WithPromoteLearner(3),
core.WithIncConfVer(),
)
c.Assert(steps[1].IsFinish(region4), Equals, true)
controller.Dispatch(region4, DispatchFromHeartBeat)
c.Assert(op.ConfVerChanged(region4), Equals, 2)
c.Assert(len(stream.MsgCh()), Equals, 3)

// Transfer leader
region5 := region4.Clone(
core.WithLeader(region4.GetStorePeer(3)),
)
c.Assert(steps[2].IsFinish(region5), Equals, true)
controller.Dispatch(region5, DispatchFromHeartBeat)
c.Assert(op.ConfVerChanged(region5), Equals, 2)
c.Assert(len(stream.MsgCh()), Equals, 4)

// Remove peer
region6 := region5.Clone(
core.WithRemoveStorePeer(1),
core.WithIncConfVer(),
)
c.Assert(steps[3].IsFinish(region6), Equals, true)
controller.Dispatch(region6, DispatchFromHeartBeat)
c.Assert(op.ConfVerChanged(region6), Equals, 3)

// The Operator has finished, so no message should be sent
c.Assert(len(stream.MsgCh()), Equals, 1)
c.Assert(len(stream.MsgCh()), Equals, 4)
c.Assert(controller.GetOperator(1), IsNil)
}