Skip to content

perf(node): split the lane store into per-family redb files (#1795 item 3) - #1880

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/issue-1795-item-3-62ca8c
Aug 31, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/issue-1795-item-3-62ca8c

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #1795 item 3 (Group H hot-path audit).

Problem

One lanes.redb held every durable write family behind a single redb write-transaction slot, so unrelated commits serialized on one writer: the periodic lane flush, a settlement checkpoint, a floor-loss write on abnormal stream end, and a buyer top-up all queued behind each other. A durability burst anywhere back-pressured every other subsystem's durable writes.

Fix

Give each write family its own redb file under data_dir, each with its own writer slot:

File Tables Family
lanes.redb lane_state_v1 + capability_v1 periodic lane flush (shared txn)
settle.redb pending_settle_v1 + buyer_pending_settle_v1 settlement sweep
floor-loss.redb pool_floor_loss_v1 + ..._forgotten_v1 abnormal-stream-end write (shared txn)
checkpoint.redb watcher_checkpoint_v1 settlement watcher
buyer.redb buyer_pool_state_v3 + ..._owner_index_v3 buyer top-up

The families were already committed in independent transactions, so there is no cross-family atomicity to preserve — splitting changes crash semantics for none of them; it only removes the writer-slot serialization between them. The only intra-file multi-table transactions are lane+capability and floor-loss+tombstone, and both stay co-located.

Notes on the issue text

Two of item 3's bullets were stale by the time this landed:

Implementation

Verification

  • cargo build, cargo clippy, cargo fmt --check clean
  • cargo nextest run -p decdn-node -p decdn-incentive green (incl. all 14 channel_state_store integration guards)

🤖 Generated with Claude Code

…em 3)

One `lanes.redb` held every durable write family behind a single redb
write-transaction slot, so unrelated commits serialized: the periodic lane
flush, a settlement checkpoint, a floor-loss write on abnormal stream end,
and a buyer top-up all queued on one writer.

Give each family its own redb file under `data_dir`, each with its own
writer slot:

- lanes.redb      — lane frontier + capability rows (shared flush txn)
- settle.redb     — seller + buyer pending-settle sets
- floor-loss.redb — dead-charge totals + forget tombstones (shared txn)
- checkpoint.redb — settlement-watcher scan checkpoints
- buyer.redb      — buyer pool state + owner index

The families were already committed in independent transactions, so there
is no cross-family atomicity to preserve — splitting changes crash
semantics for none of them, it only removes the writer-slot serialization
between them. The only intra-file multi-table transactions are lane+capability
and floor-loss+tombstone; both stay co-located.

Factor the per-file open into `open_hardened_db` (the #527 empty-file guard,
TOCTOU-safe create, and 0o600 tightening), called once per family with
lanes.redb first so the #527 fault-injection tests still name it. `open_with`
takes `Fn` (called five times) instead of `FnOnce`.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 31, 2026 14:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Splits the node’s previously single lanes.redb durable state into multiple per-“write family” redb files under data_dir, so unrelated durable commits no longer serialize behind one redb writer slot. This targets background-task contention identified in #1795 item 3 (hot-path audit), while keeping the existing per-family crash/atomicity semantics.

Changes:

  • Refactors PersistentPoolStateStore to open/manage 5 separate redb files (lanes, settle, floor-loss, checkpoint, buyer) and routes each table family to its dedicated Database.
  • Adds shared hardened-open helper (open_hardened_db) and updates chmod hardening/tests to cover all family files.
  • Updates docstrings and operator-facing observability text to reflect the new per-family file layout and failure modes.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/node/src/channel_store.rs Core refactor: split store into per-family redb Databases; add hardened open helper; update durability/docs and tests for new file set.
crates/node/src/runtime/mod.rs Update runtime wiring comment to match per-family file commits under a single concrete store handle.
crates/node/tests/channel_state_store.rs Rename/update concurrency test doc to reflect the lane-flush vs floor-loss split across files.
crates/node/src/metrics.rs Update metric documentation to point to floor-loss.redb as the likely latching/corruption locus for floor-loss persist failures.
crates/node/src/handlers/client/mod.rs Update test comment to reference floor-loss.redb instead of the formerly shared file.
crates/incentive/src/buyer_pool_table.rs Update documentation about where the node’s buyer table is persisted (buyer.redb).
crates/incentive/src/buyer_pool_redb.rs Update module docs to reflect node buyer persistence in its own file and independent writer slot.
adr/appendix-observability.md Update observability appendix to reference floor-loss.redb (not shared lanes.redb) for sustained floor-loss persist failures.
Suppressed comments (1)

crates/node/src/channel_store.rs:630

  • This backend-open error also hard-codes "lane state store file" but can now refer to any of the per-family DB files. Using a generic name (or including the family filename) will make failure reports clearer.
                "failed to open lane state store file at {}: {err}. \
                 Removing the file forfeits its durability guard \
                 — restore from backup or investigate the corruption.",

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/node/src/channel_store.rs Resolved
…em 3 review)

`open_hardened_db` opens every per-family file, but the empty-file and
open-failure messages said "lane state store file", which reads as
misleading when settle/floor-loss/checkpoint/buyer is the one truncated.
Say "redb store file" and lean on the path (which already names the file);
the #527 note stays scoped to lanes.redb explicitly.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

Copy link
Copy Markdown

Coverage report

Total: 82.28% (was 82.27%, ▲ +0.01%) — 69275/84194 lines

File Coverage Lines Δ
crates/incentive/src/buyer_pool_redb.rs 94.25% 164/174 ● 0.00%
crates/incentive/src/buyer_pool_table.rs 90.18% 817/906 ● 0.00%
crates/node/src/channel_store.rs 87.97% 1689/1920 ▲ +0.13%
crates/node/src/handlers/client/mod.rs 93.81% 1865/1988 ● 0.00%
crates/node/src/metrics.rs 94.57% 870/920 ● 0.00%
crates/node/src/runtime/mod.rs 47.79% 1158/2423 ● 0.00%
History
Commit Total Δ vs base
f432971 (HEAD) 82.28% ▲ +0.01%

@alpergundogdu
alpergundogdu merged commit 26b3211 into main Aug 31, 2026
25 checks passed
@alpergundogdu
alpergundogdu deleted the claude/issue-1795-item-3-62ca8c branch August 31, 2026 14:27
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.

perf(node): background tasks steal hot-path locks — flush/settlement under LaneBuffer, single redb writer, sweep scans

2 participants