mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
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:
parent
7596e239eb
commit
218c533874
2 changed files with 9 additions and 15 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue