]> git.hungrycats.org Git - bees/commitdiff
scan-next: abort a dst plan on any error but a missing file
authorZygo Blaxell <bees@furryterror.org>
Sat, 10 Oct 2026 23:07:14 +0000 (19:07 -0400)
committerZygo Blaxell <bees@furryterror.org>
Sun, 11 Oct 2026 00:48:00 +0000 (20:48 -0400)
The executor ran each dst plan under catch_all, which swallowed
Borrower::Dead along with everything else, and treated every failed
dedupe the same way: a DATA_DIFFERS aborted the dst plan, while the
ref-slice build hid every error from a ref's extent data fetch.

Apply one rule everywhere a dst plan executes:

  - ENOENT means the ref's file is gone.  Skip that ref and keep going
    (plan_ref_enoent).

  - DATA_DIFFERS is not an error.  The refs come from the commit root,
    so they lag live data, and a live change is expected.  Keep going
    and let verification count the ref if it survives.

  - Any other error, and a read-only dst, aborts that dst plan
    (plan_dst_abort).  Other dst plans in the same ExtentPlan still run.

  - Borrower::Dead propagates to the planner.

Assisted-by: Claude-Code:claude-opus-5-5
docs/event-counters.md
src/bees-scan-next.cc

index 3f7d0fcbab5b4f0c74c48ebb9fa5cb21c06d046a..853b5549128ebd21b265d8d263ac39f4b570719e 100644 (file)
@@ -370,11 +370,13 @@ The `plan` event group consists of events within the `scan_next` planner: choosi
  * `plan_cover_none_hole`: The coverage search produced no plan because the fixed hole operations alone exceeded `hole-max` or `total-max`.
  * `plan_cover_none_limit`: The coverage search produced no plan because every covering exceeded the operation limits (all paths pruned during the walk).
  * `plan_dedupe_bytes`: Total bytes matched (deduped) across executed dst plans.
+ * `plan_dst_abort`: A dst plan was abandoned during execution by an error other than a missing file (I/O error, read-only dst, invalid dedupe request).  Any pairs it already executed stay done; the dst is not handed to verification.
  * `plan_dst_executed`: One dst plan was executed (data materialized to a tempfile if needed, then deduped) and its extent handed to the verification tracker.
  * `plan_empty`: The winning plan had no dst plans, so execution was a no-op (the do-nothing outcome).
  * `plan_execute`: A non-empty winning plan was executed.
  * `plan_force_rewrite`: The forced FullRewrite floor won selection for a force-marked start extent (the whole extent is rewritten regardless of dedupe benefit).
  * `plan_force_rewrite_unrealizable`: A force-marked start extent could not be rewritten and was left as-is, because no covering fit within the rewrite op limits (`copy-max`, `total-max`, ...). force-rewrite is best-effort: the extent falls back to the do-nothing outcome instead of aborting the scan.
+ * `plan_ref_enoent`: A dst ref was skipped during execution because its file no longer exists.  Expected filesystem churn.
  * `plan_reject_compressed_copy`: A composed plan was rejected because it would copy part of a compressed dst (which fragments compression).  Not counted for force-marked extents, whose filter has lifted the prohibition.
  * `plan_reject_compressed_dedupe`: A composed plan was rejected because it piled more than `compressed-dedupe-max` dedupe ops onto a compressed dst.
  * `plan_reject_copy_max`: A composed plan was rejected because its copy operation count exceeded `copy-max`.
index f391f92de88d06c20f04c919ff658603e04d1d4c..177339d6fce9ee333f5caf9f7733b85c093b80f5 100644 (file)
@@ -793,7 +793,18 @@ scan_next_build_all_ref_slices(BeesContext &, const BeesExtent &extent,
        for (const auto &ref : *raw_refs_sp) {
                BEESTRACE("ref = " << ref);
                if (!ref.extent_offset().has_value() || !ref.ref_bytes().has_value()) {
-                       catch_all([&]() { ref.extent_data_fetch(layer); });
+                       // A ref that no longer exists is skipped.  Any other
+                       // error aborts this dst plan (scan_next_execute).
+                       try {
+                               ref.extent_data_fetch(layer);
+                       } catch (const system_error &e) {
+                               if (e.code().value() != ENOENT) {
+                                       throw;
+                               }
+                               BEESCOUNT(plan_ref_enoent);
+                               BEESLOGDEBUG("scan_next skip dst ref " << ref << ": " << e.what());
+                               continue;
+                       }
                }
                const auto extent_offset = ref.extent_offset();
                const auto ref_bytes_val = ref.ref_bytes();
@@ -995,10 +1006,31 @@ scan_next_execute_pairs(const shared_ptr<BeesContext> &ctx,
                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);
+               bool ok = false;
+               try {
+                       ok = ctx->dedup(pair);
+               } catch (const system_error &e) {
+                       // The file is gone: nothing left to replace.  Every
+                       // other errno aborts this dst plan.
+                       if (e.code().value() != ENOENT) {
+                               throw;
+                       }
+                       BEESCOUNT(plan_ref_enoent);
+                       BEESLOGDEBUG(what << " skip " << pair << ": " << e.what());
+                       continue;
                }
+               if (ok) {
+                       continue;
+               }
+               // A read-only dst can't be replaced; abort.
+               if (ctx->is_root_ro(pair.second.fid().root())) {
+                       THROW_ERROR(runtime_error, what << " dst is read-only: " << pair);
+               }
+               // DATA_DIFFERS.  We can't tell whether the dst changed
+               // under us or the plan was wrong: the refs come from the
+               // commit root and lag the live data.  Live changes are
+               // expected, so keep going; verification finds the ref if
+               // it survives.
        }
 }
 
@@ -3309,12 +3341,19 @@ scan_next_execute(
        }
        BEESCOUNT(plan_execute);
 
-       // Execute each dst plan.
+       // Execute each dst plan.  An error aborts only the dst plan it
+       // occurs in; the pairs it already ran stay done and are not
+       // verified.  Dead restarts the planner.
        for (const auto &dst_plan : plan.m_dst_plans) {
-               catch_all([&]() {
+               try {
                        BEESTRACE("execute dst plan " << dst_plan.m_dst);
                        scan_next_execute_dst_plan(ctx, dst_plan, planner_timer);
-               });
+               } catch (const Borrower::Dead &) {
+                       throw;
+               } catch (const exception &e) {
+                       BEESCOUNT(plan_dst_abort);
+                       BEESLOGDEBUG("scan_next abort dst plan " << dst_plan.m_dst << ": " << e.what());
+               }
        }
 }