Repository navigation
Conversation
7125dc4 to
0d863ec
Compare
0d863ec to
fa9eb26
Compare
❌ 1 Tests Failed:
View the full list of 1 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
fa9eb26 to
e01d601
Compare
| /// Staged snapshots use `u64::MAX` instead. It sits at the top of the detached | ||
| /// range, and detached commits draw again when they land on it. A transaction | ||
| /// or manifest copied from the snapshot keeps this version, so commit rejects it. | ||
| pub const STAGED_VERSION: u64 = u64::MAX; |
There was a problem hiding this comment.
used u64::MAX instead of base_version + 1 so a concurrent commit at base_version + 1 doesn't collide with an open staged scan. detached_version redraws if it ever lands on it.
| }; | ||
| let mut dataset = self.clone(); | ||
| dataset.set_manifest(Arc::new(manifest), location); | ||
| dataset.staged_indices = Some(Arc::new(indices)); |
There was a problem hiding this comment.
reusing Dataset for the staged snapshot so tx.scan() gets the existing query and index path for free. the ensure_published() guards are the price of doing that for now, can split a smaller reader snapshot trait out later.
| } | ||
|
|
||
| fn append_dataset(&mut self) -> Result<Arc<Dataset>> { | ||
| if !self.state.append_context_dirty { |
There was a problem hiding this comment.
blind appends skip building a manifest and reuse append_base. only time the schema changes mid transaction is when a 2.2+ file promotes a legacy blob column, so we rebuild once there and clear the dirty flag.
|
|
||
| // Batch merge takes the minimum read_version, which would mask a | ||
| // STAGED_VERSION transaction mixed with committed ones. | ||
| transactions |
There was a problem hiding this comment.
InsertBuilder::execute_uncommitted needs to run on append_base (which can be a STAGED_VERSION snapshot after scan() or blob promotion), so we block STAGED_VERSION at commit time instead. checking before min(read_version) in execute_batch so it can't hide behind an older committed txn.
| // would remove. | ||
| let commit = CommitBuilder::new(self.base.clone()) | ||
| .with_experimental_composite_operations(true) | ||
| .with_skip_auto_cleanup(true); |
There was a problem hiding this comment.
skipping auto cleanup on staged commits so earlier scanners don't lose files under them. uncommitted files aren't pinned against explicit cleanup though.
|
Important Format specification voteThis 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 — 0 of 3 required approvals
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 |
|
cc: @wjones127 |
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 #7954, #10386, and #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]>
wjones127
left a comment
There was a problem hiding this comment.
Thanks Drew, this is a careful first slice. Blind appends staying rebasable, failed appends leaving the previous snapshot intact, and the concurrency tests all look good.
I'm leaving this as a comment rather than an approval. None of these is a hard blocker, but I'd like to hear your thinking on the pin after scan() and the staged Dataset sentinel before the rest of the stack builds further on them.
thought: Posting this to make something we discussed privately public. Longer term, I'd like StagedTransaction to work purely on metadata. Writers like InsertBuilder / MergeInsertBuilder would return a sealed value (e.g. AppendedFragments) that can only be built by the writer, so it certifies the files exist with the claimed schema. tx.stage(...) would take that, rather than the transaction wrapping each builder and policing its WriteParams. We're deferring that to a follow-up. append(batches) can be kept as a convenience on top of it, so the main thing that would change is append_with_params.
| } | ||
|
|
||
| impl Dataset { | ||
| pub(crate) fn ensure_published(&self) -> Result<()> { |
There was a problem hiding this comment.
suggestion: I wonder if the staged snapshot should be a full Dataset at all. Because it is, every method that reads manifest.version has to opt into this check. So far that's read_transaction, is_stale, has_successor_version, cleanup, delta, create_index, both table-identifier encoders, the filtered-read proto, and three commit paths. Merge insert also needs saturating_add just to avoid overflowing on u64::MAX (in_place.rs, job.rs). The handle is reachable from user code too: the tests get it from create_plan() and FilteredReadExec::dataset(). Whoever adds the next version-sensitive method won't know to check.
I saw you mention splitting out a smaller reader snapshot later. Since #11382 and #11417 build more on this sentinel, could that happen before the stack grows? A type the scan path can read from, but that can't reach the commit and history paths, would make the mistake impossible instead of detected.
| /// Begin an experimental append transaction from this committed version. | ||
| /// | ||
| /// See [`StagedTransaction`]. | ||
| pub async fn begin_transaction(&self) -> Result<StagedTransaction> { |
There was a problem hiding this comment.
question: How do we signal that this is experimental beyond the doc comment? Since we expect to rework how data goes in (see top-level note), I wonder if we should gate it behind a Cargo feature, e.g. #[cfg(feature = "unstable-staged-transactions")] on begin_transaction, so callers have to opt in. Stabilizing later is then just dropping the gate. An opt-in flag like with_experimental_composite_operations would also work.
| /// | ||
| /// Calling this method pins a non-empty commit to [`Self::base_version`], | ||
| /// even if the returned scanner is never polled. | ||
| pub fn scan(&mut self) -> Result<Scanner> { |
There was a problem hiding this comment.
question: Is there a plan for loosening the pin after scan()? Today any scan pins, so a single concurrent commit (another append, compaction, an index optimize) fails the staged commit, and since the transaction is consumed the caller has to rewrite everything. That seems likely to bite read-your-writes workloads on tables with background maintenance.
A few options: pin only when the scanner exposes _rowid/_rowaddr; reserve fragment ids (as reserve_fragment_ids does for compaction) and, for stable row ids, a row id range, so a rebase doesn't renumber; or return the transaction on conflict so it can be retried without rewriting files. The first seems doable here; the rest could be follow-ups, but it'd be good to note the limitation in the docs/PR description.
| // would remove. | ||
| let commit = CommitBuilder::new(self.base.clone()) | ||
| .with_experimental_composite_operations(true) | ||
| .with_skip_auto_cleanup(true); |
There was a problem hiding this comment.
issue(non-blocking): Which files would auto cleanup remove here that an earlier staged scanner still needs? Once this commit lands, the new version references the staged files, and since this is append-only the base's files stay referenced too. So cleanup exposure looks the same as for any reader on an older version. The cost is that a table written only through staged commits never auto-cleans, which is easy to miss.
test_staged_commit_skips_auto_cleanup checks that old versions survive, but no test shows a scanner breaking without the skip. If there's a real case, could we add a test for it? Otherwise I'd keep auto cleanup on.
| #[case::blind(false)] | ||
| #[case::read_dependent(true)] | ||
| #[tokio::test] | ||
| async fn test_concurrent_append_obeys_the_read_contract( |
There was a problem hiding this comment.
praise: Nice test. Crossing blind vs read-dependent with stable vs physical row ids pins down exactly when a staged commit may rebase.
Xuanwo
left a comment
There was a problem hiding this comment.
Please reject transactions whose read_version is STAGED_VERSION at the shared CommitBuilder entry, before resolving the destination. The single-transaction URI path can reach new-dataset publication without the staged check. An unpublished snapshot must never serve as the read version for a published transaction. Please cover both URI and Dataset destinations and assert that rejection leaves published history unchanged.
Two public API details also need updating. A blind staged append uses CompositeOperation, so a concurrent ordinary Append produces RetryableCommitConflict. Please document that limit on rebasing and cover the mixed-writer case. Also, commit_with() now honors the configured automatic cleanup policy, while the StagedTransaction docs still tell callers to schedule cleanup themselves.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
840f6eb to
66eb547
Compare
…e docs Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: Drew <[email protected]>
Co-authored-by: Drew <[email protected]>
…patched private Co-authored-by: Drew <[email protected]>
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]>
Co-authored-by: Drew <[email protected]>
Co-authored-by: Drew <[email protected]>
…ate docs Co-authored-by: Drew <[email protected]>
1fc1653 to
ccc7d65
Compare
There was a problem hiding this comment.
The publication and documentation concerns are addressed for Lance commits: staged read versions are rejected before destination resolution, including new-dataset URI paths, and the docs now describe ordinary-append conflicts and configured automatic cleanup.
With background writers, an ordinary Append still conflicts with a blind staged append, and after scan() any intervening commit causes a conflict. These conflicts consume the transaction, so repeating the work requires a fresh transaction.
Unpublished files and borrowed blob objects remain unpinned. Coordinate cleanup with active transactions and scanners: removing aged staged files or a blob's last committed reference can leave a later commit pointing at missing data.
de69e45 to
7acc64d
Compare
Summary
Adds an experimental staged transaction API using Transaction V2.
This adds
Dataset::begin_transaction()andStagedTransactionfor staging multiple appends into a single atomic dataset version. Eachappend/append_streamwrites uncommitted data files viaInsertBuilder::execute_uncommitted*and applies the resultingAddFragment/AddDataFileactions to an in-memoryApplyState. Failed or rejected appends leave the previous working state intact, andabort(self)consumes the handle without deleting files so any already-created scanners can finish reading.Blind appends never build an intermediate manifest snapshot and can rebase over concurrent commits at
commit(). Callingscan()lazily builds an uncommitted snapshot tagged withSTAGED_VERSION(u64::MAX), holds its ownArc<Dataset>so earlier scanners survive subsequent appends, and pins publication tobase_versionso row IDs and addresses stay validStacked on #11203.
Example
How staging and publication work
Implementation
InsertBuilder::execute_uncommittedto write files without committing.CommitBuilderto publish the accumulated actions as one version.Failed statements leave the previous snapshot intact. Abort is logical, with uncommitted files left for normal cleanup.
Current scope
cleanup_old_versions/delete_unverifiedcalls (files older than 7 days can still be swept). Staged commits skip auto-cleanup so outstanding scanners keep working.Testing
git diff --check feat/reusable-apply-state..HEADcargo fmt --all -- --checkCARGO_INCREMENTAL=0 cargo clippy -p lance --tests --benches --no-deps -- -D warningsCARGO_INCREMENTAL=0 cargo test -p lance --lib dataset::stagedCARGO_INCREMENTAL=0 cargo test -p lance --lib dataset::tests::dataset_blob::test_stagedCARGO_INCREMENTAL=0 cargo test -p lance --lib dataset::tests::dataset_transactions::test_stagedCARGO_INCREMENTAL=0 cargo test -p lance --lib io::exec::table_identifier::testsCARGO_INCREMENTAL=0 cargo test -p lance --lib io::commit::tests::test_detached_commit_draws_again_on_the_staged_versionCARGO_INCREMENTAL=0 cargo test -p lance --doc dataset::staged