Skip to content

Commit

Permalink
checker: prevent the regions in split-cache from becoming the target …
Browse files Browse the repository at this point in the history
…of merge (#3454) (#3459)

* cherry pick #3454 to release-4.0

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>

* fix

Signed-off-by: HunDunDM <hundundm@gmail.com>

Co-authored-by: 混沌DM <hundundm@gmail.com>
  • Loading branch information
ti-srebot and HunDunDM authored Mar 10, 2021
1 parent d715185 commit ff6c0d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 3 additions & 2 deletions server/schedule/checker/merge_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ func (m *MergeChecker) Check(region *core.RegionInfo) []*operator.Operator {
}

func (m *MergeChecker) checkTarget(region, adjacent *core.RegionInfo) bool {
return adjacent != nil && !m.cluster.IsRegionHot(adjacent) && AllowMerge(m.cluster, region, adjacent) &&
opt.IsRegionHealthy(m.cluster, adjacent) && opt.IsRegionReplicated(m.cluster, adjacent)
return adjacent != nil && !m.splitCache.Exists(adjacent.GetID()) && !m.cluster.IsRegionHot(adjacent) &&
AllowMerge(m.cluster, region, adjacent) && opt.IsRegionHealthy(m.cluster, adjacent) &&
opt.IsRegionReplicated(m.cluster, adjacent)
}

// AllowMerge returns true if two regions can be merged according to the key type.
Expand Down
15 changes: 12 additions & 3 deletions server/schedule/checker/merge_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ func (s *testMergeCheckerSuite) SetUpTest(c *C) {
},
},
&metapb.Peer{Id: 109, StoreId: 4},
core.SetApproximateSize(10),
core.SetApproximateKeys(10),
core.SetApproximateSize(1),
core.SetApproximateKeys(1),
),
}

Expand Down Expand Up @@ -189,10 +189,19 @@ func (s *testMergeCheckerSuite) TestBasic(c *C) {
c.Assert(ops, NotNil)
c.Assert(ops[0].RegionID(), Equals, s.regions[2].GetID())
c.Assert(ops[1].RegionID(), Equals, s.regions[1].GetID())
s.cluster.RuleManager.DeleteRule("test", "test")
s.cluster.RuleManager.DeleteRule("pd", "test")

// Skip recently split regions.
s.cluster.ScheduleOptions.SplitMergeInterval = time.Hour
ops = s.mc.Check(s.regions[2])
c.Assert(ops, IsNil)

s.mc.startTime = time.Now().Add(-2 * time.Hour)
ops = s.mc.Check(s.regions[2])
c.Assert(ops, NotNil)
ops = s.mc.Check(s.regions[3])
c.Assert(ops, NotNil)

s.mc.RecordRegionSplit([]uint64{s.regions[2].GetID()})
ops = s.mc.Check(s.regions[2])
c.Assert(ops, IsNil)
Expand Down

0 comments on commit ff6c0d2

Please sign in to comment.