From a75137c1c2f4d99aa57c37bdac684df80f7a856f Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 16 Nov 2022 21:21:46 +0200 Subject: [PATCH] lib/mergeset: properly reset bsr.bhIdx after the call to blockStreamReader.readNextBHS() The issue has been introduced in 58b40f514ca2148749635e09c288d62ef150514c Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3343 --- lib/mergeset/block_header.go | 2 +- lib/mergeset/block_stream_reader.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mergeset/block_header.go b/lib/mergeset/block_header.go index ce4c8dd51..a957427ae 100644 --- a/lib/mergeset/block_header.go +++ b/lib/mergeset/block_header.go @@ -167,7 +167,7 @@ func unmarshalBlockHeadersNoCopy(dst []blockHeader, src []byte, blockHeadersCoun for i := 0; i < blockHeadersCount; i++ { tail, err := dst[dstLen+i].UnmarshalNoCopy(src) if err != nil { - return dst, fmt.Errorf("cannot unmarshal block header: %w", err) + return dst, fmt.Errorf("cannot unmarshal block header #%d out of %d: %w", i, blockHeadersCount, err) } src = tail } diff --git a/lib/mergeset/block_stream_reader.go b/lib/mergeset/block_stream_reader.go index 7e21cf44c..528a89017 100644 --- a/lib/mergeset/block_stream_reader.go +++ b/lib/mergeset/block_stream_reader.go @@ -297,8 +297,9 @@ func (bsr *blockStreamReader) readNextBHS() error { // Unmarshal the unpacked index block into bsr.bhs. bsr.bhs, err = unmarshalBlockHeadersNoCopy(bsr.bhs[:0], bsr.unpackedBuf, int(mr.blockHeadersCount)) if err != nil { - return fmt.Errorf("cannot unmarshal blockHeader #%d in the index block #%d: %w", len(bsr.bhs), bsr.mrIdx, err) + return fmt.Errorf("cannot unmarshal blockHeaders in the index block #%d: %w", bsr.mrIdx, err) } + bsr.bhIdx = 0 return nil }