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 a858b7e393
commit d78ed50edd

View file

@ -2595,6 +2595,14 @@ func (db *indexDB) storeDateMetricID(date, metricID uint64, accountID, projectID
defer PutMetricName(mn)
kb.B, err = db.searchMetricName(kb.B[:0], metricID, accountID, projectID)
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 {