From 0fbfa8c245a5975e072772f19cd2434a6bd2a903 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 31 Jan 2022 22:45:56 +0200 Subject: [PATCH] lib/storage: avoid allocations of tsidPrev on every blockStreamReader.NextBlock() call This is a follow-up for 00b7c97d2a9e27693d9156803fdcb485b262eddd Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2082 --- lib/storage/block_stream_reader.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/storage/block_stream_reader.go b/lib/storage/block_stream_reader.go index 6398adf226..9d9361c47d 100644 --- a/lib/storage/block_stream_reader.go +++ b/lib/storage/block_stream_reader.go @@ -18,6 +18,11 @@ type blockStreamReader struct { // Currently active block. Block Block + // Contains TSID for the previous block. + // This field is needed for checking that TSIDs + // increase over time when reading blocks. + tsidPrev TSID + // Filesystem path to the stream reader. // // Is empty for inmemory stream readers. @@ -213,12 +218,12 @@ func (bsr *blockStreamReader) NextBlock() bool { if bsr.err != nil { return false } - tsidPrev := bsr.Block.bh.TSID + bsr.tsidPrev = bsr.Block.bh.TSID bsr.Block.Reset() err := bsr.readBlock() if err == nil { - if bsr.Block.bh.TSID.Less(&tsidPrev) { - bsr.err = fmt.Errorf("possible data corruption: the next TSID=%v is smaller than the previous TSID=%v", &bsr.Block.bh.TSID, &tsidPrev) + if bsr.Block.bh.TSID.Less(&bsr.tsidPrev) { + bsr.err = fmt.Errorf("possible data corruption: the next TSID=%v is smaller than the previous TSID=%v", &bsr.Block.bh.TSID, &bsr.tsidPrev) return false } if bsr.Block.bh.RowsCount == 0 {