From 54e8fc1190d35a5dc0bdd5e91e7c0386c3510785 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Mon, 16 May 2022 16:53:29 +0800 Subject: [PATCH] address the comment Signed-off-by: Ryan Leung --- server/cluster/cluster.go | 8 ++++---- server/cluster/prepare_checker.go | 4 ++-- tests/server/region_syncer/region_syncer_test.go | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index e7da4843a7e..2d5bb7b04e8 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -747,9 +747,9 @@ func (c *RaftCluster) processReportBuckets(buckets *metapb.Buckets) error { return nil } -// IsPrepared return true if the prepare checker is ready. -func (c *RaftCluster) IsPrepared() bool { - return c.coordinator.prepareChecker.isPrepared() +// NeedCollect return true if need to collect regions +func (c *RaftCluster) NeedCollect() bool { + return c.coordinator.prepareChecker.needCollect() } var regionGuide = core.GenerateRegionGuideFunc(true) @@ -818,7 +818,7 @@ func (c *RaftCluster) processRegionHeartbeat(region *core.RegionInfo) error { regionEventCounter.WithLabelValues("update_cache").Inc() } - if !c.IsPrepared() && isNew { + if c.NeedCollect() && isNew { c.coordinator.prepareChecker.collect(region) } diff --git a/server/cluster/prepare_checker.go b/server/cluster/prepare_checker.go index f391386b097..be1102d386d 100644 --- a/server/cluster/prepare_checker.go +++ b/server/cluster/prepare_checker.go @@ -70,8 +70,8 @@ func (checker *prepareChecker) collect(region *core.RegionInfo) { checker.sum++ } -func (checker *prepareChecker) isPrepared() bool { +func (checker *prepareChecker) needCollect() bool { checker.RLock() defer checker.RUnlock() - return checker.prepared + return time.Since(checker.start) <= collectTimeout && !checker.prepared } diff --git a/tests/server/region_syncer/region_syncer_test.go b/tests/server/region_syncer/region_syncer_test.go index dd7dc1fb5f1..ad8bbdd99bf 100644 --- a/tests/server/region_syncer/region_syncer_test.go +++ b/tests/server/region_syncer/region_syncer_test.go @@ -233,7 +233,7 @@ func (s *regionSyncerTestSuite) TestPrepareChecker(c *C) { // ensure flush to region storage time.Sleep(3 * time.Second) - c.Assert(leaderServer.GetRaftCluster().IsPrepared(), IsTrue) + c.Assert(leaderServer.GetRaftCluster().NeedCollect(), IsFalse) // join new PD pd2, err := cluster.Join(s.ctx) @@ -252,7 +252,7 @@ func (s *regionSyncerTestSuite) TestPrepareChecker(c *C) { c.Assert(err, IsNil) } time.Sleep(time.Second) - c.Assert(rc.IsPrepared(), IsTrue) + c.Assert(rc.NeedCollect(), IsFalse) } func initRegions(regionLen int) []*core.RegionInfo {