Skip to content

Commit

Permalink
cluster: eliminate some duplicated code in processRegionHeartbeat (#5693
Browse files Browse the repository at this point in the history
)

ref #5648

Eliminate some duplicated code in `processRegionHeartbeat`.

Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato authored Nov 10, 2022
1 parent 91f1664 commit 80801a2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ var (
// DefaultMinResolvedTSPersistenceInterval is the default value of min resolved ts persistence interval.
// If interval in config is zero, it means not to persist resolved ts and check config with this DefaultMinResolvedTSPersistenceInterval
DefaultMinResolvedTSPersistenceInterval = config.DefaultMinResolvedTSPersistenceInterval
regionUpdateCacheEventCounter = regionEventCounter.WithLabelValues("update_cache")
regionUpdateKVEventCounter = regionEventCounter.WithLabelValues("update_kv")
)

// regionLabelGCInterval is the interval to run region-label's GC work.
Expand Down Expand Up @@ -795,14 +797,15 @@ func (c *RaftCluster) processRegionHeartbeat(region *core.RegionInfo) error {
}
c.coordinator.CheckTransferWitnessLeader(region)

hasRegionStats := c.regionStats != nil
// Save to storage if meta is updated.
// Save to cache if meta or leader is updated, or contains any down/pending peer.
// Mark isNew if the region in cache does not have leader.
isNew, saveKV, saveCache, needSync := regionGuide(region, origin)
if !saveKV && !saveCache && !isNew {
// Due to some config changes need to update the region stats as well,
// so we do some extra checks here.
if c.regionStats != nil && c.regionStats.RegionStatsNeedUpdate(region) {
if hasRegionStats && c.regionStats.RegionStatsNeedUpdate(region) {
c.regionStats.Observe(region, c.getRegionStoresLocked(region))
}
return nil
Expand Down Expand Up @@ -843,10 +846,10 @@ func (c *RaftCluster) processRegionHeartbeat(region *core.RegionInfo) error {
c.core.UpdateStoreStatus(key)
}

regionEventCounter.WithLabelValues("update_cache").Inc()
regionUpdateCacheEventCounter.Inc()
}

if c.regionStats != nil {
if hasRegionStats {
c.regionStats.Observe(region, c.getRegionStoresLocked(region))
}

Expand Down Expand Up @@ -874,7 +877,7 @@ func (c *RaftCluster) processRegionHeartbeat(region *core.RegionInfo) error {
logutil.ZapRedactStringer("region-meta", core.RegionToHexMeta(region.GetMeta())),
errs.ZapError(err))
}
regionEventCounter.WithLabelValues("update_kv").Inc()
regionUpdateKVEventCounter.Inc()
}
}

Expand Down

0 comments on commit 80801a2

Please sign in to comment.