From 927411a64ccc7ce3a9547d9bad12b93d62bb9a16 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Tue, 15 Oct 2024 16:09:36 +0800 Subject: [PATCH] fix the memory leak of region statistics Signed-off-by: Ryan Leung --- server/statistics/region_collection.go | 1 + server/statistics/region_collection_test.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/server/statistics/region_collection.go b/server/statistics/region_collection.go index 7b354ce9f54..8d4d6d1849c 100644 --- a/server/statistics/region_collection.go +++ b/server/statistics/region_collection.go @@ -283,6 +283,7 @@ func (r *RegionStatistics) ClearDefunctRegion(regionID uint64) { } } if oldIndex, ok := r.offlineIndex[regionID]; ok { + delete(r.offlineIndex, regionID) r.deleteOfflineEntry(oldIndex, regionID) } } diff --git a/server/statistics/region_collection_test.go b/server/statistics/region_collection_test.go index 6f27443b24f..aa5a8399ab6 100644 --- a/server/statistics/region_collection_test.go +++ b/server/statistics/region_collection_test.go @@ -129,6 +129,10 @@ func TestRegionStatistics(t *testing.T) { stores[3] = store3 regionStats.Observe(region1, stores) re.Empty(regionStats.stats[OfflinePeer]) + + regionStats.ClearDefunctRegion(1) + re.Equal(1, len(regionStats.index)) + re.Equal(1, len(regionStats.offlineIndex)) } func TestRegionStatisticsWithPlacementRule(t *testing.T) {