diff --git a/lib/mergeset/block_stream_writer.go b/lib/mergeset/block_stream_writer.go index a184d7a4b..242ec8615 100644 --- a/lib/mergeset/block_stream_writer.go +++ b/lib/mergeset/block_stream_writer.go @@ -130,11 +130,6 @@ func (bsw *blockStreamWriter) MustClose() { 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) - if !bsw.mrFirstItemCaught { - bsw.mr.firstItem = append(bsw.mr.firstItem[:0], bsw.bh.firstItem...) - bsw.mrFirstItemCaught = true - } - // Write itemsData fs.MustWriteData(bsw.itemsWriter, bsw.sb.itemsData) bsw.bh.itemsBlockSize = uint32(len(bsw.sb.itemsData)) @@ -155,6 +150,11 @@ func (bsw *blockStreamWriter) WriteBlock(ib *inmemoryBlock) { bsw.flushIndexData() 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.mr.blockHeadersCount++ }