]> git.hungrycats.org Git - bees/commit
bees: gate dedupe on the src's resulting reference count
authorZygo Blaxell <bees@furryterror.org>
Sun, 5 Jul 2026 17:26:26 +0000 (13:26 -0400)
committerZygo Blaxell <bees@furryterror.org>
Sat, 5 Sep 2026 04:04:13 +0000 (00:04 -0400)
commit4d4b0ef101c2eee9ef3b6c98cd5c9b2c0f720122
treeb12a53d52d4279cc013610d04b4eca4208ee27e9
parent8a901455c8f2c2c9c97c2369d6c8340e1b062535
bees: gate dedupe on the src's resulting reference count

The scan_next candidate gates rejected a dedupe only when an extent was
*already* at rewrite.refs-max references (a binary "src already full" test).
A single dedupe redirects every reference of the dst onto the src, so a src
sitting just under the limit could still absorb a many-ref dst and overshoot
the ceiling by thousands — the reference-cluster blow-up seen in extent-scan
stress runs, where hot canonical extents climbed well past the configured
limit.

Add scan_next_refs_would_exceed(src_refs, dst_refs, refs_max): the src ends up
with the sum of the two counts, so reject when that sum exceeds the ceiling
(landing exactly on it is allowed).  Both process_candidate sites use it —
Plan A (candidate is the src, m_start the dst) and Plan B (roles swapped, same
symmetric sum).  The Planner-level "reject truncated dst ref list" check stays
binary: it fires before any src candidate exists to sum against.

The additive form also subsumes the old truncation guard: real extents have at
least one reference, so if either side is already at the ceiling the sum
strictly exceeds it.

test_refs_ceiling_gate pins the boundary (> not >=) and the summation,
including the src-under-limit / dst-many-refs overshoot the binary gate let
through.

Assisted-by: Claude-Code:claude-opus-4-8
src/bees-plan.h
src/bees-scan-next.cc
test/test-bees-plan.cc