From e7ea0c93eb4ff0b13966dc227b08adae467cf390 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Sun, 25 Jun 2023 17:55:20 +0800 Subject: [PATCH] checker: fix the conflict between tiflash learner and location labels (#6671) --- server/schedule/checker/rule_checker.go | 5 +-- server/schedule/checker/rule_checker_test.go | 32 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/server/schedule/checker/rule_checker.go b/server/schedule/checker/rule_checker.go index 26b2983215e..7f9a24d4183 100644 --- a/server/schedule/checker/rule_checker.go +++ b/server/schedule/checker/rule_checker.go @@ -366,12 +366,13 @@ func (c *RuleChecker) fixBetterLocation(region *core.RegionInfo, rf *placement.R } strategy := c.strategy(region, rf.Rule) - regionStores := c.cluster.GetRegionStores(region) - oldStore := strategy.SelectStoreToRemove(regionStores) + ruleStores := c.getRuleFitStores(rf) + oldStore := strategy.SelectStoreToRemove(ruleStores) if oldStore == 0 { return nil, nil } var coLocationStores []*core.StoreInfo + regionStores := c.cluster.GetRegionStores(region) for _, s := range regionStores { if placement.MatchLabelConstraints(s, rf.Rule.LabelConstraints) { coLocationStores = append(coLocationStores, s) diff --git a/server/schedule/checker/rule_checker_test.go b/server/schedule/checker/rule_checker_test.go index ce7cea1cc36..101eba12354 100644 --- a/server/schedule/checker/rule_checker_test.go +++ b/server/schedule/checker/rule_checker_test.go @@ -1355,3 +1355,35 @@ func (suite *ruleCheckerTestSuite) TestLocationLabels() { suite.NotNil(op) suite.Equal("move-to-better-location", op.Desc()) } + +func (suite *ruleCheckerTestSuite) TestTiFlashLocationLabels() { + suite.cluster.SetEnableUseJointConsensus(true) + suite.cluster.AddLabelsStore(1, 1, map[string]string{"zone": "z1", "rack": "r1", "host": "h1"}) + suite.cluster.AddLabelsStore(2, 1, map[string]string{"zone": "z1", "rack": "r1", "host": "h1"}) + suite.cluster.AddLabelsStore(3, 1, map[string]string{"zone": "z1", "rack": "r2", "host": "h1"}) + suite.cluster.AddLabelsStore(4, 1, map[string]string{"zone": "z1", "rack": "r2", "host": "h1"}) + suite.cluster.AddLabelsStore(5, 1, map[string]string{"zone": "z2", "rack": "r3", "host": "h2"}) + suite.cluster.AddLabelsStore(6, 1, map[string]string{"zone": "z2", "rack": "r3", "host": "h2"}) + suite.cluster.AddLabelsStore(7, 1, map[string]string{"engine": "tiflash"}) + suite.cluster.AddRegionWithLearner(1, 1, []uint64{3, 5}, []uint64{7}) + + rule1 := &placement.Rule{ + GroupID: "tiflash", + ID: "test1", + Role: placement.Learner, + Count: 1, + LabelConstraints: []placement.LabelConstraint{ + { + Key: "engine", + Op: placement.In, + Values: []string{"tiflash"}, + }, + }, + } + suite.ruleManager.SetRule(rule1) + rule := suite.ruleManager.GetRule("pd", "default") + rule.LocationLabels = []string{"zone", "rack", "host"} + suite.ruleManager.SetRule(rule) + op := suite.rc.Check(suite.cluster.GetRegion(1)) + suite.Nil(op) +}