From 83aca79137e85dcf6be0aca43c9c90f92bae1931 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 28 Apr 2020 11:57:19 +0300 Subject: [PATCH] lib/storage: recover when metricID->metricName entry is missing in the inverted index after unclean shutdown Newly added index entries can be missing after unclean shutdown, since they didn't flush to persistent storage yet. Log about this and delete the corresponding metricID, so it could be re-created next time. --- lib/storage/index_db.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index 808137351..de28aaf26 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -2557,6 +2557,14 @@ func (db *indexDB) storeDateMetricID(date, metricID uint64) error { defer PutMetricName(mn) kb.B, err = db.searchMetricName(kb.B[:0], metricID) if err != nil { + if err == io.EOF { + logger.Errorf("missing metricName by metricID %d; this could be the case after unclean shutdown; "+ + "deleting the metricID, so it could be re-created next time", metricID) + if err := db.deleteMetricIDs([]uint64{metricID}); err != nil { + return fmt.Errorf("cannot delete metricID %d after unclean shutdown: %s", metricID, err) + } + return nil + } return fmt.Errorf("cannot find metricName by metricID %d: %s", metricID, err) } if err = mn.Unmarshal(kb.B); err != nil {