Skip to content

Commit

Permalink
address the comment
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed May 16, 2022
1 parent bf2b5e0 commit 54e8fc1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions server/cluster/prepare_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions tests/server/region_syncer/region_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 54e8fc1

Please sign in to comment.