Skip to content

feat(dataset): stage add_bases with append and index support - #11417

Open
geruh wants to merge 9 commits into
lance-format:will/transaction-v2-action-constructorsfrom
geruh:staged-add-bases
Open

geruh wants to merge 9 commits into
lance-format:will/transaction-v2-action-constructorsfrom
geruh:staged-add-bases

Conversation

@geruh

@geruh geruh commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Note: This is stacked on #11382. Please review the top commit (1903d5846) since the rest of the branch comes from #11382.

Summary

Adds add_bases to StagedTransaction so you can register new storage bases, append data into them, and build or extend indexes in one atomic commit.

let mut tx = dataset.begin_transaction().await?;

tx.add_bases(vec![
    BasePath::new(0, uri, Some("tier2".into()), true),
])?;

tx.append_with_params(
    batches,
    &WriteParams {
        mode: WriteMode::Append,
        target_base_names_or_paths: Some(vec!["tier2".into()]),
        ..Default::default()
    },
).await?;

tx.create_index(
    &["id"],
    IndexType::BTree,
    None,
    &ScalarIndexParams::default(),
).await?;

let committed = tx.commit().await?;

How it works

flowchart LR
    A["add_bases(bases)"] --> B["AddBase with local base ID"]
    B --> C["append_with_params(target)"]
    C --> D["AddDataFile with Ref::Local(base)"]
    D --> E["commit()"]
    E --> F["Resolve final base IDs"]
Loading

Each new base gets a local ID until commit. Setting append_context_dirty = true makes the next append rebuild the staged snapshot so InsertBuilder can see the new bases by name, path, or target_all_bases.

When stage_append builds the AddDataFile actions, base_reference maps existing bases to Ref::Committed and newly added bases to Ref::Local. It looks through the staged AddBase actions rather than keeping another map in StagedState.

On commit, ApplyState assigns the final base IDs and resolves those references. This also lets the transaction rebase if another writer adds bases first, without rewriting the data or index files.

Per-base storage credentials aren't supported on staged appends yet.

Testing

Tested with stable row IDs on and off. Covers single and batch add_bases, append and append stream, targeting bases by name or path and target_all_bases, index creation and extension, concurrent rebasing of base and fragment IDs, duplicate names and paths, abort, compaction, and index optimization.

wjones127 and others added 8 commits November 17, 2026 17:46
Appends go through the existing insert writer and land as AddFragment
and AddDataFile on the reusable ApplyState. A scan pins publication to
the base version. Appends that were not scanned can rebase. The
uncommitted snapshot uses u64::MAX so commit and maintenance reject it.

Co-authored-by: Drew <[email protected]>
…mat#10780)

This PR adds `local_fragment_aliases` to IndexMetadata and reserves
feature flag `FLAG_LOCAL_FRAGMENT_ALIASES` so index files can keep their
stored fragment IDs when a commit assigns different committed fragment
IDs.

The main use case is committing an append and its index together. If
another writer commits first and changes the assigned fragment IDs, the
retry can update local_fragment_aliases and fragment_bitmap together
instead of rewriting the index files. For example, an index storing (17,
5) can alias 17 -> 42, and a rebase to fragment 43 updates
local_fragment_aliases to {17: 43} and fragment_bitmap to {43}.

Segments that already store committed fragment IDs omit the map. When
present, the map is resolved before the Fragment Reuse Index (FRI).
Writers that reuse existing index files must preserve the map, and
readers must reject any map they cannot interpret.

This PR adds the protobuf definition updates the spec in `index.md`, and
adds a read guard that rejects mapped segments until reader support
lands. The reader and writer feature flag bit is still unassigned.
Writing mapped indexes, applying the map on read, and wiring up index
maintenance will follow in separate PRs.

Related to lance-format#7954, lance-format#10386, and lance-format#10722.

### Testing
- `cargo test -p lance-table --lib`
- `cargo clippy --all-targets -- -D warnings`
- `cargo run --locked --manifest-path protos/codegen/Cargo.toml --
--check`
- `mkdocs build --strict`

---------

Co-authored-by: Drew <[email protected]>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added enhancement New feature or request A-python Python bindings A-index Vector index, linalg, tokenizer A-java Java bindings + JNI A-format On-disk format: protos and format spec docs A-namespace Namespace impls format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). and removed enhancement New feature or request labels Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 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), at least one of them on the latest commit, 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.

Approvals carry over across pushes, so a rebase or a typo fix does not send everyone back to re-vote. Whoever approves the latest commit is vouching that nothing substantive has changed since the earlier approvals; if something has, ask for fresh votes.

Status: ❌ Blocked — 1 of 3 required approvals

Approvals @Xuanwo (1/3)
Latest commit approved by @Xuanwo
Vetoes none
Voting period elapsed — ended Thu 2026-11-26 19:40 UTC (11:40 PST)

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[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 23, 2026

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @geruh for working on this!

I left a blocking comment on staged base-ID remapping for Blob v2 descriptors. Alongside fixing that invariant, could we also add regression coverage for both Managed and External Blob v2 descriptors verifying either that the original bytes are returned after reopen or that a conflicting commit fails explicitly, while keeping nonconcurrent use working?

Comment on lines +435 to +451
actions.extend(actions_for_appended_fragment(
Ref::Local(local_id),
fragment,
|base_id| self.base_reference(base_id),
)?);
}
let step = UserStep::new("append", actions);
let pins_base_version = step_pins_base_version(&step, &self.base.manifest)?;
let promotes_legacy_blob =
step_promotes_legacy_blob(&self.state.append_base.manifest.schema, &step.actions);
let next_working = self.state.working.apply_step_checked(&step)?;
self.state.working = next_working;
self.state.steps.push(step);
self.state.staged_dataset = None;
self.state.append_context_dirty |= promotes_legacy_blob;
self.state.next_local_fragment_id = next_local_fragment_id;
self.state.requires_original_version |= pins_base_version;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

DataFile.base_id is remapped through transaction-local base references on commit, while already persisted Managed and External Blob v2 descriptors (including an external descriptor stored in a primary data file) can retain the staging-time numeric base ID. On replay, this can commit a manifest inconsistent with its immutable data.

Could we preserve the blob-to-base binding across replay, or use the existing requires_original_version guard where safe replay cannot be guaranteed?

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 24, 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 Nov 24, 2026
@github-actions github-actions Bot added the enhancement New feature or request label Nov 24, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 24, 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: approve.

The version guard addresses the Blob v2 base-binding finding: affected blob appends now reject a conflicting commit, while nonconcurrent commits preserve the intended bytes after reopen.

Please mark this PR with the breaking-change label: lance_table::format::IndexMetadata and lance_table::format::pb::IndexMetadata gained the required local_fragment_aliases field, so Rust callers constructing either with struct literals must initialize it.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 24, 2026
@wjones127
wjones127 force-pushed the will/transaction-v2-action-constructors branch 2 times, most recently from de69e45 to 7acc64d Compare December 1, 2026 19:11

This branch has not been deployed

No deployments
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-index Vector index, linalg, tokenizer A-java Java bindings + JNI A-namespace Namespace impls 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-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants