lib/mergeset: properly record the firstItem in metaindexRow at blockStreamWriter.WriteBlock

The 3c246cdf00 added an optimization where the previous metaindexRow
could be saved to disk when the current block header couldn't be added indexBlock because the resulting
indexBlock size became too big. This could result in an empty metaindexRow.firstItem for the next metaindexRow.
This commit is contained in:
Aliaksandr Valialkin 2024-02-12 18:06:46 +02:00
parent 2eb967231b
commit 5d69ba630e
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -130,11 +130,6 @@ func (bsw *blockStreamWriter) MustClose() {
func (bsw *blockStreamWriter) WriteBlock(ib *inmemoryBlock) { func (bsw *blockStreamWriter) WriteBlock(ib *inmemoryBlock) {
bsw.bh.firstItem, bsw.bh.commonPrefix, bsw.bh.itemsCount, bsw.bh.marshalType = ib.MarshalSortedData(&bsw.sb, bsw.bh.firstItem[:0], bsw.bh.commonPrefix[:0], bsw.compressLevel) bsw.bh.firstItem, bsw.bh.commonPrefix, bsw.bh.itemsCount, bsw.bh.marshalType = ib.MarshalSortedData(&bsw.sb, bsw.bh.firstItem[:0], bsw.bh.commonPrefix[:0], bsw.compressLevel)
if !bsw.mrFirstItemCaught {
bsw.mr.firstItem = append(bsw.mr.firstItem[:0], bsw.bh.firstItem...)
bsw.mrFirstItemCaught = true
}
// Write itemsData // Write itemsData
fs.MustWriteData(bsw.itemsWriter, bsw.sb.itemsData) fs.MustWriteData(bsw.itemsWriter, bsw.sb.itemsData)
bsw.bh.itemsBlockSize = uint32(len(bsw.sb.itemsData)) bsw.bh.itemsBlockSize = uint32(len(bsw.sb.itemsData))
@ -155,6 +150,11 @@ func (bsw *blockStreamWriter) WriteBlock(ib *inmemoryBlock) {
bsw.flushIndexData() bsw.flushIndexData()
bsw.unpackedIndexBlockBuf = bsw.bh.Marshal(bsw.unpackedIndexBlockBuf) bsw.unpackedIndexBlockBuf = bsw.bh.Marshal(bsw.unpackedIndexBlockBuf)
} }
if !bsw.mrFirstItemCaught {
bsw.mr.firstItem = append(bsw.mr.firstItem[:0], bsw.bh.firstItem...)
bsw.mrFirstItemCaught = true
}
bsw.bh.Reset() bsw.bh.Reset()
bsw.mr.blockHeadersCount++ bsw.mr.blockHeadersCount++
} }