From 218c5338747026b5cccbaa557753951da5956930 Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Fri, 20 Sep 2024 11:50:47 +0200 Subject: [PATCH] lib/storage: follow-up after d8f8822fa5be0060551b9e644165066b2797ce16 (#7036) Make function name and comments more clear. https://github.com/VictoriaMetrics/VictoriaMetrics/commit/d8f8822fa5be0060551b9e644165066b2797ce16 Signed-off-by: hagen1778 Co-authored-by: Nikolay --- lib/storage/index_db.go | 9 +++++---- lib/storage/storage.go | 15 ++++----------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index 2c37c2fd3..0e6ea2a92 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -1518,7 +1518,7 @@ func (db *indexDB) searchMetricNameWithCache(dst []byte, metricID uint64) ([]byt return dst, true } - if db.s.shouldDeleteMissingMetricID(metricID) { + if db.s.wasMetricIDMissingBefore(metricID) { // Cannot find the MetricName for the given metricID for the last 60 seconds. // It is likely the indexDB contains incomplete set of metricID -> metricName entries // after unclean shutdown or after restoring from a snapshot. @@ -1799,9 +1799,10 @@ func (db *indexDB) getTSIDsFromMetricIDs(qt *querytracer.Tracer, metricIDs []uin if !is.getTSIDByMetricID(tsid, metricID) { // Cannot find TSID for the given metricID. // This may be the case on incomplete indexDB - // due to snapshot or due to unflushed entries. - // Just increment errors counter and skip it for now. - if is.db.s.shouldDeleteMissingMetricID(metricID) { + // due to snapshot or due to un-flushed entries. + // Mark the metricID as deleted, so it is created again when new sample + // for the given time series is ingested next time. + if is.db.s.wasMetricIDMissingBefore(metricID) { is.db.missingTSIDsForMetricID.Add(1) metricIDsToDelete = append(metricIDsToDelete, metricID) } diff --git a/lib/storage/storage.go b/lib/storage/storage.go index 71b91b1a5..c3996f137 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -2711,21 +2711,20 @@ var indexDBTableIdx = func() *atomic.Uint64 { return &x }() -// shouldDeleteMissingMetricID checks if metricID index entry is missing +// wasMetricIDMissingBefore checks if passed metricID was already registered as missing before. +// It returns true if metricID was registered as missing for more than 60s. // -// Broken index entry should be deleted by caller +// This function is called when storage can't find TSID for corresponding metricID. // There are the following expected cases when this may happen: -// // 1. The corresponding metricID -> metricName/tsid entry isn't visible for search yet. // The solution is to wait for some time and try the search again. // It is OK if newly registered time series isn't visible for search during some time. // This should resolve https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5959 -// // 2. The metricID -> metricName/tsid entry doesn't exist in the indexdb. // This is possible after unclean shutdown or after restoring of indexdb from a snapshot. // In this case the metricID must be deleted, so new metricID is registered // again when new sample for the given metric is ingested next time. -func (s *Storage) shouldDeleteMissingMetricID(metricID uint64) bool { +func (s *Storage) wasMetricIDMissingBefore(metricID uint64) bool { ct := fasttime.UnixTimestamp() s.missingMetricIDsLock.Lock() defer s.missingMetricIDsLock.Unlock() @@ -2742,11 +2741,5 @@ func (s *Storage) shouldDeleteMissingMetricID(metricID uint64) bool { deleteDeadline = ct + 60 s.missingMetricIDs[metricID] = deleteDeadline } - // Cannot find index entry for the given metricID for the last 60 seconds. - // It is likely the indexDB contains incomplete set of metricID -> metricName/tsid entries - // after unclean shutdown or after restoring from a snapshot. - // Mark the metricID as deleted, so it is created again when new sample - // for the given time series is ingested next time. - return ct > deleteDeadline }