From 410f993bf694d3608fb86bb19d9cfa3d66720365 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 19 Sep 2019 17:46:32 +0300 Subject: [PATCH] lib/mergeset: fill partHeader.firstItem on first block flush --- lib/mergeset/merge.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/mergeset/merge.go b/lib/mergeset/merge.go index 2387c793a7..27a6a014db 100644 --- a/lib/mergeset/merge.go +++ b/lib/mergeset/merge.go @@ -95,11 +95,6 @@ again: bsr := heap.Pop(&bsm.bsrHeap).(*blockStreamReader) - if !bsm.phFirstItemCaught { - ph.firstItem = append(ph.firstItem[:0], bsr.Block.items[0]...) - bsm.phFirstItemCaught = true - } - var nextItem []byte hasNextItem := false if len(bsm.bsrHeap) > 0 { @@ -142,6 +137,10 @@ func (bsm *blockStreamMerger) flushIB(bsw *blockStreamWriter, ph *partHeader, it itemsCount := uint64(len(bsm.ib.items)) ph.itemsCount += itemsCount atomic.AddUint64(itemsMerged, itemsCount) + if !bsm.phFirstItemCaught { + ph.firstItem = append(ph.firstItem[:0], bsm.ib.items[0]...) + bsm.phFirstItemCaught = true + } ph.lastItem = append(ph.lastItem[:0], bsm.ib.items[len(bsm.ib.items)-1]...) bsw.WriteBlock(&bsm.ib) bsm.ib.Reset()