lib/storage: follow-up after d8f8822fa5 (#7036)

Make function name and comments more clear.

d8f8822fa5

Signed-off-by: hagen1778 <roman@victoriametrics.com>
Co-authored-by: Nikolay <nik@victoriametrics.com>
This commit is contained in:
Roman Khavronenko 2024-09-20 11:50:47 +02:00 committed by GitHub
parent 7596e239eb
commit 218c533874
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 15 deletions

View file

@ -1518,7 +1518,7 @@ func (db *indexDB) searchMetricNameWithCache(dst []byte, metricID uint64) ([]byt
return dst, true 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. // 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 // It is likely the indexDB contains incomplete set of metricID -> metricName entries
// after unclean shutdown or after restoring from a snapshot. // 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) { if !is.getTSIDByMetricID(tsid, metricID) {
// Cannot find TSID for the given metricID. // Cannot find TSID for the given metricID.
// This may be the case on incomplete indexDB // This may be the case on incomplete indexDB
// due to snapshot or due to unflushed entries. // due to snapshot or due to un-flushed entries.
// Just increment errors counter and skip it for now. // Mark the metricID as deleted, so it is created again when new sample
if is.db.s.shouldDeleteMissingMetricID(metricID) { // for the given time series is ingested next time.
if is.db.s.wasMetricIDMissingBefore(metricID) {
is.db.missingTSIDsForMetricID.Add(1) is.db.missingTSIDsForMetricID.Add(1)
metricIDsToDelete = append(metricIDsToDelete, metricID) metricIDsToDelete = append(metricIDsToDelete, metricID)
} }

View file

@ -2711,21 +2711,20 @@ var indexDBTableIdx = func() *atomic.Uint64 {
return &x 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: // There are the following expected cases when this may happen:
//
// 1. The corresponding metricID -> metricName/tsid entry isn't visible for search yet. // 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. // 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. // 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 // This should resolve https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5959
//
// 2. The metricID -> metricName/tsid entry doesn't exist in the indexdb. // 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. // 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 // 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. // 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() ct := fasttime.UnixTimestamp()
s.missingMetricIDsLock.Lock() s.missingMetricIDsLock.Lock()
defer s.missingMetricIDsLock.Unlock() defer s.missingMetricIDsLock.Unlock()
@ -2742,11 +2741,5 @@ func (s *Storage) shouldDeleteMissingMetricID(metricID uint64) bool {
deleteDeadline = ct + 60 deleteDeadline = ct + 60
s.missingMetricIDs[metricID] = deleteDeadline 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 return ct > deleteDeadline
} }