From 669ecbaa4b13471d5ce598dfc11151eef993f0a9 Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Thu, 11 Mar 2021 14:28:55 +0800 Subject: [PATCH] checker: prevent the regions in split-cache from becoming the target of merge (#3454) (#3458) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * cherry pick #3454 to release-3.0 Signed-off-by: ti-srebot * revert Signed-off-by: HunDunDM * pick Signed-off-by: HunDunDM Co-authored-by: 混沌DM Co-authored-by: Ti Chi Robot <71242396+ti-chi-bot@users.noreply.github.com> --- server/schedule/merge_checker.go | 2 +- server/schedule/merge_checker_test.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/server/schedule/merge_checker.go b/server/schedule/merge_checker.go index 827ce1e8ad4..78b57631a5b 100644 --- a/server/schedule/merge_checker.go +++ b/server/schedule/merge_checker.go @@ -125,7 +125,7 @@ func (m *MergeChecker) Check(region *core.RegionInfo) []*Operator { func (m *MergeChecker) checkTarget(region, adjacent, target *core.RegionInfo) *core.RegionInfo { // if is not hot region and under same namespace - if adjacent != nil && !m.cluster.IsRegionHot(adjacent.GetID()) && + if adjacent != nil && !m.splitCache.Exists(adjacent.GetID()) && !m.cluster.IsRegionHot(adjacent.GetID()) && m.classifier.AllowMerge(region, adjacent) && len(adjacent.GetDownPeers()) == 0 && len(adjacent.GetPendingPeers()) == 0 && len(adjacent.GetLearners()) == 0 { // if both region is not hot, prefer the one with smaller size diff --git a/server/schedule/merge_checker_test.go b/server/schedule/merge_checker_test.go index 15096e23a08..7e4463b75ee 100644 --- a/server/schedule/merge_checker_test.go +++ b/server/schedule/merge_checker_test.go @@ -98,8 +98,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), ), } @@ -148,6 +148,11 @@ func (s *testMergeCheckerSuite) TestBasic(c *C) { c.Assert(ops[1].RegionID(), Equals, s.regions[3].GetID()) // Skip recently split regions. + 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(s.regions[2].GetID()) ops = s.mc.Check(s.regions[2]) c.Assert(ops, IsNil)