From 3d12906286cb31505ceebcd39567c4e6dee7a750 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Thu, 6 Apr 2017 19:50:32 +0200 Subject: [PATCH] storage: Guard against a corner case of data corruption Fixes #2475. --- storage/local/crashrecovery.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/storage/local/crashrecovery.go b/storage/local/crashrecovery.go index 2d89e6f808..822678b4d3 100644 --- a/storage/local/crashrecovery.go +++ b/storage/local/crashrecovery.go @@ -86,11 +86,12 @@ func (p *persistence) recoverFromCrash(fingerprintToSeries map[model.Fingerprint for fp, s := range fingerprintToSeries { if _, seen := fpsSeen[fp]; !seen { // fp exists in fingerprintToSeries, but has no representation on disk. - if s.persistWatermark == len(s.chunkDescs) { + if s.persistWatermark >= len(s.chunkDescs) { // Oops, everything including the head chunk was - // already persisted, but nothing on disk. - // Thus, we lost that series completely. Clean - // up the remnants. + // already persisted, but nothing on disk. Or + // the persistWatermark is plainly wrong. Thus, + // we lost that series completely. Clean up the + // remnants. delete(fingerprintToSeries, fp) if err := p.purgeArchivedMetric(fp); err != nil { // Purging the archived metric didn't work, so try