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: rewrite move region related functions #1667

Merged
merged 32 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
34d0d58
rewrite CreateMoveRegionOperator and matchPeerSteps
Luffbee Aug 6, 2019
3b9e828
add label check for MoveRegion and matchPeer
Luffbee Aug 6, 2019
7e029a7
fix misspelling
Luffbee Aug 6, 2019
58ebbab
fix kind handling
Luffbee Aug 6, 2019
b37faff
update moveRegionSteps
Luffbee Aug 7, 2019
337dc30
fix text
Luffbee Aug 7, 2019
70cd43e
add test for reject leader label
Luffbee Aug 7, 2019
b16fd81
reorder steps of orderedMoveRegionSteps according to comment
Luffbee Aug 7, 2019
0920e49
address comments
Luffbee Aug 7, 2019
b739656
improve comments
Luffbee Aug 7, 2019
b073942
change parseStoreIDs back to map
Luffbee Aug 8, 2019
b7753bb
Merge branch 'master' into rewrite-move-region
Luffbee Aug 8, 2019
a257544
Update server/schedule/operator/operator.go
Luffbee Aug 9, 2019
5a0c970
Update server/schedule/operator/operator.go
Luffbee Aug 9, 2019
d0df4e5
address log
Luffbee Aug 9, 2019
402b582
Merge branch 'master' into rewrite-move-region
Luffbee Aug 9, 2019
3756ba2
add test for findNoLabelProperty
Luffbee Aug 9, 2019
8ec469f
Merge branch 'rewrite-move-region' of https://github.com/Luffbee/pd i…
Luffbee Aug 9, 2019
ca7d1ef
add a comment
Luffbee Aug 12, 2019
c9d9db0
add func interleaveStepGroups
Luffbee Aug 12, 2019
a9ead58
fix comment; add test
Luffbee Aug 12, 2019
eade3d2
Merge branch 'master' into rewrite-move-region
Luffbee Aug 13, 2019
3e0377b
format comments; rename
Luffbee Aug 16, 2019
1287ab8
rename
Luffbee Aug 16, 2019
c0d2c3c
go fmt
Luffbee Aug 16, 2019
c0ba889
Merge branch 'master' into rewrite-move-region
Luffbee Aug 16, 2019
d6316bf
Merge branch 'master' into rewrite-move-region
Luffbee Aug 19, 2019
645ccfb
Merge branch 'rewrite-move-region' of https://github.com/Luffbee/pd i…
Luffbee Aug 19, 2019
c6e20da
Merge branch 'master' into rewrite-move-region
Luffbee Aug 19, 2019
700a70a
fix comment
Luffbee Aug 20, 2019
cb9a3d1
Merge branch 'master' into rewrite-move-region
Luffbee Aug 21, 2019
adab5e8
Merge branch 'master' into rewrite-move-region
Luffbee Aug 21, 2019
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
1 change: 1 addition & 0 deletions server/checker/merge_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (m *MergeChecker) Check(region *core.RegionInfo) []*operator.Operator {
log.Debug("try to merge region", zap.Stringer("from", core.RegionToHexMeta(region.GetMeta())), zap.Stringer("to", core.RegionToHexMeta(target.GetMeta())))
ops, err := operator.CreateMergeRegionOperator("merge-region", m.cluster, region, target, operator.OpMerge)
if err != nil {
log.Warn("create merge region operator failed", zap.Error(err))
return nil
}
checkerCounter.WithLabelValues("merge_checker", "new_operator").Inc()
Expand Down
128 changes: 119 additions & 9 deletions server/checker/merge_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pingcap/pd/server/namespace"
"github.com/pingcap/pd/server/schedule"
"github.com/pingcap/pd/server/schedule/operator"
"github.com/pingcap/pd/server/schedule/opt"
)

func TestChecker(t *testing.T) {
Expand All @@ -44,7 +45,18 @@ func (s *testMergeCheckerSuite) SetUpTest(c *C) {
cfg := mockoption.NewScheduleOptions()
cfg.MaxMergeRegionSize = 2
cfg.MaxMergeRegionKeys = 2
cfg.LabelProperties = map[string][]*metapb.StoreLabel{
opt.RejectLeader: {{Key: "reject", Value: "leader"}},
}
s.cluster = mockcluster.NewCluster(cfg)
stores := map[uint64][]string{
1: {}, 2: {}, 3: {}, 4: {}, 5: {}, 6: {},
7: {"reject", "leader"},
8: {"reject", "leader"},
}
for storeID, labels := range stores {
s.cluster.PutStoreWithLabels(storeID, labels...)
}
s.regions = []*core.RegionInfo{
core.NewRegionInfo(
&metapb.Region{
Expand Down Expand Up @@ -157,14 +169,19 @@ func (s *testMergeCheckerSuite) checkSteps(c *C, op *operator.Operator, steps []
func (s *testMergeCheckerSuite) TestMatchPeers(c *C) {
// partial store overlap not including leader
ops := s.mc.Check(s.regions[2])
c.Assert(ops, NotNil)
s.checkSteps(c, ops[0], []operator.OpStep{
operator.TransferLeader{FromStore: 6, ToStore: 5},
operator.AddLearner{ToStore: 1, PeerID: 1},
operator.PromoteLearner{ToStore: 1, PeerID: 1},
operator.AddLearner{ToStore: 4, PeerID: 1},
operator.PromoteLearner{ToStore: 4, PeerID: 1},

operator.RemovePeer{FromStore: 2},
operator.AddLearner{ToStore: 4, PeerID: 2},
operator.PromoteLearner{ToStore: 4, PeerID: 2},

operator.AddLearner{ToStore: 1, PeerID: 2},
operator.PromoteLearner{ToStore: 1, PeerID: 2},

operator.TransferLeader{FromStore: 6, ToStore: 5},
operator.RemovePeer{FromStore: 6},

operator.MergeRegion{
FromRegion: s.regions[2].GetMeta(),
ToRegion: s.regions[1].GetMeta(),
Expand Down Expand Up @@ -241,16 +258,109 @@ func (s *testMergeCheckerSuite) TestMatchPeers(c *C) {
s.cluster.PutRegion(s.regions[2])
ops = s.mc.Check(s.regions[2])
s.checkSteps(c, ops[0], []operator.OpStep{
operator.AddLearner{ToStore: 1, PeerID: 4},
operator.PromoteLearner{ToStore: 1, PeerID: 4},
operator.AddLearner{ToStore: 4, PeerID: 4},
operator.PromoteLearner{ToStore: 4, PeerID: 4},

operator.RemovePeer{FromStore: 3},
operator.AddLearner{ToStore: 4, PeerID: 5},
operator.PromoteLearner{ToStore: 4, PeerID: 5},

operator.AddLearner{ToStore: 1, PeerID: 5},
operator.PromoteLearner{ToStore: 1, PeerID: 5},

operator.RemovePeer{FromStore: 6},

operator.AddLearner{ToStore: 5, PeerID: 6},
operator.PromoteLearner{ToStore: 5, PeerID: 6},

operator.TransferLeader{FromStore: 2, ToStore: 4},
operator.RemovePeer{FromStore: 2},

operator.MergeRegion{
FromRegion: s.regions[2].GetMeta(),
ToRegion: s.regions[1].GetMeta(),
IsPassive: false,
},
})
s.checkSteps(c, ops[1], []operator.OpStep{
operator.MergeRegion{
FromRegion: s.regions[2].GetMeta(),
ToRegion: s.regions[1].GetMeta(),
IsPassive: true,
},
})

// no overlap with reject leader label
s.regions[1] = s.regions[1].Clone(
core.SetPeers([]*metapb.Peer{
{Id: 112, StoreId: 7},
{Id: 113, StoreId: 8},
{Id: 114, StoreId: 1},
}),
core.WithLeader(&metapb.Peer{Id: 114, StoreId: 1}),
)
s.cluster.PutRegion(s.regions[1])
ops = s.mc.Check(s.regions[2])
s.checkSteps(c, ops[0], []operator.OpStep{
operator.AddLearner{ToStore: 1, PeerID: 7},
operator.PromoteLearner{ToStore: 1, PeerID: 7},

operator.RemovePeer{FromStore: 3},

operator.AddLearner{ToStore: 7, PeerID: 8},
operator.PromoteLearner{ToStore: 7, PeerID: 8},

operator.RemovePeer{FromStore: 6},

operator.AddLearner{ToStore: 8, PeerID: 9},
operator.PromoteLearner{ToStore: 8, PeerID: 9},

operator.TransferLeader{FromStore: 2, ToStore: 1},
operator.RemovePeer{FromStore: 2},

operator.MergeRegion{
FromRegion: s.regions[2].GetMeta(),
ToRegion: s.regions[1].GetMeta(),
IsPassive: false,
},
})
s.checkSteps(c, ops[1], []operator.OpStep{
operator.MergeRegion{
FromRegion: s.regions[2].GetMeta(),
ToRegion: s.regions[1].GetMeta(),
IsPassive: true,
},
})

// overlap with reject leader label
s.regions[1] = s.regions[1].Clone(
core.SetPeers([]*metapb.Peer{
{Id: 115, StoreId: 7},
{Id: 116, StoreId: 8},
{Id: 117, StoreId: 1},
}),
core.WithLeader(&metapb.Peer{Id: 117, StoreId: 1}),
)
s.regions[2] = s.regions[2].Clone(
core.SetPeers([]*metapb.Peer{
{Id: 118, StoreId: 7},
{Id: 119, StoreId: 3},
{Id: 120, StoreId: 2},
}),
core.WithLeader(&metapb.Peer{Id: 120, StoreId: 2}),
)
s.cluster.PutRegion(s.regions[1])
ops = s.mc.Check(s.regions[2])
s.checkSteps(c, ops[0], []operator.OpStep{
operator.AddLearner{ToStore: 1, PeerID: 10},
operator.PromoteLearner{ToStore: 1, PeerID: 10},

operator.RemovePeer{FromStore: 3},

operator.AddLearner{ToStore: 8, PeerID: 11},
operator.PromoteLearner{ToStore: 8, PeerID: 11},

operator.TransferLeader{FromStore: 2, ToStore: 1},
operator.RemovePeer{FromStore: 2},

operator.MergeRegion{
FromRegion: s.regions[2].GetMeta(),
ToRegion: s.regions[1].GetMeta(),
Expand Down
Loading