Repository navigation
Conversation
9738c6b to
8f5839a
Compare
| #[derive(Clone)] | ||
| enum AddedFragment { | ||
| Present(u64), | ||
| Removed { fresh_row_ids: u64 }, |
There was a problem hiding this comment.
This keeps the row IDs of later staged fragments unchanged when an earlier fragment is removed. An intermediate manifest may already have exposed those IDs.
| fn tombstone_dropped_field(&mut self, field_id: i32, schema: &Schema) -> Result<()> { | ||
| Arc::make_mut(&mut self.dropped_fields).insert(field_id); | ||
| if self.patched.is_empty() { | ||
| return Ok(()); | ||
| } | ||
| let single = BTreeSet::from([field_id]); | ||
| let live = schema_field_ids(schema); | ||
| for patched in self.patched.values_mut().flatten() { | ||
| tombstone_fields_in_fragment(Arc::make_mut(patched), &single, &live)?; | ||
| } | ||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
This applies drops to patched fragments now and defers masking base fragments until they are read or assembled. V1 files keep their field positions until every field in the file has been dropped.
| } | ||
| self.unvalidated = UnvalidatedScope::default(); |
There was a problem hiding this comment.
This scope includes changes from earlier unchecked steps too. We clear it only after validation succeeds so a later checked step cannot overlook them.
| pub fn extend_spilled_row_lineage(&mut self, loaded: &SpilledRowLineage) -> Result<()> { | ||
| if loaded.is_empty() { | ||
| return Ok(()); | ||
| } | ||
| if self.spilled_row_lineage.is_empty() { | ||
| self.spilled_row_lineage = Arc::new(loaded.clone()); | ||
| return Ok(()); | ||
| } | ||
| let mut updates = Vec::new(); | ||
| for (&fragment_id, incoming) in loaded { | ||
| match self.spilled_row_lineage.get(&fragment_id) { | ||
| Some(existing) => { | ||
| let (merged, added) = | ||
| merge_loaded_row_lineage(existing, incoming, fragment_id)?; | ||
| if added { | ||
| updates.push((fragment_id, merged)); | ||
| } | ||
| } | ||
| None => updates.push((fragment_id, incoming.clone())), | ||
| } | ||
| } | ||
| if !updates.is_empty() { | ||
| let map = Arc::make_mut(&mut self.spilled_row_lineage); | ||
| for (fragment_id, merged) in updates { | ||
| map.insert(fragment_id, merged); | ||
| } | ||
| } | ||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
Later steps may need lineage that earlier steps never loaded. Entries can be partial, so this fills missing sequences while preserving existing ones. The caller must load them from the base version.
8f5839a to
7ab301e
Compare
|
Local Criterion benchmarks (
|
wjones127
left a comment
There was a problem hiding this comment.
Thanks Drew, this is a nice step toward staged transactions. Making ApplyState own its state with copy-on-write fragments is a clean way to reuse it across steps, and the benchmarks make a clear case for the incremental path. The per-step snapshot-vs-single-build test gives me a lot of confidence the commit path still produces the same manifest.
Nothing here blocks, since the module is experimental. Encouraged:
- Row id contract (most important). Burned slots keep intermediate row ids stable while staging, but a retry renumbers them. I'd like to settle what callers may rely on before the dataset-level API builds on it.
- API surface. The build config comes in at four places, and
apply_step/validate_step_invariantsduplicateapply_step_checked. Narrowing both would leave one way to do each thing. - Smaller items: a submodule for
WorkingFragments, and a couple of nits.
|
|
||
| /// One fragment this operation added, in the order it was added. | ||
| /// | ||
| /// A removed fragment keeps its slot because an intermediate manifest build may |
There was a problem hiding this comment.
question: What's the contract for row ids a caller sees in an intermediate manifest? This keeps them stable while staging, but on a retry the rebase renumbers them anyway. In the rebase test, the staged fragment's ids move from 1000..1010 to 1010..1020:
lance/rust/lance-table/src/transaction/action/apply.rs
Lines 4017 to 4027 in 7ab301e
So anything a later step persists against those ids (say an index segment over a staged fragment on a stable row id table) would be wrong after a retry. If the staged API will rely on these ids, I think a retry needs to detect that and fail rather than renumber. If it won't, do we need the burned slots at all? They also change the one-shot CompositeOperation path: adding and then removing a fragment in one operation now uses up its row ids.
There was a problem hiding this comment.
yeah this was an important point in the transaction layer anything that reads or depends on intermediate row ids pins read_version so a concurrent commit fails instead of renumbering on retry
we still need the burned slots even without retries though. if step 1 adds frag A, step 2 adds frag B and the caller reads its row ids, and step 3 removes frag A, frag B needs to keep the same row ids in step 3 and the final commit. added a doc note on ApplyState explaining this
c7965e8 to
840f6eb
Compare
7ab301e to
25891e3
Compare
| /// # } | ||
| /// ``` | ||
| #[derive(Clone)] | ||
| pub struct ApplyState { |
There was a problem hiding this comment.
thoughts: I wonder if it would be cleaner to call this the working state of a manifest or dataset like: ManifestWorkingState. Since the functions are technically modifying the state of a manifest
There was a problem hiding this comment.
It's a little long, but I agree it's better than ApplyState. 👍
There was a problem hiding this comment.
thought: A shorter option with the same idea: WorkingManifest. It pairs with WorkingFragments, and .build() would then read well. Your call, though. ManifestWorkingState is also fine.
wjones127
left a comment
There was a problem hiding this comment.
Thanks Drew, this addresses everything I raised. LGTM.
| /// # } | ||
| /// ``` | ||
| #[derive(Clone)] | ||
| pub struct ApplyState { |
There was a problem hiding this comment.
thought: A shorter option with the same idea: WorkingManifest. It pairs with WorkingFragments, and .build() would then read well. Your call, though. ManifestWorkingState is also fine.
840f6eb to
66eb547
Compare
21745ec to
2798da3
Compare
de69e45 to
7acc64d
Compare
Co-authored-by: Drew <[email protected]>
Co-authored-by: Drew <[email protected]>
…patched private Co-authored-by: Drew <[email protected]>
2798da3 to
0394862
Compare
This prepares
ApplyStatefor staged transactions, where each operation needs to see earlier changes before the transaction commits.ApplyStatenow owns its working state and supports applying checked steps and building intermediate manifests. Failed checked steps leave the previous state unchanged. Repeated manifest builds preserve row ID allocations and reservations.Fragment patches and shared bookkeeping avoid copying the base fragment list for every step. Validation tracks changes since the last successful check, and later steps can supply newly loaded spilled row lineage.
The existing
CompositeOperationcommit path uses the same application and manifest building code.Stacked on #11014. The dataset-level staged transaction API follows separately.
note: temporarily pointing to above branch :)
Why incremental state and validation
If each staged step clones the full
Vec<Fragment>and runs a fullbuild_manifestto validate, stagingksteps on an-fragment table costsO(k * n)even when each step only appends or touches a few fragments.WorkingFragmentskeeps base fragments shared behindArcand tracks edits in aBTreeMappatch set (with lazyDropFieldmasking), so cloningApplyStatefor rollback safety and checking touched fragments scales with the staged edits rather than base table size.Testing
git diff --checkcargo fmt --all -- --checkCARGO_INCREMENTAL=0 cargo clippy -p lance-table -p lance --tests --benches --no-deps -- -D warningsCARGO_INCREMENTAL=0 cargo test -p lance-table --libCARGO_INCREMENTAL=0 cargo test -p lance-table --docCARGO_INCREMENTAL=0 cargo test -p lance --lib dataset::tests::dataset_transactionsCARGO_INCREMENTAL=0 cargo test -p lance --lib io::commit::conflict_resolver::tests