From 473c85d110069d45912ed4f52a0ce0a44ef3fd67 Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Tue, 16 Jul 2024 21:38:58 +0800 Subject: [PATCH 1/3] schedule: fix split-merge-interval update Signed-off-by: lhy1024 --- pkg/schedule/checker/merge_checker.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/schedule/checker/merge_checker.go b/pkg/schedule/checker/merge_checker.go index d7a28ad0ff8..7adbf9ea0eb 100644 --- a/pkg/schedule/checker/merge_checker.go +++ b/pkg/schedule/checker/merge_checker.go @@ -88,13 +88,14 @@ func (m *MergeChecker) Check(region *core.RegionInfo) []*operator.Operator { return nil } + m.splitCache.UpdateTTL(m.conf.GetSplitMergeInterval()) + expireTime := m.startTime.Add(m.conf.GetSplitMergeInterval()) if time.Now().Before(expireTime) { mergeCheckerRecentlyStartCounter.Inc() return nil } - m.splitCache.UpdateTTL(m.conf.GetSplitMergeInterval()) if m.splitCache.Exists(region.GetID()) { mergeCheckerRecentlySplitCounter.Inc() return nil From b4a11a5775731b469288e017f5be21e7381cd992 Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Tue, 16 Jul 2024 22:12:22 +0800 Subject: [PATCH 2/3] add unit test Signed-off-by: lhy1024 --- pkg/schedule/checker/merge_checker.go | 6 +++++- pkg/schedule/checker/merge_checker_test.go | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/schedule/checker/merge_checker.go b/pkg/schedule/checker/merge_checker.go index 7adbf9ea0eb..1a7548a1084 100644 --- a/pkg/schedule/checker/merge_checker.go +++ b/pkg/schedule/checker/merge_checker.go @@ -46,6 +46,8 @@ const ( mergeOptionValueDeny = "deny" ) +var gcInterval = time.Minute + // MergeChecker ensures region to merge with adjacent region when size is small type MergeChecker struct { PauseController @@ -57,7 +59,7 @@ type MergeChecker struct { // NewMergeChecker creates a merge checker. func NewMergeChecker(ctx context.Context, cluster sche.CheckerCluster, conf config.CheckerConfigProvider) *MergeChecker { - splitCache := cache.NewIDTTL(ctx, time.Minute, conf.GetSplitMergeInterval()) + splitCache := cache.NewIDTTL(ctx, gcInterval, conf.GetSplitMergeInterval()) return &MergeChecker{ cluster: cluster, conf: conf, @@ -88,6 +90,8 @@ func (m *MergeChecker) Check(region *core.RegionInfo) []*operator.Operator { return nil } + // update the split cache. + // It must be called before the following merge checker logic. m.splitCache.UpdateTTL(m.conf.GetSplitMergeInterval()) expireTime := m.startTime.Add(m.conf.GetSplitMergeInterval()) diff --git a/pkg/schedule/checker/merge_checker_test.go b/pkg/schedule/checker/merge_checker_test.go index 06e8d468de3..844e09fcdf4 100644 --- a/pkg/schedule/checker/merge_checker_test.go +++ b/pkg/schedule/checker/merge_checker_test.go @@ -56,6 +56,7 @@ func TestMergeCheckerTestSuite(t *testing.T) { func (suite *mergeCheckerTestSuite) SetupTest() { cfg := mockconfig.NewTestOptions() + gcInterval = 100 * time.Millisecond suite.ctx, suite.cancel = context.WithCancel(context.Background()) suite.cluster = mockcluster.NewCluster(suite.ctx, cfg) suite.cluster.SetMaxMergeRegionSize(2) @@ -234,6 +235,7 @@ func (suite *mergeCheckerTestSuite) TestBasic() { ops = suite.mc.Check(suite.regions[3]) re.Nil(ops) + // issue #4616 suite.cluster.SetSplitMergeInterval(500 * time.Millisecond) ops = suite.mc.Check(suite.regions[2]) re.Nil(ops) @@ -245,6 +247,19 @@ func (suite *mergeCheckerTestSuite) TestBasic() { re.NotNil(ops) ops = suite.mc.Check(suite.regions[3]) re.NotNil(ops) + + // issue #8405 + suite.mc.startTime = time.Now() + suite.cluster.SetSplitMergeInterval(time.Second) + suite.cluster.SetSplitMergeInterval(time.Hour) + suite.mc.RecordRegionSplit([]uint64{suite.regions[2].GetID()}) + suite.cluster.SetSplitMergeInterval(time.Second) + suite.mc.Check(suite.regions[2]) // trigger the config update + time.Sleep(time.Second) // wait for the cache to gc + ops = suite.mc.Check(suite.regions[2]) + re.NotNil(ops) + ops = suite.mc.Check(suite.regions[3]) + re.NotNil(ops) } func (suite *mergeCheckerTestSuite) TestMatchPeers() { From d5d77564cee706965313d183dce59b1f44937912 Mon Sep 17 00:00:00 2001 From: lhy1024 Date: Wed, 17 Jul 2024 11:35:42 +0800 Subject: [PATCH 3/3] address comments Signed-off-by: lhy1024 --- pkg/schedule/checker/merge_checker_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/schedule/checker/merge_checker_test.go b/pkg/schedule/checker/merge_checker_test.go index 844e09fcdf4..61b8cd579df 100644 --- a/pkg/schedule/checker/merge_checker_test.go +++ b/pkg/schedule/checker/merge_checker_test.go @@ -85,6 +85,7 @@ func (suite *mergeCheckerTestSuite) SetupTest() { } func (suite *mergeCheckerTestSuite) TearDownTest() { + gcInterval = time.Minute suite.cancel() }