Skip to content

perf(dataset): spill large inline transaction out of manifest - #7881

Merged
wjones127 merged 12 commits into
lance-format:mainfrom
zhangyue19921010:spill-large-inline-transaction-final
Aug 5, 2026
Merged

wjones127 merged 12 commits into
lance-format:mainfrom
zhangyue19921010:spill-large-inline-transaction-final

Conversation

@zhangyue19921010

@zhangyue19921010 zhangyue19921010 commented Jul 21, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #7961

Problem

On a wide table (300 columns, 800k fragments, 80k fragments per write) the manifest is unexpectedly large. Measuring the physical layout:

  • A single 800k-fragment commit produces a 1576 MiB manifest, of which the inline transaction section is 786.6 MiB (49.9%). The transaction carries the full fragment metadata of the commit, nearly byte-for-byte identical to the manifest's own fragment list — the same data is stored twice in one file.
  • Every subsequent 80k-fragment append carries a 78.7 MiB (~8%) inline section as well.

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_manifest prefetches 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:

  • the manifest PUT on the commit critical path grows by the full transaction size;
  • on commit-conflict retries, the transaction is re-uploaded with the manifest every attempt;
  • the external _transactions/ file is written by default anyway, so the inline copy is pure redundancy.

Change

  • Add a fixed threshold 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.
  • All three commit paths (new dataset, detached, and the regular commit retry loop) share the decision; the retry loop recomputes it every attempt because a rebase may rewrite the transaction.

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_file as a referenced path, so the only copy is retained for as long as the manifest that references it.

@github-actions github-actions Bot added the enhancement New feature or request label Jul 21, 2026
@zhangyue19921010 zhangyue19921010 changed the title feat(dataset): spill large inline transaction out of manifest perf(dataset): spill large inline transaction out of manifest Jul 21, 2026
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Transaction spill handling

Layer / File(s) Summary
Inline transaction policy
rust/lance/src/dataset.rs, rust/lance/src/io/commit.rs
Transactions are inlined only when their encoded size is within the 64 KiB threshold; oversized transactions enable external transaction-file writing.
Commit and clone write paths
rust/lance/src/io/commit.rs
New dataset, detached, and retried commits conditionally pass transactions to manifests, while deep clones record their computed transaction file.
Manifest cleanup and spill validation
rust/lance-table/src/io/manifest.rs, rust/lance/src/dataset/tests/dataset_transactions.rs
Manifest writes clear absent inline transaction sections, and tests cover spilling, restore, and deep-clone transaction-file behavior.

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
Loading

Suggested reviewers: xuanwo

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: spilling large inline transactions out of the manifest.
Description check ✅ Passed The description is detailed and directly matches the transaction-spilling changes in the PR.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (5)
rust/lance/src/dataset/tests/dataset_transactions.rs (3)

729-763: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test utility helpers missing #[cfg_attr(coverage, coverage(off))].

large_props, spill_test_batch, and reopen are 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 win

Move use statements to the top of the file.

Several new test functions declare use inside the function body (large_props at Line 733; test_large_transaction_spills_to_external_file at Lines 768-770; test_spilled_restore_and_deep_clone_read_own_transaction at Line 889).

As per coding guidelines: "Place use imports 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 win

Use record_batch!() instead of manual Schema/RecordBatch::try_new boilerplate.

spill_test_batch manually builds an ArrowSchema and calls RecordBatch::try_new.

As per coding guidelines: "Use record_batch!() from arrow_array to construct RecordBatch in tests instead of manual Schema/Arc/try_new boilerplate."

♻️ 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 win

Doc 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 tradeoff

Transaction is protobuf-encoded twice per commit attempt.

inline_transaction_config encodes transaction just to measure its size; the caller then re-encodes it again inside write_transaction_file and/or do_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 touches write_transaction_file, build_manifest, and do_write_manifest signatures — 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

📥 Commits

Reviewing files that changed from the base of the PR and between aea6ded and d9e7c17.

📒 Files selected for processing (4)
  • rust/lance-table/src/io/manifest.rs
  • rust/lance/src/dataset.rs
  • rust/lance/src/dataset/tests/dataset_transactions.rs
  • rust/lance/src/io/commit.rs

@codecov

codecov Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 48 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance/src/io/commit.rs 57.52% 47 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@zhangyue19921010

Copy link
Copy Markdown
Collaborator Author

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 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.

I think we need to decide on what the threshold is. 64KB seems very low. What are we optimizing for here?

Comment thread rust/lance/src/io/commit.rs Outdated
transaction: &Transaction,
write_config: &ManifestWriteConfig,
) -> (bool, ManifestWriteConfig) {
let inline = pb::Transaction::from(transaction).encoded_len() <= MAX_INLINE_TRANSACTION_BYTES;

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: 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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

changed. Now only one conversion via pb::Transaction::from is required

Comment thread rust/lance/src/dataset.rs Outdated
Comment on lines +3845 to +3850
pub fn with_transaction_file_enabled(&self) -> Self {
Self {
disable_transaction_file: false,
..self.clone()
}
}

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.

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.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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;

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

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.

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.
Comment on lines +180 to +183
// 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;

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.

praise: This is a good safeguard

Comment thread rust/lance/src/io/commit.rs Outdated
Comment on lines +105 to +107
inlined: bool,
verify_version: Option<u64>,
naming_scheme: ManifestNamingScheme,

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): 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

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.

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.

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.

Created: #8307

@wjones127
wjones127 merged commit b5109a3 into lance-format:main Aug 5, 2026
39 of 40 checks passed
wjones127 pushed a commit that referenced this pull request Oct 14, 2026
… 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Large transactions are inlined into the manifest, doubling manifest size on large tables

2 participants