From a7fe3bcf346566a55cad60a43a4834ba9b723b57 Mon Sep 17 00:00:00 2001 From: okJiang <819421878@qq.com> Date: Thu, 19 Dec 2024 14:48:51 +0800 Subject: [PATCH] add StaleRegionFromPDCounter Signed-off-by: okJiang <819421878@qq.com> --- internal/locate/region_cache.go | 1 + internal/locate/sorted_btree.go | 2 ++ metrics/metrics.go | 10 ++++++++++ 3 files changed, 13 insertions(+) diff --git a/internal/locate/region_cache.go b/internal/locate/region_cache.go index c70e137a4..6e733c888 100644 --- a/internal/locate/region_cache.go +++ b/internal/locate/region_cache.go @@ -1902,6 +1902,7 @@ func (mu *regionIndexMu) insertRegionToCache(cachedRegion *Region, invalidateOld // and there is the synchronization time between the pd follower and the leader. // So we should check the epoch. if ok && (oldVer.GetVer() > newVer.GetVer() || oldVer.GetConfVer() > newVer.GetConfVer()) { + metrics.StaleRegionFromPDCounter.Inc() logutil.BgLogger().Debug("get stale region", zap.Uint64("region", newVer.GetID()), zap.Uint64("new-ver", newVer.GetVer()), zap.Uint64("new-conf", newVer.GetConfVer()), zap.Uint64("old-ver", oldVer.GetVer()), zap.Uint64("old-conf", oldVer.GetConfVer())) diff --git a/internal/locate/sorted_btree.go b/internal/locate/sorted_btree.go index ea233cc3c..020335ef3 100644 --- a/internal/locate/sorted_btree.go +++ b/internal/locate/sorted_btree.go @@ -40,6 +40,7 @@ import ( "github.com/google/btree" "github.com/tikv/client-go/v2/internal/logutil" + "github.com/tikv/client-go/v2/metrics" "go.uber.org/zap" ) @@ -112,6 +113,7 @@ func (s *SortedRegions) removeIntersecting(r *Region, verID RegionVerID) ([]*btr return false } if item.cachedRegion.meta.GetRegionEpoch().GetVersion() > verID.ver { + metrics.StaleRegionFromPDCounter.Inc() logutil.BgLogger().Debug("get stale region", zap.Uint64("region", verID.GetID()), zap.Uint64("ver", verID.GetVer()), zap.Uint64("conf", verID.GetConfVer()), zap.Uint64("intersecting-ver", item.cachedRegion.meta.GetRegionEpoch().GetVersion())) diff --git a/metrics/metrics.go b/metrics/metrics.go index ce247600c..400403522 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -117,6 +117,7 @@ var ( TiKVPipelinedFlushDuration prometheus.Histogram TiKVValidateReadTSFromPDCount prometheus.Counter TiKVLowResolutionTSOUpdateIntervalSecondsGauge prometheus.Gauge + StaleRegionFromPDCounter prometheus.Counter ) // Label constants. @@ -852,6 +853,14 @@ func initMetrics(namespace, subsystem string, constLabels prometheus.Labels) { Help: "The actual working update interval for the low resolution TSO. As there are adaptive mechanism internally, this value may differ from the config.", }) + StaleRegionFromPDCounter = prometheus.NewCounter( + prometheus.CounterOpts{ + Namespace: namespace, + Subsystem: subsystem, + Name: "stale_region_from_pd", + Help: "Counter of stale region from PD", + }) + initShortcuts() } @@ -948,6 +957,7 @@ func RegisterMetrics() { prometheus.MustRegister(TiKVPipelinedFlushDuration) prometheus.MustRegister(TiKVValidateReadTSFromPDCount) prometheus.MustRegister(TiKVLowResolutionTSOUpdateIntervalSecondsGauge) + prometheus.MustRegister(StaleRegionFromPDCounter) } // readCounter reads the value of a prometheus.Counter.