Repository navigation
Description
Problem
In crates/incentive/src/buyer_channel_table.rs, forget and forget_if_channel commit unconditionally, even when nothing was removed. Under Durability::Immediate that is a synchronous fsync on a transaction that changed nothing.
The other two no-row operations already do the right thing — advance_progress and add_deposit return early from inside the write txn on UnknownProvider / ChannelMismatch / Regressed, so it drops uncommitted and redb aborts it. Their doc comments say why. forget_if_channel is the deliberate exception, and carries a NOTE saying so.
Raised by Gemini on #1257 (forget, forget_if_channel). Not taken there: the behavior is pre-existing and identical in both stores that PR merged (on main, node's buyer_forget and incentive's forget both .remove() then .commit() with no guard), and #1257's value depended on being behavior-preserving.
The fix is bigger than it looks
The obvious patch — commit only when a row was actually removed — is incomplete. The table_exists() pre-check exists only because the commit is unconditional:
WriteTransaction::open_table creates the table, so without the pre-check a forget on a never-written store would commit that creation. Skip the commit and the aborted txn rolls the creation back on its own.
Verified rather than assumed: deleting the pre-check from advance_progress (which already early-returns from inside the txn) leaves no_row_ops_do_not_create_the_table passing. The abort really does roll back the implicit table creation.
So the patch as suggested trades one cost for another — it stops paying an fsync but keeps paying a whole extra read transaction on every forget to guard against something that can no longer happen.
Proposed change
For forget and forget_if_channel:
- Commit only when a row was actually removed (
table.remove(&key)?.is_some()/matches). - Delete the now-redundant
table_exists()pre-check from both — the aborted txn covers it. - Re-verify
no_row_ops_do_not_create_the_tablestill holds for all four ops, and update its comment: the pre-check would no longer be the mechanism keeping the table uncreated for these two; the abort is. - Keep the pre-check in
advance_progress/add_deposit, or delete it there too — it's already redundant for them by the same argument. Worth deciding once, consistently, with the reasoning written down.
Net: saves both the fsync and the read txn, and makes all four no-row ops consistent.
Severity
Low. One wasted fsync per forget of an already-absent row, plus one redundant read txn per call — all off the hot path. This is cleanup, not a bug: no correctness or durability issue, and no on-disk impact.
Acceptance
- No write txn commits when it changed nothing.
- No redundant read txn guarding a case the abort already handles.
no_row_ops_do_not_create_the_tablestill passes, with a comment matching the actual mechanism.- The four no-row ops are consistent, and the reason is documented.
Activity