Skip to content

Commit

Permalink
sstable: avoid allocating up to maximum block size in valueBlockWriter
Browse files Browse the repository at this point in the history
Tests can set a high maximum block size e.g. TestReader sets the block size
to 2GB. This resulted in a 3GB byte slice being allocated. The new logic
is similar to the behavior in blockWriter.

Fixes #2159
  • Loading branch information
sumeerbhola authored and nicktrav committed Jan 11, 2023
1 parent 873d625 commit 5bad2c1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions sstable/value_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,12 @@ func (w *valueBlockWriter) addValue(v []byte) (valueHandle, error) {
}
blockLen = int(vh.offsetInBlock + vh.valueLen)
if cap(w.buf.b) < blockLen {
size := w.blockSize + w.blockSize/2
if size < blockLen {
size = blockLen + blockLen/2
size := 2 * cap(w.buf.b)
if size < 1024 {
size = 1024
}
for size < blockLen {
size *= 2
}
buf := make([]byte, blockLen, size)
_ = copy(buf, w.buf.b)
Expand Down

0 comments on commit 5bad2c1

Please sign in to comment.