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

checker: prevent the regions in split-cache from becoming the target of merge #3454

Merged
merged 3 commits into from
Mar 10, 2021
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
5 changes: 3 additions & 2 deletions server/schedule/checker/merge_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,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 @@ -122,8 +122,8 @@ func (s *testMergeCheckerSuite) SetUpTest(c *C) {
},
},
&metapb.Peer{Id: 109, StoreId: 4},
core.SetApproximateSize(10),
core.SetApproximateKeys(10),
core.SetApproximateSize(1),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, the original value 10 is greater than threshold 2, which causes the region to be unable to be merged.

core.SetApproximateKeys(1),
),
}

Expand Down Expand Up @@ -191,10 +191,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")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rule was not deleted correctly here, which caused the subsequent test to be invalid.


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

s.mc.startTime = time.Now().Add(-2 * time.Hour)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original test did not modify the startTime. Due to the following code logic, all regions cannot be merged.

	expireTime := m.startTime.Add(m.opts.GetSplitMergeInterval())
	if time.Now().Before(expireTime) {
		checkerCounter.WithLabelValues("merge_checker", "recently-start").Inc()
		return nil
	}

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