Skip to content

Backport feat/write buffer manager - #596

Merged
cb1kenobi merged 3 commits into
v1.3.xfrom
backport-feat/write-buffer-manager
May 27, 2026
Merged

cb1kenobi merged 3 commits into
v1.3.xfrom
backport-feat/write-buffer-manager

Conversation

@cb1kenobi

Copy link
Copy Markdown
Member

Backport of #584

kriszyp and others added 2 commits May 27, 2026 17:27
Adds a process-wide WriteBufferManager singleton in DBSettings, lazy-
created on first DB open and shared across every database in the
process. Memtable memory is bounded by a single configurable limit
rather than each DB managing its own budget.

New `RocksDatabase.config()` options:
- `writeBufferManagerSize` — bytes of memtable memory the WBM caps
  across all DBs (0 disables); runtime-mutable via SetBufferSize
- `writeBufferManagerCostToCache` — when true, memtable charges show
  up in `block-cache-usage` as pinned entries, giving a single
  observability metric for read cache + memtable footprint
- `writeBufferManagerAllowStall` — when true, writes stall once the
  cap is reached instead of letting memtables grow past it

Implementation notes:
- DBSettings::getInstance() now uses C++11 magic statics for thread-
  safe lazy initialization (previously raced on concurrent first-call
  from libuv worker threads).
- Configuration fields are `std::atomic` so JS-thread Config() writes
  are safe against worker-thread reads in getWriteBufferManager().
- WBM creation is mutex-protected; double-checked locking on the
  atomic size guards against teardown between load and lock.
- `costToCache` and `allowStall` are fixed at first WBM creation
  (already-open DBs hold shared_ptr refs; the WBM can't be swapped).
  Config() writes after creation are ignored with an stderr warning.
- Setting size=0 at runtime is a "no new attachments" signal, not a
  teardown — RocksDB asserts SetBufferSize(>0).

Verified by 11 tests covering: negative-size rejection, default-off
path, costToCache wiring, multi-DB sharing, runtime resize, active
memtable reclamation after flush, block-cache-usage charge visibility,
the actual structural cap (writeBufferManagerSize, not blockCacheSize),
and maintain-window cycling.

Co-Authored-By: Claude Sonnet 4.7 <noreply@anthropic.com>
@cb1kenobi
cb1kenobi requested a review from a team as a code owner May 27, 2026 22:27
@cb1kenobi
cb1kenobi merged commit 79b734c into v1.3.x May 27, 2026
38 of 40 checks passed
@cb1kenobi
cb1kenobi deleted the backport-feat/write-buffer-manager branch May 27, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants