Repository navigation
fix(blob): deduplicate managed reference scans during cleanup - #9435
Merged
Merged
Conversation
Xuanwo
added a commit
that referenced
this pull request
Oct 7, 2026
Blob v2 compaction currently copies Packed and Dedicated payloads because their descriptors address sidecars through the containing data file. Managed descriptors carry a relative URI, byte range, and optional registered base ID, allowing compaction to preserve payload objects when replacing data files. New payload objects use `_blobs/<uuid>.blob`. Existing Packed and Dedicated objects can be adopted at their original paths without copying bytes, including when their original data files are later removed. Cleanup follows references from protected table versions. The default table base stays implicit, so moving the complete dataset does not retain its old URI. Shallow clone preserves the source base through existing data-file metadata. Deep clone copies local objects at the same relative paths without rewriting their descriptors; references to registered bases are copied and rebound into the destination. Managed uses the existing five descriptor fields in both file formats 2.2 and 2.3. Kind 4 uses the implicit table base; kind 5 carries an exact registered base ID, preserving IDs such as zero in existing shallow clones without changing descriptor nullability. Writer-side `base_id=None` selects the implicit base. Explicit IDs must already exist; writes do not register bases automatically. New Blob data-file commits publish paired reader/writer table capability bits. The capability survives restore; metadata-only updates to an old table do not activate it. Existing kinds retain their read semantics. This adds no user configuration or repack API. Compatibility validation uses a checked-in v11.0.0 Packed/Dedicated fixture. The released v11.0.0 client refuses normal opens of flagged snapshots. A real cached-handle experiment also confirms the boundary: after new-client compaction and cleanup remove the original data files, old-client GC with `delete_unverified=True` can still delete adopted sidecars, while leaving `_blobs` objects alone. Before activation, upgrade all maintenance clients to a Managed-aware version or stop their maintenance tasks. All maintenance after activation must use a Managed-aware client; the flag blocks normal opens of flagged snapshots but cannot revoke pre-existing handles or retrofit old binaries' historical maintenance paths. Cleanup still rescans descriptors shared across metadata-only versions. Scan deduplication is deferred to #9435 for separate design review. Regression coverage moves complete tables containing both new Managed objects and adopted released sidecars, removes the original location, then scans, reads, and runs cleanup at the new location. Clone coverage checks source retention after compaction, registered-base rebinding, and byte-for-byte preservation of local data files during deep clone. Prepared writes reject unknown bases, including nested Blob columns. The format-spec proposal remains separate, as required by the repository's spec/implementation workflow. Related: #8899 addresses the compaction problem through a Blob Reuse Index; #9193 documents the existing Blob v2 contract. ## Benchmark At the benchmarked revision, Managed kept total write amplification close to 1x through ten compactions, with approximately unchanged full-scan and random-read performance on the tested workloads. Benchmarked revision: `f7dec16f659f758d2b7b302513501975767fda78`; historical baseline: `400408ffb7ee6b7bbf7c240962b5a94fb5fef879`. Runs used one dedicated EC2 **c7i.24xlarge** (96 vCPUs, 192 GiB RAM) and same-region S3 in **us-east-2**, Rust 1.97.0, `release-with-debug` with thin LTO, and 48 CPU/runtime threads. Both builds used identical dependency locks and CPU flags (`haswell`, `+avx2,+fma,+f16c`). Data uses deterministic high-entropy payloads in format 2.2. An explicit 8 KiB inline threshold and 512 KiB Dedicated threshold select the requested layouts; the production Dedicated default is 4 MiB. These measurements apply only to the pinned revision above. Subsequent changes include upstream BlobFile buffering/read changes, dependency updates, and portable Managed base resolution. The numbers have not been revalidated for the current head and are retained as historical evidence, not a current-head performance claim. Cleanup scan deduplication remains in draft follow-up #9435 and is outside these measurements. ### Write amplification For each payload size, append **10,000 rows** at a time to **1,000,000 rows**, compacting the accumulated table into one fragment after every additional **100,000 rows**. No garbage collection runs. Total written bytes include appends, all ten compactions, descriptors and metadata; submitted write bytes were cross-checked against the retained S3 inventory. GB below is decimal. | Payload/layout | Logical input | Total written by this PR | Write amplification | |---|---:|---:|---:| | 100 KiB packed | 102.400 GB | 102.672 GB | 1.002653x | | 1 MiB Dedicated | 1,048.576 GB | 1,048.948 GB | 1.000355x | Retained payload bytes equal logical input bytes for both cases: compaction did not rewrite the payloads. The historical full ingestion/compaction workflow was not measured, so these are candidate measurements, not a measured old/new write-amplification ratio. ### Full-column scans Read the entire blob column, including every payload and its checksum. Use 16 MiB logical batches, batch/fragment readahead 16, fresh processes, one excluded warmup per version, and **three alternating old/new pairs**, with no concurrent writes or other scans. Both versions read identical 1M-row contents. The candidate uses its actual final compacted tables. Baseline final tables were generated directly with the old compaction writer's batch/row-group settings; a small preflight checked payload sizes, layout kinds and full contents against real old compaction output. This compares final-table reads and does not replay the old write workflow. Packed has 96 old versus 100 new payload objects; Dedicated has 1M in each version. | Payload/layout | Old median GB/s (range) | New median GB/s (range) | Median paired throughput change | |---|---:|---:|---:| | 100 KiB packed | 0.836 (0.832–0.875) | 0.834 (0.826–0.841) | -1.22% | | 1 MiB Dedicated | 0.620 (0.580–0.644) | 0.626 (0.597–0.643) | +0.88% | ### Random access: take 10 complete blobs Reuse those same final tables. Each request selects ten distinct random row indices, calls `take_blobs_by_indices`, and concurrently reads all ten `BlobFile` payloads. Request batches are serial. Timing includes descriptor lookup, payload reads and checksum hashing; dataset open and expected-content generation are excluded. Each process reuses its dataset session, excludes ten warmup requests, then measures 100 requests. **Five alternating pairs** give **500 measured requests per version/layout**, with matching random indices within each pair. Every returned payload and its row order were validated. This measures reused sessions; payload caches were not explicitly flushed. | Payload/layout | Old P50 / P95 latency | New P50 / P95 latency | Median paired P50 latency change | |---|---:|---:|---:| | 100 KiB packed | 157.03 / 220.27 ms | 157.81 / 212.53 ms | +0.05% | | 1 MiB Dedicated | 149.97 / 193.99 ms | 149.59 / 187.05 ms | +0.61% | Latency percentiles use nearest-rank over the 500 requests. Paired changes use the median of within-pair new/old ratios (round P50s for random reads), not ratios of the aggregate table medians. Lower latency is better. These small differences do not establish a sustained read improvement or regression; results describe this configuration rather than a hardware throughput ceiling. Raw commands, checksums, timings, binary hashes and exact dependency locks are retained in the private benchmark project.
Xuanwo
marked this pull request as ready for review
October 7, 2026 21:05
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
BubbleCal
approved these changes
Oct 8, 2026
Xuanwo
added a commit
that referenced
this pull request
Oct 8, 2026
#9777) Managed Blob capability transitions and cleanup scan reuse need durable regression coverage after #9293 and #9435. These tests cover activation on new Blob files, preservation after removing Blob columns, coexistence with base-path and mixed-version flags, and cleanup retention across deletions, projections, tags, and branches. Concurrent scan requests must share one scan per retention class; failed descriptor reads must not publish successful completion or permit unsafe deletion. The cross-version tests use released v11.0.0 and v13.0.0 clients to create Packed/Dedicated data, verify metadata-only updates remain readable, and check that adoption and subsequent restore fence old opens and appends. Historical unflagged reads remain allowed; this does not promise safety for old cached-handle maintenance. Both release checks passed locally through the existing subprocess runner using ordinary CPython 3.14 for the released abi3 wheels. No production behavior changes. The larger Blob v2 specification remains in #9193.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cleanup repeatedly scans Managed Blob descriptors when table versions share the same fragment view. This change records successful scans separately for retained and expired versions and adds discovered paths directly to the existing cleanup sets. Each view is scanned at most twice per cleanup, without retaining a separate copy of its full reference set.
The scan identity includes fragment metadata (including deletions and overlays), projected fields and base bindings. It uses the implicit and registered base semantics from #9293. Branch retention shares the same inspection state; failed reads are never recorded as successful scans. A missing expired descriptor can be skipped, while a missing retained descriptor still stops cleanup before deletion.
Benchmark
Compared main
84d1681e07af565837f2d97e72ff1b8b040cd15cwith this PR at9738f9ef767307f3e4695695b8d3915189d06f41. Each case contains 100,000 real Managed objects. Metadata-only versions share two descriptor files; compaction cases replay cumulative appends followed by 8 or 32 compactions (24 or 96 table versions).The measured workflow is
dataset.cleanup(policy).with_max_candidate_files(0).explain(), retaining the latest version and selecting older versions for cleanup. This measures inspection and file listing, without deleting files, so both versions use identical inputs. The 64-byte Dedicated payloads isolate descriptor work; cleanup does not read payload contents. Every latest payload was separately verified.One Apple M4 Max / 128 GiB / local APFS host, Rust 1.98.1, identical dependency lock and
release-with-debugbuilds, eight CPU/I/O/runtime threads. Each version has an excluded warmup followed by five alternating pairs in fresh processes, with warm OS caches and no concurrent builds or dataset writes. Values below are medians; RSS includes dataset opening but excludes generation and payload validation.Median paired elapsed-time reductions are 49.6%, 95.4%, 45.8% and 60.5%, respectively. For 128 metadata-only versions, elapsed ranges are 14.553–15.469 s on main and 0.683–0.717 s on this PR. For 32 compactions they are 5.873–6.224 s and 2.319–2.493 s. These results cover local cleanup inspection, not S3 performance or the final deletion phase. Global path sets and metadata for distinct fragment views still consume memory.
All paired cleanup removal statistics matched. Separate execution probes cover actual deletion, tagged and branched retention, dropped Blob columns and missing retained descriptors. Commands, all ranges, raw paired measurements, build hashes and dependency locks are preserved in the private benchmark project; the additional probes are standalone evidence, not new public CI coverage. The September S3 scan benchmarks in #9293 do not measure this change.