From 2601cc0fb003823eeba978ad6ae458e65219da91 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 26 Mar 2021 17:57:51 +0200 Subject: [PATCH] lib/storage: do not update b.nextIdx if no samples are removed because of retention --- lib/storage/merge.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/storage/merge.go b/lib/storage/merge.go index 2795b2439..e5e7f221d 100644 --- a/lib/storage/merge.go +++ b/lib/storage/merge.go @@ -179,11 +179,14 @@ func mergeBlocks(ob, ib1, ib2 *Block, retentionDeadline int64, rowsDeleted *uint func skipSamplesOutsideRetention(b *Block, retentionDeadline int64, rowsDeleted *uint64) { timestamps := b.timestamps nextIdx := b.nextIdx + nextIdxOrig := nextIdx for nextIdx < len(timestamps) && timestamps[nextIdx] < retentionDeadline { nextIdx++ } - atomic.AddUint64(rowsDeleted, uint64(nextIdx-b.nextIdx)) - b.nextIdx = nextIdx + if n := nextIdx - nextIdxOrig; n > 0 { + atomic.AddUint64(rowsDeleted, uint64(n)) + b.nextIdx = nextIdx + } } func appendRows(ob, ib *Block) {