Skip to content

Commit

Permalink
db: intialize memTable.reserve when creating memTable
Browse files Browse the repository at this point in the history
  • Loading branch information
sumeerbhola committed May 10, 2023
1 parent c03eda9 commit 23f478b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions mem_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func newMemTable(opts memTableOptions) *memTable {
m.skl.Reset(arena, m.cmp)
m.rangeDelSkl.Reset(arena, m.cmp)
m.rangeKeySkl.Reset(arena, m.cmp)
m.reserved = arena.Size()
return m
}

Expand Down
15 changes: 15 additions & 0 deletions mem_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,21 @@ func TestMemTableConcurrentDeleteRange(t *testing.T) {
}
}

func TestMemTableReserved(t *testing.T) {
m := newMemTable(memTableOptions{size: 5000})
// Increase to 2 references.
m.writerRef()
// The initial reservation accounts for the already allocated bytes from the
// arena.
require.Equal(t, m.reserved, m.skl.Arena().Size())
b := newBatch(nil)
b.Set([]byte("blueberry"), []byte("pie"), nil)
require.NotEqual(t, 0, int(b.memTableSize))
prevReserved := m.reserved
m.prepare(b)
require.Equal(t, int(m.reserved), int(b.memTableSize)+int(prevReserved))
}

func buildMemTable(b *testing.B) (*memTable, [][]byte) {
m := newMemTable(memTableOptions{})
var keys [][]byte
Expand Down

0 comments on commit 23f478b

Please sign in to comment.