From 92858b774498a40d7ec7991879e3331cd7f1fc27 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Wed, 11 Oct 2023 11:42:25 +0800 Subject: [PATCH] *: remove store statistics after store tombstone (#7186) close tikv/pd#7187 Signed-off-by: Ryan Leung Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- pkg/mcs/scheduling/server/cluster.go | 3 +-- pkg/statistics/store_collection.go | 7 ++++--- server/cluster/cluster.go | 8 +++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/mcs/scheduling/server/cluster.go b/pkg/mcs/scheduling/server/cluster.go index a6a3de11d53..e8489fdaa15 100644 --- a/pkg/mcs/scheduling/server/cluster.go +++ b/pkg/mcs/scheduling/server/cluster.go @@ -470,8 +470,7 @@ func (c *Cluster) collectClusterMetrics() { } func (c *Cluster) resetMetrics() { - statsMap := statistics.NewStoreStatisticsMap(c.persistConfig) - statsMap.Reset() + statistics.Reset() c.coordinator.GetSchedulersController().ResetSchedulerMetrics() c.coordinator.ResetHotSpotMetrics() diff --git a/pkg/statistics/store_collection.go b/pkg/statistics/store_collection.go index 3e53e423084..dcdd77d9112 100644 --- a/pkg/statistics/store_collection.go +++ b/pkg/statistics/store_collection.go @@ -102,7 +102,6 @@ func (s *storeStatistics) Observe(store *core.StoreInfo) { case metapb.NodeState_Removed: s.Tombstone++ s.Removed++ - s.resetStoreStatistics(storeAddress, id) return } @@ -261,7 +260,8 @@ func (s *storeStatistics) Collect() { } } -func (s *storeStatistics) resetStoreStatistics(storeAddress string, id string) { +// ResetStoreStatistics resets the metrics of store. +func ResetStoreStatistics(storeAddress string, id string) { metrics := []string{ "region_score", "leader_score", @@ -317,7 +317,8 @@ func (m *storeStatisticsMap) Collect() { m.stats.Collect() } -func (m *storeStatisticsMap) Reset() { +// Reset resets the metrics. +func Reset() { storeStatusGauge.Reset() clusterStatusGauge.Reset() placementStatusGauge.Reset() diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index 55f67f223cd..332a8b27a3f 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -1625,7 +1625,10 @@ func (c *RaftCluster) BuryStore(storeID uint64, forceBury bool) error { // clean up the residual information. delete(c.prevStoreLimit, storeID) c.RemoveStoreLimit(storeID) - c.resetProgress(storeID, store.GetAddress()) + addr := store.GetAddress() + c.resetProgress(storeID, addr) + storeIDStr := strconv.FormatUint(storeID, 10) + statistics.ResetStoreStatistics(addr, storeIDStr) if !c.isAPIServiceMode { c.hotStat.RemoveRollingStoreStats(storeID) c.slowStat.RemoveSlowStoreStatus(storeID) @@ -2169,8 +2172,7 @@ func (c *RaftCluster) collectMetrics() { } func (c *RaftCluster) resetMetrics() { - statsMap := statistics.NewStoreStatisticsMap(c.opt) - statsMap.Reset() + statistics.Reset() if !c.isAPIServiceMode { c.coordinator.GetSchedulersController().ResetSchedulerMetrics()