Repository navigation
Conversation
📝 WalkthroughWalkthroughChangesTransaction spill handling
Estimated code review effort: 3 (Moderate) | ~30 minutes Sequence Diagram(s)sequenceDiagram
participant commit_transaction
participant inline_transaction_config
participant write_transaction_file
participant write_manifest_file
commit_transaction->>inline_transaction_config: evaluate encoded transaction size
inline_transaction_config->>commit_transaction: return inline decision and write config
commit_transaction->>write_transaction_file: write oversized transaction externally
commit_transaction->>write_manifest_file: pass inline transaction or None
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (5)
rust/lance/src/dataset/tests/dataset_transactions.rs (3)
729-763: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTest utility helpers missing
#[cfg_attr(coverage, coverage(off))].
large_props,spill_test_batch, andreopenare test utilities, not test functions themselves.As per coding guidelines: "disable coverage for test utilities with
#[cfg_attr(coverage, coverage(off))]."🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rust/lance/src/dataset/tests/dataset_transactions.rs` around lines 729 - 763, Apply #[cfg_attr(coverage, coverage(off))] to the test utility functions large_props, spill_test_batch, and reopen. Do not change their behavior or add the attribute to unrelated test functions.Source: Coding guidelines
733-733: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMove
usestatements to the top of the file.Several new test functions declare
useinside the function body (large_propsat Line 733;test_large_transaction_spills_to_external_fileat Lines 768-770;test_spilled_restore_and_deep_clone_read_own_transactionat Line 889).As per coding guidelines: "Place
useimports at the top of the file, not inline within function bodies."Also applies to: 768-770, 889-889
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rust/lance/src/dataset/tests/dataset_transactions.rs` at line 733, Move the inline MAX_INLINE_TRANSACTION_BYTES and related imports from large_props, test_large_transaction_spills_to_external_file, and test_spilled_restore_and_deep_clone_read_own_transaction to the file-level use section. Remove the function-local use statements while preserving all existing test behavior.Source: Coding guidelines
742-754: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
record_batch!()instead of manualSchema/RecordBatch::try_newboilerplate.
spill_test_batchmanually builds anArrowSchemaand callsRecordBatch::try_new.As per coding guidelines: "Use
record_batch!()fromarrow_arrayto constructRecordBatchin tests instead of manualSchema/Arc/try_newboilerplate."♻️ Proposed simplification
-fn spill_test_batch() -> (Arc<ArrowSchema>, RecordBatch) { - let schema = Arc::new(ArrowSchema::new(vec![ArrowField::new( - "i", - DataType::Int32, - false, - )])); - let batch = RecordBatch::try_new( - schema.clone(), - vec![Arc::new(Int32Array::from_iter_values(0..10))], - ) - .unwrap(); - (schema, batch) -} +fn spill_test_batch() -> (Arc<ArrowSchema>, RecordBatch) { + let batch = record_batch!(("i", Int32, (0..10).collect::<Vec<_>>())).unwrap(); + (batch.schema(), batch) +}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rust/lance/src/dataset/tests/dataset_transactions.rs` around lines 742 - 754, Update spill_test_batch to construct the test batch with arrow_array’s record_batch!() macro, removing the manual ArrowSchema, Arc, and RecordBatch::try_new setup while preserving the "i" Int32 non-null column and values 0..10. Return the macro-produced batch together with its schema as required by the function signature.Source: Coding guidelines
rust/lance/src/io/commit.rs (2)
140-158: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDoc comment on the threshold doesn't explain why 64KiB was chosen.
The comment states what the constant does but not the rationale for the specific value (e.g. tied to the manifest-size reduction goal mentioned in the PR description).
As per coding guidelines: "Add doc comments to magic constants, thresholds, and non-obvious transformation functions, explaining what the value represents and why it was chosen."
📝 Proposed doc update
-/// Transactions serialized above this size are not inlined into the manifest. +/// Transactions serialized above this size are not inlined into the manifest +/// and are written only to the external transaction file. 64 KiB was chosen +/// to bound manifest size growth while keeping the vast majority of everyday +/// transactions (e.g. simple appends/deletes) inline. pub(crate) const MAX_INLINE_TRANSACTION_BYTES: usize = 64 * 1024;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rust/lance/src/io/commit.rs` around lines 140 - 158, Update the doc comment for MAX_INLINE_TRANSACTION_BYTES to explain both that it limits inline transaction serialization and why the 64 KiB threshold was selected, referencing the intended manifest-size reduction goal. Keep inline_transaction_config behavior unchanged.Source: Coding guidelines
140-158: 🚀 Performance & Scalability | 🔵 Trivial | ⚖️ Poor tradeoffTransaction is protobuf-encoded twice per commit attempt.
inline_transaction_configencodestransactionjust to measure its size; the caller then re-encodes it again insidewrite_transaction_fileand/ordo_write_manifest. For large transactions (the exact case this threshold targets) this duplicates non-trivial serialization work on every commit attempt.Threading the already-computed
pb::Transaction/byte length through to the writer would avoid the second encode, but toucheswrite_transaction_file,build_manifest, anddo_write_manifestsignatures — likely not worth it unless profiling shows this matters.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rust/lance/src/io/commit.rs` around lines 140 - 158, The transaction is protobuf-encoded in inline_transaction_config and then encoded again by the commit writers. Reuse the already computed pb::Transaction or encoded bytes through write_transaction_file, build_manifest, and do_write_manifest so each commit attempt serializes the transaction only once, while preserving the inline-size decision and external-file behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@rust/lance/src/dataset/tests/dataset_transactions.rs`:
- Around line 729-763: Apply #[cfg_attr(coverage, coverage(off))] to the test
utility functions large_props, spill_test_batch, and reopen. Do not change their
behavior or add the attribute to unrelated test functions.
- Line 733: Move the inline MAX_INLINE_TRANSACTION_BYTES and related imports
from large_props, test_large_transaction_spills_to_external_file, and
test_spilled_restore_and_deep_clone_read_own_transaction to the file-level use
section. Remove the function-local use statements while preserving all existing
test behavior.
- Around line 742-754: Update spill_test_batch to construct the test batch with
arrow_array’s record_batch!() macro, removing the manual ArrowSchema, Arc, and
RecordBatch::try_new setup while preserving the "i" Int32 non-null column and
values 0..10. Return the macro-produced batch together with its schema as
required by the function signature.
In `@rust/lance/src/io/commit.rs`:
- Around line 140-158: Update the doc comment for MAX_INLINE_TRANSACTION_BYTES
to explain both that it limits inline transaction serialization and why the 64
KiB threshold was selected, referencing the intended manifest-size reduction
goal. Keep inline_transaction_config behavior unchanged.
- Around line 140-158: The transaction is protobuf-encoded in
inline_transaction_config and then encoded again by the commit writers. Reuse
the already computed pb::Transaction or encoded bytes through
write_transaction_file, build_manifest, and do_write_manifest so each commit
attempt serializes the transaction only once, while preserving the inline-size
decision and external-file behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: QUIET
Plan: Pro Plus
Run ID: d903656c-fd22-45bc-b9ab-457f77791b88
📒 Files selected for processing (4)
rust/lance-table/src/io/manifest.rsrust/lance/src/dataset.rsrust/lance/src/dataset/tests/dataset_transactions.rsrust/lance/src/io/commit.rs
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Hi @wjones127 Could you take some time to look into this issue? In scenarios with large volumes of data, such as when we write more than 100,000 fragments in a single batch, the abnormal Manifest size issue may still be worth resolving. |
wjones127
left a comment
There was a problem hiding this comment.
I think we need to decide on what the threshold is. 64KB seems very low. What are we optimizing for here?
| transaction: &Transaction, | ||
| write_config: &ManifestWriteConfig, | ||
| ) -> (bool, ManifestWriteConfig) { | ||
| let inline = pb::Transaction::from(transaction).encoded_len() <= MAX_INLINE_TRANSACTION_BYTES; |
There was a problem hiding this comment.
suggestion: it would be nice if we didn't have to do pb::Transaction::from twice. IIRC there's probably a meaningful amount of work that has to do with mapping Vec<Fragment> to Vec<pb::Fragment>. Maybe this function could take in pb::Transaction as a parameter instead?
There was a problem hiding this comment.
changed. Now only one conversion via pb::Transaction::from is required
| pub fn with_transaction_file_enabled(&self) -> Self { | ||
| Self { | ||
| disable_transaction_file: false, | ||
| ..self.clone() | ||
| } | ||
| } |
There was a problem hiding this comment.
question: why do we need this? It seems like none of the other fields have setters or getters. (Except for disable_transaction_file, which also seems unnecessary.)
There was a problem hiding this comment.
removed. It was previously considered for compatibility. Upon closer inspection, this parameter is inaccessible externally and has been removed.
| } | ||
|
|
||
| /// Transactions serialized above this size are not inlined into the manifest. | ||
| pub(crate) const MAX_INLINE_TRANSACTION_BYTES: usize = 64 * 1024; |
There was a problem hiding this comment.
question(blocking): This seems very low to me. What made you choose it? I would have chosen something in the range of 1–20MB, intuitively.
There was a problem hiding this comment.
Initially, my main criterion was the manifest open path's single 64 KiB last-block read: everything — the manifest, and the inline transaction along with it — can be picked up in that one read. That said, if we look at it purely from the angle of keeping the manifest small, something in the 20 MB range is also a reasonable value.
There was a problem hiding this comment.
my main criterion was the manifest open path's single 64 KiB last-block read: everything — the manifest, and the inline transaction along with it — can be picked up in that one read.
Yeah, part of the reason we wanted to move the transaction file into the manifest file was this optimization. The other one was that we would only require one IOP to commit a transaction instead of two (one for txn file, one for manifest).
The inline-threshold check built a full pb::Transaction (deep-copying fragments and properties) just to measure encoded_len, then discarded it; the external transaction file write and the inline manifest write each converted again. Convert once per commit attempt and reuse it for all three, threading pb::Transaction through write_transaction_file and write_manifest_file.
A failed commit's reported error can mask a commit that actually landed (lost ack): the manifest was written but the response never reached the client. Since large transactions are no longer inlined, the external .txn file is the landed version's only transaction record, and deleting it on failure permanently breaks read_transaction and any rebase across that version. Cleanup now deletes the file only when that cannot destroy a landed version's record: inlined transactions keep a redundant copy in the manifest, so their file is always deleted; spilled transactions keep the file unless probing the target version confirms nothing landed. After a commit conflict the attempted version exists and may be our own lost-ack commit, so the file is kept and orphans are left to GC.
| // No inline copy is written to this file. Clear any offset inherited | ||
| // from a previous manifest (e.g. via restore or clone), which would | ||
| // otherwise point at arbitrary bytes of the file being written. | ||
| manifest.transaction_section = None; |
There was a problem hiding this comment.
praise: This is a good safeguard
| inlined: bool, | ||
| verify_version: Option<u64>, | ||
| naming_scheme: ManifestNamingScheme, |
There was a problem hiding this comment.
issue(blocking): this expands this function's responsibilities from cleaning up a transaction file to deciding whether it is safe to. I think that decision should live somewhere else, not here.
IIUC, this is design for the case where object storage returned 500 but the manifest was actually written anyways, right? If so, I wonder if we should move the handling of that case to the error handler of the manifest put.
There was a problem hiding this comment.
Good point — I moved the safety check into the manifest commit error-handling path, so cleanup_transaction_file is once again limited to best-effort deletion.
There was a problem hiding this comment.
Update:Removed the branch's custom transaction-file cleanup guard since main's verify_commit_outcome (#7722) already covers it with a stronger commit-outcome check.
…transaction-final # Conflicts: # rust/lance/src/io/commit.rs
There was a problem hiding this comment.
note: Not related to this PR, but there's also a bug with the index_section we should fix in a follow up as well.
… manifest (#9915) ## Problem `Dataset::read_version_transaction(version)` always resolves the version location and reads and decodes the full manifest. It does this even when the handle is already checked out at that version or the session cache already holds that manifest. On tables with millions of fragments the manifest is over a gigabyte, so each call downloads it again. ## Change 1. When `version == self.manifest.version`, use the in-memory manifest and the same `TransactionKey` cache path as `read_transaction()`. 2. Otherwise resolve the location. When the location carries a known size (so its e_tag is trustworthy), look up the shared `ManifestKey` cache before falling back to `read_manifest`. 3. The fallback path is unchanged: branch check and `DatasetNotFound` mapping. ## Tests `test_read_version_transaction_same_version_skips_manifest_read` (4 IOPs → 1) and the updated `test_inline_transaction` both fail on main and pass with this change. Works with the transaction cache warm-up (#7740) and the external transaction spill (#7881). --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
Closes: #7961
Problem
On a wide table (300 columns, 800k fragments, 80k fragments per write) the manifest is unexpectedly large. Measuring the physical layout:
Why inlining a large transaction has no benefit
The most read-side benefit of the inline copy is riding along with the manifest read:
read_manifestprefetches one object-store block from the file tail (64 KiB by default on cloud stores), and reading the transaction costs zero extra requests only when the length prefix, the transaction, the manifest message, and the footer all fit in that window. Fitting under 64 KiB is therefore a necessary condition for the benefit: a larger transaction can never fit, so readers pay a separate ranged GET either way — exactly the cost of reading the external transaction file. Meanwhile the costs remain:_transactions/file is written by default anyway, so the inline copy is pure redundancy.Change
MAX_INLINE_TRANSACTION_BYTES = 64 KiB: transactions whose serialized size exceeds it are no longer inlined and are written only to the external transaction file; readers use the existing fallback. The threshold is the bound above which the ride-along benefit is provably zero, so spilling only cuts cases with no benefit and never affects a transaction that could have one; transactions at or below it are inlined as before, with the inline cost bounded by 64 KiB.Impact
For the workload above: the full-commit manifest shrinks from 1576 MiB to ~790 MiB (-50%); each 80k-fragment append manifest shrinks ~8%; conflict retries upload half the bytes — the manifest no longer carries the transaction, though the external file is still rewritten per attempt. No new configuration; behavior for small transactions — the overwhelming majority — is unchanged. Spilled transactions remain safe against cleanup: it treats
manifest.transaction_fileas a referenced path, so the only copy is retained for as long as the manifest that references it.