lib/storage: do not update b.nextIdx if no samples are removed because of retention

This commit is contained in:
Aliaksandr Valialkin 2021-03-26 17:57:51 +02:00
parent 022fe4efd0
commit 940a547116

View file

@ -179,11 +179,14 @@ func mergeBlocks(ob, ib1, ib2 *Block, retentionDeadline int64, rowsDeleted *uint
func skipSamplesOutsideRetention(b *Block, retentionDeadline int64, rowsDeleted *uint64) { func skipSamplesOutsideRetention(b *Block, retentionDeadline int64, rowsDeleted *uint64) {
timestamps := b.timestamps timestamps := b.timestamps
nextIdx := b.nextIdx nextIdx := b.nextIdx
nextIdxOrig := nextIdx
for nextIdx < len(timestamps) && timestamps[nextIdx] < retentionDeadline { for nextIdx < len(timestamps) && timestamps[nextIdx] < retentionDeadline {
nextIdx++ nextIdx++
} }
atomic.AddUint64(rowsDeleted, uint64(nextIdx-b.nextIdx)) if n := nextIdx - nextIdxOrig; n > 0 {
atomic.AddUint64(rowsDeleted, uint64(n))
b.nextIdx = nextIdx b.nextIdx = nextIdx
}
} }
func appendRows(ob, ib *Block) { func appendRows(ob, ib *Block) {