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.
This commit is contained in:
Aliaksandr Valialkin 2020-04-28 11:57:19 +03:00
parent 1397612117
commit 83aca79137

View File

@ -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 {