lib/storage: avoid allocations of tsidPrev on every blockStreamReader.NextBlock() call

This is a follow-up for 00b7c97d2a

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2082
This commit is contained in:
Aliaksandr Valialkin 2022-01-31 22:45:56 +02:00
parent a8d22e1223
commit a8509c112a
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -18,6 +18,11 @@ type blockStreamReader struct {
// Currently active block. // Currently active block.
Block 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. // Filesystem path to the stream reader.
// //
// Is empty for inmemory stream readers. // Is empty for inmemory stream readers.
@ -213,12 +218,12 @@ func (bsr *blockStreamReader) NextBlock() bool {
if bsr.err != nil { if bsr.err != nil {
return false return false
} }
tsidPrev := bsr.Block.bh.TSID bsr.tsidPrev = bsr.Block.bh.TSID
bsr.Block.Reset() bsr.Block.Reset()
err := bsr.readBlock() err := bsr.readBlock()
if err == nil { if err == nil {
if bsr.Block.bh.TSID.Less(&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, &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 return false
} }
if bsr.Block.bh.RowsCount == 0 { if bsr.Block.bh.RowsCount == 0 {