]> git.hungrycats.org Git - bees/commitdiff
scan-next: drop the phantom U from the plan bar's EOF tail
authorZygo Blaxell <bees@furryterror.org>
Fri, 24 Jul 2026 11:36:50 +0000 (07:36 -0400)
committerZygo Blaxell <bees@furryterror.org>
Sat, 10 Oct 2026 19:00:04 +0000 (15:00 -0400)
The plan-line disposition bar rounded every part's size up to a whole
block so a real sub-block dedupe/copy tail (e.g. a 971-byte final block)
still showed.  That round-up also emitted a spurious "U" for the
sub-block past-EOF unreachable tail the EOF clip inserts: one physical
block rendered as both the data/copy char and a phantom unreachable char,
e.g. "[CU]" with 0d1c0p1u for a single 4K block that is entirely data.

Route the bar through scan_next_region_block_count like the cost metrics:
an unreachable part rounds down, so the sub-block past-EOF tail floors to
zero blocks and drops out of the bar (the C/D/0 char for that block
already represents it), while every other kind keeps rounding up so real
sub-block tails still appear.  Determine the hole part's sub-kind before
counting to pick the rounding.

Display only; no change to planning, cost, or dedupe behavior.  The tail
was already a materialize-time no-op: back_holes gives a past-EOF hole its
own zero temp, and scan_next_make_clipped_file_pair clips every pair to
the files' real i_size, so a dst range at or past EOF yields no
FIDEDUPERANGE.

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

index f4937089c34d93a7d85f35d0981c997db196e7d1..5839c44f0c449ed9eee7e661a5b47c9641a7d8d7 100644 (file)
@@ -2989,11 +2989,27 @@ scan_next_execute_dst_plan(const shared_ptr<BeesContext> &ctx,
        size_t d_count = 0, c_count = 0, p_count = 0, u_count = 0;
 
        for (const auto &part : parts) {
-               // Round up: a sub-block tail (e.g. a 971-byte final block) is a
-               // real dedupe/copy op and must still appear in the count and the
-               // bar.  Plain truncation here floored it to zero blocks and
-               // dropped it from both, producing a spurious "0d0c0p0u []".
-               const uint64_t N = (part.size + BLOCK_SIZE_SUMS - 1) / BLOCK_SIZE_SUMS;
+               // Determine a hole part's sub-kind (unreachable vs zero/prealloc)
+               // up front so the block count can round unreachable regions down,
+               // matching scan_next_region_block_count / scan_next_plan_init.  A
+               // sub-block past-EOF unreachable tail shares its block with the
+               // preceding data/copy part and frees nothing, so it floors to
+               // zero blocks and drops out of the bar — the C/D/0 char for that
+               // block already represents it.  Every other kind rounds up, so a
+               // real sub-block dedupe/copy/hole tail (e.g. a 971-byte final
+               // block) still appears.
+               bool unreachable = false;
+               if (part.kind == BeesTreeExtentKind::hole) {
+                       for (const auto &region : dst_bm->m_regions) {
+                               if (region.m_begin <= part.begin && region.m_end > part.begin) {
+                                       unreachable =
+                                               region.m_state == BeesTreeBlockState::unreachable;
+                                       break;
+                               }
+                       }
+               }
+               const uint64_t N = scan_next_region_block_count(unreachable, part.size,
+                       ranged_cast<uint64_t>(BLOCK_SIZE_SUMS));
                if (N == 0) continue;
 
                int log_len = 0;
@@ -3010,14 +3026,7 @@ scan_next_execute_dst_plan(const shared_ptr<BeesContext> &ctx,
                        c_count++;
                        bar += "C" + string(log_len, 'c');
                } else if (part.kind == BeesTreeExtentKind::hole) {
-                       BeesTreeBlockState state = BeesTreeBlockState::zero;
-                       for (const auto &region : dst_bm->m_regions) {
-                               if (region.m_begin <= part.begin && region.m_end > part.begin) {
-                                       state = region.m_state;
-                                       break;
-                               }
-                       }
-                       if (state == BeesTreeBlockState::unreachable) {
+                       if (unreachable) {
                                u_count++;
                                bar += "U" + string(log_len, 'u');
                        } else {