Skip to content

feat(blob): implement blob reuse index - #8899

Closed
Xuanwo wants to merge 7 commits into
mainfrom
xuanwo/blob-reuse-index
Closed

Xuanwo wants to merge 7 commits into
mainfrom
xuanwo/blob-reuse-index

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Problem

Blob v2 Packed and Dedicated descriptors use DataFile-local blob IDs. After compaction writes a new DataFile, those descriptors cannot reference immutable sidecars owned by an older DataFile, forcing payload rewrites and preventing precise lifecycle tracking.

Design

See Lance Blob Reuse Index for the complete design and lifecycle model.

Format contract

This adds an optional sparse Blob Reuse Index (BRI) to DataFile. A hit redirects a local blob ID to a terminal (base_id, blob_dir, physical_id) source; a miss retains the existing identity mapping under the containing DataFile stem. The descriptor and sidecar formats remain unchanged, and Packed descriptors continue applying their stored position and size.

A manifest containing BRI metadata sets reader and writer feature flag bit 512. Implementations that do not understand the mapping must reject the current dataset version rather than read an incorrect identity path.

Behavior

Compaction reuses Dedicated sidecars by default. For each terminal physical Packed sidecar reachable from the current snapshot, it computes union_bytes(visible_packed_ranges) / physical_pack_size. Visible ranges are aggregated across DataFiles, BRI sources, fragments, fields, and equivalent base-path aliases; duplicate and overlapping ranges count once. Planning scans descriptors and object metadata without reading payload bytes.

Packed sidecars are reused at or above blob_repack_utilization_threshold and repacked below it; the default is 0.3. A low-utilization pack makes every current fragment that visibly references it a compaction candidate, while the existing source-fragment, source-row, and source-byte budgets bound each plan. Later compactions recompute utilization when only part of a shared pack fits one plan. Setting blob_reuse_index=false materializes managed sidecars instead.

Read, recompaction, cleanup, shallow clone, deep clone, and Rust/Python/Java metadata bindings follow the same physical-reference contract. Deep clone assigns collision-free local sidecar directories, cleanup resolves registered bases by physical store and data-directory identity, and manifest validation rejects conflicting BRI definitions for the same physical DataFile.

Compatibility

Existing datasets and historical versions remain unchanged. BRI can be removed by a complete rewrite that materializes all referenced sidecars. This format change requires the normal PMC vote before merge.

@github-actions github-actions Bot added A-python Python bindings A-java Java bindings + JNI enhancement New feature or request labels Aug 31, 2026
@Xuanwo
Xuanwo changed the base branch from xuanwo/blob-reuse-index-format to main August 31, 2026 15:51
@Xuanwo
Xuanwo marked this pull request as ready for review August 31, 2026 16:16

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Gate recommendation: request changes.

The BRI direction addresses a real compaction limitation, but the durable format proposal and its implementation need separate review and merge stages. Restore the spec-only proposal in #8898, let it complete the PMC format vote, then rebase this PR onto that result so this revision contains only the implementation.

Comment thread protos/table.proto
// Sparse redirects from file-local blob ids to reused Blob v2 sidecars.
// Absent means every Packed or Dedicated blob id resolves below this data
// file's own stem directory.
BlobReuseIndex blob_reuse_index = 8;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new protobuf field makes the PR a format-specification proposal, but this revision also carries the reader, writer, compaction, cleanup, clone, binding, and test implementation. The repository’s format process requires protobuf/docs plus only minimum build-enabling edits in one PMC-voteable PR, with behavior implemented in follow-ups; combining them obscures the durable contract and couples ordinary code review to the 72-hour vote. #8898 already contains this exact spec-only commit but is closed unmerged. Please land that proposal independently, then rebase/drop commit 93c40b3e here so this PR is implementation-only.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Aug 31, 2026
@westonpace

Copy link
Copy Markdown
Member

How does this work with cleanup? Does cleanup need to reference the BRI to understand which blobs are free to delete? What happens if cleanup can delete a data file but that data file's pack files / dedicated blobs are still alive via the BRI?

@Xuanwo

Xuanwo commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

How does this work with cleanup? Does cleanup need to reference the BRI to understand which blobs are free to delete?
Yes. Cleanup treats the BRI as an additional blob-level liveness edge.

While scanning the retained manifest working set, cleanup resolves each BRI source to its effective data directory and records every (blob_dir, physical_id) target as an explicitly referenced blob path. Blob GC checks this set before falling back to the existing parent-DataFile liveness rule.

What happens if cleanup can delete a data file but that data file's pack files / dedicated blobs are still alive via the BRI?

This means the old .lance file can be deleted while any pack file or dedicated blob file referenced by a live BRI remains. For Packed blobs, multiple local IDs may resolve to the same physical ID, so any live mapping retains the entire pack file. A sidecar becomes eligible for deletion only after neither a retained DataFile nor any retained BRI references it. Sources outside the dataset being cleaned are outside that cleanup run’s ownership.

@github-actions github-actions Bot added A-format On-disk format: protos and format spec docs format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). labels Sep 4, 2026
@github-actions

github-actions Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Important

Format specification vote

This PR modifies the Lance format specification, so it requires 3 binding +1 votes from PMC members (excluding the proposer) and a minimum 72-hour voting period, weekends excluded, before it can merge. Vote by approving this PR (+1) or requesting changes (−1, a veto). See the voting process.

Status: ❌ Blocked — vetoed by @wjones127

Approvals (this commit) none (0/3)
Vetoes @wjones127
Voting period elapsed — ended Wed 2026-09-09 09:43 UTC (02:43 PDT)

Updated automatically by the format-spec vote gate, which re-checks every 15 minutes — just voted? Re-check now (press Run workflow; leave the input blank to re-check every open format PR). A PMC member may apply the format-waived label to waive the vote for a trivial edit (typo, wording, formatting).

@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 4, 2026
# Conflicts:
#	java/src/test/java/org/lance/operation/DataReplacementTest.java
#	rust/lance/src/dataset/blob.rs
#	rust/lance/src/dataset/fragment.rs

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Gate recommendation: request changes.

This revision still combines the durable BRI format proposal with its reader, writer, compaction, cleanup, clone, binding, and test implementation. Restore the spec-only proposal in #8898, let it complete the PMC format vote, then rebase this PR onto that result so this revision is implementation-only.

The physical-utilization contract also needs to ensure that repacking a pack with duplicate or overlapping visible ranges cannot increase stored payload bytes.


All visible Packed descriptors that resolve to the same physical object
participate, including descriptors reached through different DataFiles, BRI
sources, fragments, fields, or equivalent base-path aliases. Duplicate and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The union numerator can select a “reclaimable” pack even when repacking grows it. Duplicate and overlapping descriptors count once here, but the rewrite materializes every selected descriptor and the current writer emits each resulting payload independently. For example, a 100-byte pack whose same 1-byte range is referenced 1,000 times has 1% utilization, yet repacking emits about 1,000 payload bytes. Base selection on actual emitted bytes or preserve shared ranges in the output, and cover this permitted case.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Sep 4, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 4, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Sep 4, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 4, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Sep 4, 2026

@wjones127 wjones127 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 for now. I attempted to review, but I'm still confused on how this works. I think you should:

  • First, write up and merge the Blob V2 spec #9014. Having a spec we can reference for how Blobs work in the first place will make this change easier to understand.
  • Second, clean up the prose. Provide examples of the file structure before and after compaction, and before and after cleanup, showing how the references flow through the BRI.


## Scope

A Blob Reuse Index (BRI) is optional metadata on a DataFile. It provides sparse

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: "on a DataFile" is ambiguous. At first I thought it was metadata stored in a data file. But that's wrong; it's in the manifest. I think it could be clear to say something like:

A Blob Reuse Index (BRI) is an optional mapping from ... to ....

Comment on lines +5 to +9
A Blob Reuse Index (BRI) is optional metadata on a DataFile. It provides sparse
redirects from file-local Blob v2 identifiers to existing physical sidecars.
The index applies only to Packed and Dedicated descriptors. Inline payloads
remain in the data file, and External descriptors retain their URI and base-path
semantics.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I think this would be clearer if you gave a brief description of the problem. Something like:

Blob columns are either written inline or in sidecar files. During compaction, inline blobs are always rewritten. Side car files may be rewritten, but the Blob Reuse Index provides an alternative path: keep the existing sidecar files and use the BRI index to route new fragment rows to the old sidecar files. This information can't be written directly in the new data files because ...

Comment thread protos/table.proto
Comment on lines +492 to +496
// Sparse physical-sidecar redirects used by Blob v2 compaction and cloning.
message BlobReuseIndex {
// Non-empty when BlobReuseIndex is present.
repeated BlobReuseSource sources = 1;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue(blocking): the BRI name suggests this will be similar to the FRI, but it's not done the same way. FRI is a system index. It has an index details messsage:

message FragmentReuseIndexDetails {

It's loaded and managed like other indexes.

But the BRI here is a separate structure, entirely different from the index handling. I honestly think that's okay, and potentially good; system indexes can be awkward. However, if we go this route, we shouldn't call it an "index". We don't want it confused with the index system.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could call it BlobSidecarPins instead. The idea being we are 'pinning' certain blob files so they can be re-used, avoiding them being removed by GC when their corresponding fragment is. And having Sidecar in the name makes it clear it's for the sidecar files and not anything else. What do you think of that?

Comment on lines +42 to +45
BRI is an immutable part of physical DataFile identity. If a commit retains the
same `(base_id, path)`, it retains a semantically identical sparse mapping.
Adding, removing, or changing BRI metadata for that identity is invalid. A
writer changes BRI only by writing a new physical DataFile.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: I don't understand what this paragraph means. Could you rewrite this for clarity. Consider using an example.

Comment thread protos/table.proto
Comment on lines +504 to +507
// Strictly increasing output-local blob ids redirected by this source.
RowIdSequence local_ids = 3;
// Physical blob ids aligned positionally with local_ids.
EncodedU64Array physical_ids = 4;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue(blocking): It's unclear what these ids represent. Part of the issue is that we are missing a spec page on Blob V2 (new issue tracking that here: #9014). But I think these could better describe what's in here. Also would like to see considerations for how big these could get. These are encoded arrays, and we wouldn't want them to get too large and bloat the manifest.

@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 4, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Gate recommendation: request changes.

The prerequisite sequence is now clearer. Blob V2 has no canonical format page, while this proposal relies on its Packed and Dedicated descriptor and sidecar semantics. First land the Blob V2 specification tracked in #9014. Then restore #8898 as a standalone BRI format proposal and complete its PMC vote. Finally, rebase this PR so it contains only the implementation.

The physical-utilization contract also still needs to ensure that repacking a pack with duplicate or overlapping visible ranges cannot increase stored payload bytes.

@lance-gatekeeper lance-gatekeeper Bot added K-changes Latest Gatekeeper recommendation requests changes. and removed K-changes Latest Gatekeeper recommendation requests changes. labels Sep 4, 2026
@Xuanwo Xuanwo closed this Sep 21, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-format On-disk format: protos and format spec docs A-java Java bindings + JNI A-python Python bindings enhancement New feature or request format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). K-changes Latest Gatekeeper recommendation requests changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants