]> git.hungrycats.org Git - bees/commitdiff
scan-next: dump planner trace state on NO Dedup
authorZygo Blaxell <bees@furryterror.org>
Tue, 1 Sep 2026 21:00:20 +0000 (17:00 -0400)
committerZygo Blaxell <bees@furryterror.org>
Sat, 10 Oct 2026 19:00:05 +0000 (15:00 -0400)
A dedupe miss (FIDEDUPERANGE returning BTRFS_SAME_DATA_DIFFERS) means
the planner paired two ranges whose data does not match.  Today the
only record of that event is the one-line "NO Dedup!" log entry,
which names the file offsets but nothing about how the planner
composed the pair.  Field reports of dedupe failures on identical,
inactive files therefore arrive with no actionable planner state.

Call BeesTracer::trace_now() on the miss path so the caller's live
BEESTRACE stack is dumped at the moment of the miss.  Unlike the
unwind-time dump, this needs no exception, so callers that swallow
the false return still produce a trace.  Misses are rare, so an
unconditional dump per miss is cheap.

Enrich the stack that dump walks with planner state that was
previously invisible:

 - scan_next_execute_pairs: one frame per pair, with the batch index
   and count, so the dump identifies which pair of the batch failed
   and how far the batch had progressed;
 - scan_next_execute_dst_plan: the plan's cost accounting (op counts
   and byte totals), so the dump can be compared against what the
   cost model predicted;
 - scan_next_sweep_join_pairs: the current dst ref and sweep cursor,
   for throws raised while pairs are being manufactured.

Together with the existing lazy plan-tree and materialized-tree trace
frames, every NO Dedup event now emits the full planner context as
long-term field data collection infrastructure.

Assisted-by: Claude-Code:claude-opus-5
Assisted-by: Claude-Code:claude-opus-5-5
src/bees-context.cc
src/bees-scan-next.cc

index 49f4b50de6dfa458dcfce0fe8331f810c3eb9d72..b62f54bbe7e5892edcf6e3957768feae7f8a3ed9 100644 (file)
@@ -268,6 +268,14 @@ BeesContext::dedup(const BeesRangePair &brp_in)
                        } else {
                                BEESCOUNT(dedup_miss);
                                BEESLOGINFO("NO Dedup! " << brp);
+                               // Dump the live trace stack now, while the
+                               // caller's planner state (plan tree, materialized
+                               // src tree, current pair) is still in scope.
+                               // Misses are rare, so an unconditional dump per
+                               // miss is cheap; callers that swallow the false
+                               // return (no throw, no unwind dump) still get a
+                               // full trace this way.
+                               BeesTracer::trace_now();
                        }
 
                        lock.reset();
index fed770ccbb768903b7d1e077a06a5d2b127e526e..7de53f10f63f68300468b9ff3225ced3c3716965 100644 (file)
@@ -861,8 +861,14 @@ scan_next_sweep_join_pairs(BeesContext &ctx,
                        continue;
                }
 
+               BEESTRACE("sweep_join dst_ref " << di << " of " << dst_refs.size()
+                       << ": " << dst_ref);
+
                uint64_t cursor = dst_ref.begin();
                while (cursor < dst_ref.end()) {
+                       BEESTRACE("sweep_join cursor " << to_hex(cursor)
+                               << " in [" << to_hex(dst_ref.begin())
+                               << ".." << to_hex(dst_ref.end()) << ")");
                        bool covered = false;
                        bool open_failed = false;
                        uint64_t best_overlap_end = cursor;
@@ -976,7 +982,14 @@ scan_next_execute_pairs(const shared_ptr<BeesContext> &ctx,
        const vector<BeesRangePair> &pairs, const string &what)
 {
        BEESNOTE("scan_next dedupe " << what << " " << pairs.size() << " pairs");
+       size_t index = 0;
        for (const auto &pair : pairs) {
+               // One trace frame per pair so a "NO Dedup!" trace dump (or a
+               // mid-loop throw) identifies which pair of the batch failed
+               // and how far the batch had progressed.
+               BEESTRACE(what << " pair " << index << " of " << pairs.size()
+                       << ": " << pair);
+               ++index;
                const auto ok = ctx->dedup(pair);
                if (!ok) {
                        THROW_ERROR(runtime_error, what << " failed for " << pair);
@@ -2977,6 +2990,16 @@ scan_next_execute_dst_plan(const shared_ptr<BeesContext> &ctx,
        BEESTRACE("scan_next dst " << to_hex(dst.bytenr())
                << " plan " << BeesExtentTreeDump(dst_plan.m_plan_tree));
 
+       // Planner accounting for the same dump: what the planner thought this
+       // plan would do.  A "NO Dedup!" trace can then be compared against
+       // the op counts and byte totals the cost model predicted.
+       BEESTRACE("scan_next dst " << to_hex(dst.bytenr())
+               << " cost dedupe_ops " << dst_plan.m_cost.m_dedupe_ops
+               << " copy_ops " << dst_plan.m_cost.m_copy_ops
+               << " hole_ops " << dst_plan.m_cost.m_hole_ops
+               << " matched " << pretty(dst_plan.m_cost.m_matched_bytes)
+               << " copy " << pretty(dst_plan.m_cost.m_copy_bytes));
+
        auto &layer = Borrower::current().layer();
        // Materialize: replace PreCopyExtent with PostCopyExtent.
        auto src_tree = scan_next_materialize_plan_tree(