From e8377011ab95e8dc921a1cad4b30f283b8d70fd8 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 25 Jun 2019 14:39:17 +0300 Subject: [PATCH] lib/storage: free up memory from caches owned by indexDB when it is deleted --- lib/storage/index_db.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index 3dd49ab59..f4d6f9d29 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -111,17 +111,15 @@ func openIndexDB(path string, metricIDCache, metricNameCache *fastcache.Cache, c // Do not persist tagCache in files, since it is very volatile. mem := memory.Allowed() - tagCache := fastcache.New(mem / 32) db := &indexDB{ refCount: 1, tb: tb, name: name, - tagCache: tagCache, - metricIDCache: metricIDCache, - metricNameCache: metricNameCache, - + tagCache: fastcache.New(mem / 32), + metricIDCache: metricIDCache, + metricNameCache: metricNameCache, uselessTagFiltersCache: fastcache.New(mem / 128), currHourMetricIDs: currHourMetricIDs, @@ -261,6 +259,15 @@ func (db *indexDB) decRef() { db.tb.MustClose() db.SetExtDB(nil) + // Free space occupied by caches owned by db. + db.tagCache.Reset() + db.uselessTagFiltersCache.Reset() + + db.tagCache = nil + db.metricIDCache = nil + db.metricNameCache = nil + db.uselessTagFiltersCache = nil + if atomic.LoadUint64(&db.mustDrop) == 0 { return }