1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Arena allocator backed by `bumpalo::Bump`.
//!
//! Used for arena-allocating raw bytes within a memtable's lifetime.
//! The arena is tied to one `Memtable` instance and is dropped when
//! the memtable is flushed and released.
//!
//! # Note on `alloc_bytes` removal
//!
//! A previous `alloc_bytes(&self, n: usize) -> &mut [u8]` method was unsound:
//! it acquired the inner `Mutex`, allocated from the `Bump`, dropped the
//! `MutexGuard`, then returned a `&mut [u8]` with the lifetime of `&self` via
//! `unsafe` pointer cast. Two concurrent calls could produce overlapping
//! `&mut [u8]` slices, violating Rust's aliasing rules. The method had zero
//! callers in the codebase (the skip-list hot path uses `bytes::Bytes`), so it
//! was removed rather than made safe.
//!
//! If arena-backed allocation is needed in the future, the safe approach is to
//! return an `(offset, len)` pair and provide a separate shared accessor, or to
//! require `&mut self` so the borrow checker enforces exclusivity.
use ;
/// Thread-safe arena allocator. `bumpalo::Bump` itself is not `Sync`, so we
/// wrap it in a `Mutex` for the (rare) concurrent alloc case. The hot path
/// (skip list inserts) does not use the arena directly — values are stored
/// as `bytes::Bytes` (reference-counted). The arena is here for future use
/// (e.g., arena-backed key storage to reduce allocator pressure).