From 876e5da4f818b490537a73e97bf078c2b44cf4f7 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Tue, 25 Oct 2016 14:59:33 +0200 Subject: [PATCH] Add guard against non-monotonic samples in series This can only happen due to data corruption. --- storage/local/series.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/storage/local/series.go b/storage/local/series.go index 05f0633d5..4acc40884 100644 --- a/storage/local/series.go +++ b/storage/local/series.go @@ -14,6 +14,7 @@ package local import ( + "fmt" "sort" "sync" "time" @@ -496,6 +497,10 @@ func (s *memorySeries) preloadChunksForRange( if throughIdx == len(s.chunkDescs) { throughIdx-- } + if fromIdx > throughIdx { + // Guard against nonsensical result. The caller will quarantine the series with a meaningful log entry. + return nopIter, fmt.Errorf("fromIdx=%d is greater than throughIdx=%d, likely caused by data corruption", fromIdx, throughIdx) + } pinIndexes := make([]int, 0, throughIdx-fromIdx+1) for i := fromIdx; i <= throughIdx; i++ {