diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index 26728b039..bf30836e0 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -506,9 +506,6 @@ func generateTSID(dst *TSID, mn *MetricName) { } func (is *indexSearch) createGlobalIndexes(tsid *TSID, mn *MetricName) { - // The order of index items is important. - // It guarantees index consistency. - ii := getIndexItems() defer putIndexItems(ii) @@ -1504,17 +1501,17 @@ func (db *indexDB) searchMetricNameWithCache(dst []byte, metricID uint64) ([]byt db.s.missingMetricIDs = nil db.s.missingMetricIDsResetDeadline = ct + 2*60 } - timestamp, ok := db.s.missingMetricIDs[metricID] + deleteDeadline, ok := db.s.missingMetricIDs[metricID] if !ok { if db.s.missingMetricIDs == nil { db.s.missingMetricIDs = make(map[uint64]uint64) } - db.s.missingMetricIDs[metricID] = ct - timestamp = ct + deleteDeadline = ct + 60 + db.s.missingMetricIDs[metricID] = deleteDeadline } db.s.missingMetricIDsLock.Unlock() - if ct > timestamp+60 { + if ct > deleteDeadline { // 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. diff --git a/lib/storage/storage.go b/lib/storage/storage.go index 8be641051..be09f9db5 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -147,9 +147,11 @@ type Storage struct { deletedMetricIDs atomic.Pointer[uint64set.Set] deletedMetricIDsUpdateLock sync.Mutex - // missingMetricIDs maps metricID to the timestamp of first unsuccessful lookup - // of metricName by the given metricID. + // missingMetricIDs maps metricID to the deadline in unix timestamp seconds + // after which all the indexdb entries for the given metricID + // must be deleted if metricName isn't found by the given metricID. // This is used inside searchMetricNameWithCache() for detecting permanently missing metricID->metricName entries. + // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5959 missingMetricIDsLock sync.Mutex missingMetricIDs map[uint64]uint64 missingMetricIDsResetDeadline uint64 @@ -1151,7 +1153,7 @@ func (s *Storage) SearchMetricNames(qt *querytracer.Tracer, tfss []*TagFilters, metricName, ok = idb.searchMetricNameWithCache(metricName[:0], metricID) if !ok { // Skip missing metricName for metricID. - // It should be automatically fixed. See indexDB.searchMetricName for details. + // It should be automatically fixed. See indexDB.searchMetricNameWithCache for details. continue } if _, ok := metricNamesSeen[string(metricName)]; ok {