diff --git a/lib/mergeset/inmemory_part.go b/lib/mergeset/inmemory_part.go index 9b41faca82..012d6dcc20 100644 --- a/lib/mergeset/inmemory_part.go +++ b/lib/mergeset/inmemory_part.go @@ -76,9 +76,8 @@ var inmemoryPartBytePool bytesutil.ByteBufferPool // It is safe calling NewPart multiple times. // It is unsafe re-using mp while the returned part is in use. func (mp *inmemoryPart) NewPart() *part { - ph := mp.ph size := mp.size() - p, err := newPart(&ph, "", size, mp.metaindexData.NewReader(), &mp.indexData, &mp.itemsData, &mp.lensData) + p, err := newPart(&mp.ph, "", size, mp.metaindexData.NewReader(), &mp.indexData, &mp.itemsData, &mp.lensData) if err != nil { logger.Panicf("BUG: cannot create a part from inmemoryPart: %s", err) } @@ -86,5 +85,5 @@ func (mp *inmemoryPart) NewPart() *part { } func (mp *inmemoryPart) size() uint64 { - return uint64(len(mp.metaindexData.B) + len(mp.indexData.B) + len(mp.itemsData.B) + len(mp.lensData.B)) + return uint64(cap(mp.metaindexData.B) + cap(mp.indexData.B) + cap(mp.itemsData.B) + cap(mp.lensData.B)) } diff --git a/lib/storage/inmemory_part.go b/lib/storage/inmemory_part.go index 3f78e24b7b..b0681c9849 100644 --- a/lib/storage/inmemory_part.go +++ b/lib/storage/inmemory_part.go @@ -49,9 +49,12 @@ func (mp *inmemoryPart) InitFromRows(rows []rawRow) { // It is safe calling NewPart multiple times. // It is unsafe re-using mp while the returned part is in use. func (mp *inmemoryPart) NewPart() (*part, error) { - ph := mp.ph - size := uint64(len(mp.timestampsData.B) + len(mp.valuesData.B) + len(mp.indexData.B) + len(mp.metaindexData.B)) - return newPart(&ph, "", size, mp.metaindexData.NewReader(), &mp.timestampsData, &mp.valuesData, &mp.indexData) + size := mp.size() + return newPart(&mp.ph, "", size, mp.metaindexData.NewReader(), &mp.timestampsData, &mp.valuesData, &mp.indexData) +} + +func (mp *inmemoryPart) size() uint64 { + return uint64(cap(mp.timestampsData.B) + cap(mp.valuesData.B) + cap(mp.indexData.B) + cap(mp.metaindexData.B)) } func getInmemoryPart() *inmemoryPart {