diff --git a/lib/mergeset/encoding.go b/lib/mergeset/encoding.go index 8cb57082c..f57f4f4e3 100644 --- a/lib/mergeset/encoding.go +++ b/lib/mergeset/encoding.go @@ -540,17 +540,6 @@ func putLensBuffer(lb *lensBuffer) { lensBufferPool.Put(lb) } -func getInmemoryBlock() *inmemoryBlock { - v := ibPool.Get() - if v == nil { - return &inmemoryBlock{} - } - return v.(*inmemoryBlock) +func newInmemoryBlock() *inmemoryBlock { + return &inmemoryBlock{} } - -func putInmemoryBlock(ib *inmemoryBlock) { - ib.Reset() - ibPool.Put(ib) -} - -var ibPool sync.Pool diff --git a/lib/mergeset/part_search.go b/lib/mergeset/part_search.go index 8671561b6..d2a8a1116 100644 --- a/lib/mergeset/part_search.go +++ b/lib/mergeset/part_search.go @@ -316,7 +316,7 @@ func (ps *partSearch) readInmemoryBlock(bh *blockHeader) (*inmemoryBlock, error) ps.sb.lensData = bytesutil.Resize(ps.sb.lensData, int(bh.lensBlockSize)) ps.p.lensFile.MustReadAt(ps.sb.lensData, int64(bh.lensBlockOffset)) - ib := getInmemoryBlock() + ib := newInmemoryBlock() if err := ib.UnmarshalData(&ps.sb, bh.firstItem, bh.commonPrefix, bh.itemsCount, bh.marshalType); err != nil { return nil, fmt.Errorf("cannot unmarshal storage block with %d items: %w", bh.itemsCount, err) } diff --git a/lib/mergeset/table.go b/lib/mergeset/table.go index ba12ada94..6a9eb7bed 100644 --- a/lib/mergeset/table.go +++ b/lib/mergeset/table.go @@ -182,16 +182,15 @@ func (ris *rawItemsShard) addItems(tb *Table, items [][]byte) error { ris.mu.Lock() ibs := ris.ibs if len(ibs) == 0 { - ib := getInmemoryBlock() + ib := newInmemoryBlock() ibs = append(ibs, ib) ris.ibs = ibs } ib := ibs[len(ibs)-1] for _, item := range items { if !ib.Add(item) { - ib = getInmemoryBlock() + ib = newInmemoryBlock() if !ib.Add(item) { - putInmemoryBlock(ib) err = fmt.Errorf("cannot insert an item %q into an empty inmemoryBlock; it looks like the item is too large? len(item)=%d", item, len(item)) break } @@ -675,13 +674,13 @@ func (tb *Table) mergeRawItemsBlocks(blocksToMerge []*inmemoryBlock) { func (tb *Table) mergeInmemoryBlocks(blocksToMerge []*inmemoryBlock) *partWrapper { // Convert blocksToMerge into inmemoryPart's mps := make([]*inmemoryPart, 0, len(blocksToMerge)) - for _, ib := range blocksToMerge { + for i, ib := range blocksToMerge { if len(ib.items) == 0 { continue } mp := getInmemoryPart() mp.Init(ib) - putInmemoryBlock(ib) + blocksToMerge[i] = nil mps = append(mps, mp) } if len(mps) == 0 {