From 63f51fa228a3a4f2d554716e4f51f44c620556a8 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Mon, 23 Oct 2023 15:29:33 +0800 Subject: [PATCH 1/2] Fix cornercase in capping memory allowance This pull request addresses a corner case when capping the pebble memory allowance. On a 32-bit machine, the memory usage is capped at MaxInt32 (note that this value is also inclusive), and on a 64-bit machine, it's capped at MaxUint32. These edge values should also be considered valid options. --- options.go | 4 ++-- options_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/options.go b/options.go index c4c6b12387..c4e799b1cf 100644 --- a/options.go +++ b/options.go @@ -1662,8 +1662,8 @@ func (o *Options) Validate() error { fmt.Fprintf(&buf, "L0StopWritesThreshold (%d) must be >= L0CompactionThreshold (%d)\n", o.L0StopWritesThreshold, o.L0CompactionThreshold) } - if uint64(o.MemTableSize) >= maxMemTableSize { - fmt.Fprintf(&buf, "MemTableSize (%s) must be < %s\n", + if uint64(o.MemTableSize) > maxMemTableSize { + fmt.Fprintf(&buf, "MemTableSize (%s) must be <= %s\n", humanize.Bytes.Uint64(uint64(o.MemTableSize)), humanize.Bytes.Uint64(maxMemTableSize)) } if o.MemTableStopWritesThreshold < 2 { diff --git a/options_test.go b/options_test.go index 46a5863ee6..0d448a96e3 100644 --- a/options_test.go +++ b/options_test.go @@ -280,7 +280,7 @@ func TestOptionsValidate(t *testing.T) { [Options] mem_table_size=4294967296 `, - `MemTableSize \(4\.0GB\) must be < [2|4]\.0GB`, + `MemTableSize \(4\.0GB\) must be <= [2|4]\.0GB`, }, {` [Options] From b2fd753140ef153c311c54b82ab7f482d68f1ab8 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Tue, 31 Oct 2023 20:42:28 +0800 Subject: [PATCH 2/2] Fix size overflow in batch --- batch.go | 2 +- batch_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/batch.go b/batch.go index badcd345c0..73b5176e9e 100644 --- a/batch.go +++ b/batch.go @@ -1381,7 +1381,7 @@ func (b *Batch) countData() []byte { func (b *Batch) grow(n int) { newSize := len(b.data) + n - if uint64(newSize) >= maxBatchSize { + if uint64(newSize) > maxBatchSize { panic(ErrBatchTooLarge) } if newSize > cap(b.data) { diff --git a/batch_test.go b/batch_test.go index 1f05c07e84..f0a886e9c4 100644 --- a/batch_test.go +++ b/batch_test.go @@ -986,7 +986,7 @@ func TestBatchTooLarge(t *testing.T) { result = r } }() - b.grow(maxBatchSize) + b.grow(maxBatchSize + 1) }() require.EqualValues(t, ErrBatchTooLarge, result) }