Skip to content

feat(transaction): Add MergingSnapshotProducer and ManifestFilter - #3564

Open
CTTY wants to merge 4 commits into
apache:mainfrom
CTTY:ctty/merging-sp
Open

CTTY wants to merge 4 commits into
apache:mainfrom
CTTY:ctty/merging-sp

Conversation

@CTTY

@CTTY CTTY commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Which issue does this PR close?

What changes are included in this PR?

  • Add MergingSnapshotProducer as a Transaction state to store deleted files
  • Add ManifestFilterManager to cache the manifests across transaction attempts
  • When building the snapshot summary, widen a removed file's partition values
    to the types the current schema declares (int -> long, float -> double).
    A value read from a manifest keeps the literal type it was written with; Java
    reads manifests against the current partition type so it never sees the
    difference. The real fix belongs in the manifest reader; this is a TODO.
  • write_added_manifest and AddedManifests move to snapshot/mod.rs so both
    producers share them; the simple producer keeps the per-spec grouping from
    fix: support fast append across partition specs #3662 and both producers reject a cached manifest whose partition spec a
    concurrent commit removed.

Are these changes tested?

Added unit tests

AI Disclosure

Used Claude, but reviewed them with human eyes


/// Produces the resulting manifest set for the current table and writes
/// this attempt's snapshot.
pub(crate) async fn apply(&mut self, table: &Table) -> Result<ActionCommit> {

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.

Seems like we currently have no logic to validate new deletes or overwrite?

@CTTY CTTY Oct 28, 2026 •

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.

We can add them later before adding the actions that consume MSP

@CTTY
CTTY marked this pull request as ready for review October 28, 2026 20:45

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

It's on the large side, but this is close; I left a couple of comments inline.

Keying each rewrite by ManifestKey rather than path means a retry only redoes the manifests whose inherited values actually moved, and that's the piece the rest of #3417 builds on.

What I'd most like to settle is who decides that a missing delete fails, the action or the filter. I'd like to hear @anoopj's opinion on that thread; a follow-up is fine.

Could the description also mention the to_human_string promotion fix in spec/?

I'll take another look once that thread converges.

Comment thread crates/iceberg/src/spec/transform.rs Resolved
Comment on lines +106 to +108
/// Produces the resulting manifest set for the current table and writes
/// this attempt's snapshot.
pub(crate) async fn apply(&mut self, table: &Table) -> Result<ActionCommit> {

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.

I think this is aligned with the current Java implementation and we are trying to change it for v4. I suggest establishing a separate CommitValidator API. Action execution state can own the validator alongside this producer across retries. This has two advantages:

  1. The validation can be stateful. So retries can reuse the already validated state.
  2. Provides a useful seam for introducing v4 specific implementations of validations.

apache/iceberg#18699 may be a useful reference. This is one of the many upcoming changes we are making for validations.

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.

Thanks for pointing me to the java side PR! I had some thoughts about this a few weeks ago, and my previous thought was caching validated snapshots directly under the MSP and the seam also makes sense to me.

iiuc, we could still address this #3419 ? I'm leaning toward moving validations to another PR since the current PR is already quite large

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

Thanks @CTTY , just finished first round of review, left some comments.

jopdorp added a commit to jopdorp/iceberg-rust that referenced this pull request Nov 3, 2026


Merges CTTY's branch and drops the producer this branch carried from apache#3046.
@jopdorp

jopdorp commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

@CTTY we put #3585 (RewriteFilesAction, continuing #3046) on top of this branch and the producer carries it as is, remove-only rewrites included. Two things the rewrite tests ran into that I think belong in the producer rather than the action:

  1. A manifest left with only deleted entries is carried forward on every later commit. current_manifests keeps it since fix(transaction): preserve delete-only manifests in FastAppend #2545, and the filter rewrites the source manifest so the FastAppendAction drops delete-only manifests, causing deleted files to reappear #2148 case can't come back, but nothing drops it afterwards. Java keeps a manifest in MergingSnapshotProducer.apply only when it has added or existing files or was written by this commit (MergingSnapshotProducer.java:1057-1062). Could apply do the same after deletes.manifests? We hit this in pyiceberg, where the same carry-forward made every commit slower over time.

  2. MergingIntent has no data sequence number for added files, so the entries always inherit the snapshot's. A compaction needs to keep the number that existing equality deletes apply to. ManifestWriter::add_file(file, seq) is already there for it, plus Java's check that it is not above the new snapshot's. Fine as a follow-up, just flagging that RewriteFiles needs it.

Happy to open either as a PR on top of this once it lands.

Both were in the producer #3585 carried before the restack, in case it saves time: the keep rule at https://github.com/jopdorp/iceberg-rust/blob/682a6150b/crates/iceberg/src/transaction/merging.rs#L301-L313 and the sequence number check at https://github.com/jopdorp/iceberg-rust/blob/682a6150b/crates/iceberg/src/transaction/merging.rs#L259-L270.

@CTTY

CTTY commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

Hi @jopdorp , thanks for the feedback! I've addressed the first point you mentioned. And I'm planning to address the starting-seq-number issue when we are actually wiring actions with MSP and adding validation methods

@jopdorp

jopdorp commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@CTTY #3300 (overwrite) sits on this branch now as well, it only builds a MergingIntent with fail_missing_delete_paths on. Three things from putting it on top, none blocking for us:

  1. Missing delete paths are checked after the loop in ManifestFilterManager::filter has written its rewritten manifests, and validate_added_files also runs after the filters wrote. On feat(transaction): add overwrite action on MergingSnapshotProducer (stacks on #3564, continues #2185) #3300 @laskoviymishka asked for everything to be matched before the first write. They land in owned_artifacts, so **3. Merging and artifact lifecycle** — introduce MergingSnapshotProducer, manifest filtering, reusable added-manifest production; wire terminal CommitStatus reporting and cleanup #3417 covers them and maybe that is enough.
  2. The MergingIntent doc says the action validates disjoint add/remove sets. Overwrite allows deleting a path and re-adding it in the same commit, which was asked for in feat(transaction): add overwrite action on MergingSnapshotProducer (stacks on #3564, continues #2185) #3300's review, and the producer handles it fine: a deleted entry plus an added one. Should the doc allow that, or do you want actions to reject it?
  3. On v3, should a data file's deletion vectors go when the data file is removed? Overwrite leaves removed_delete_files empty, so they stay live. I have not checked what Java does here.

Happy to send a PR into your branch for 1 if you want it.

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

Re-ran my check at 8a442c6: removing a.parquet now marks its DV deleted (total-delete-files=0). Naming the DV as well under fail_missing_delete_paths removes it once, and removing only b.parquet or appending leaves a's DV alone. The older delete file cleanup (dropDeleteFilesOlderThan) isn't there yet, which is fine as a follow-up.

@jopdorp

jopdorp commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

@CTTY one thing from my last comment is still open: the MergingIntent doc says add and remove sets are disjoint, but overwrite deletes a path and re-adds it in the same commit (that was asked for in #3300's review), and the producer handles it fine. Should the doc allow that, or should actions reject it?

@jopdorp

jopdorp commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

@blackmwk could you take another look when you get a chance? JeonDaehong approved and the dangling deletion vectors are fixed, and #3300 and #3585 are waiting on this one.

@CTTY CTTY mentioned this pull request Nov 17, 2026
3 tasks
@jopdorp

jopdorp commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@CTTY opened CTTY#21 against your branch, it just merges main and resolves the conflict with the per-spec fast append, so you can pull it in if it helps.
@blackmwk your threads are all resolved and JeonDaehong approved, could you take another look? @anoopj @blackmwk are you ok with the two validation threads at merging.rs:123 going to #3419 like CTTY suggested?

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

Thanks @CTTY generally LGTM, some comments to address.

Comment thread crates/iceberg/src/spec/transform.rs Resolved
filtered: HashMap<ManifestKey, FilteredManifest>,
/// Format version the rewrites were written under. Per spec, v1 entries
/// cannot inherit sequence numbers, so an upgrade invalidates them.
format_version: Option<FormatVersion>,

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.

Why it's optional?

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.

We cannot initialize the format version when initializing this struct, because there may be format upgrade that could invalidate our cache

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 see, it's a bit ugly to pass local fields for one retry, how about we just add fields and mutators for snapshot id, uuid, table format, next_manifest_counter. And we could reset these fields before calling filter method.

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.

Also we could infer minimun table format from inputs.

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.

Or we could wrap them in sth like a RetryContext.

@CTTY CTTY Dec 3, 2026 •

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.

a RetryContext or AttemptContext sounds pretty clean, but we still have to store the format version in the ManifestFilterManager to validate against the format_version of the current attempt to make sure we invalidate the cache when format is being upgraded

// before reading, as Java's ManifestFilterManager does, and read the
// rest concurrently as `validate_files_not_live` does.
for source in manifests {
if source.content != self.content {

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 should return error here?

@CTTY CTTY Dec 2, 2026 •

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.

Currently I'm passing a list of manifests with mixed contents. We can split the input by content and add new API for each content but it would not really be necessary

- Add MergingSnapshotProducer as a Transaction state to store deleted files
- Add ManifestFilterManager to cache the manifests across transaction attempts
- Widen removed files' partition values to the current schema's types when
  building the summary key, as Java's manifest reader does
The removal conditions (content, files to remove, fail_missing_delete_paths,
dangling DVs) are fixed at build time; the per-attempt cache has no setter,
so after build() the only way to change a manager is filter().
filtered: HashMap<ManifestKey, FilteredManifest>,
/// Format version the rewrites were written under. Per spec, v1 entries
/// cannot inherit sequence numbers, so an upgrade invalidates them.
format_version: Option<FormatVersion>,

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 see, it's a bit ugly to pass local fields for one retry, how about we just add fields and mutators for snapshot id, uuid, table format, next_manifest_counter. And we could reset these fields before calling filter method.

filtered: HashMap<ManifestKey, FilteredManifest>,
/// Format version the rewrites were written under. Per spec, v1 entries
/// cannot inherit sequence numbers, so an upgrade invalidates them.
format_version: Option<FormatVersion>,

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.

Also we could infer minimun table format from inputs.

data_filter: ManifestFilterManager,
delete_filter: ManifestFilterManager,
/// Manifests written for the added files, reused across attempts.
added_manifests: Option<AddedManifests>,

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.

Should this be part of MergingIntent?

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.

No, added_manifests should come from manifest writers that live in the snapshot producer, not tx actions

filtered: HashMap<ManifestKey, FilteredManifest>,
/// Format version the rewrites were written under. Per spec, v1 entries
/// cannot inherit sequence numbers, so an upgrade invalidates them.
format_version: Option<FormatVersion>,

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.

Or we could wrap them in sth like a RetryContext.

CTTY added 2 commits December 3, 2026 05:14
- Add PartitionSpec::resolve(schema, partition) -> Result<Struct>, which
  widens a stored partition value to the type the schema declares now
  (int -> long, float -> double). build_summary resolves a removed file's
  partition before rendering the summary key; the unit tests move to
  spec/partition.rs with it.
- Move the snapshot producers' test helpers (data_file, append_to,
  with_snapshot) into the crate-level test_utils module.
- AttemptContext bundles what one attempt writes against (table,
  snapshot id, commit UUID, manifest counter, owned artifacts) and
  allocates manifest paths, so ManifestFilterManager::filter takes it
  instead of five per-attempt arguments and both producers' added
  manifests go through the same path allocation.
- RemovedFileIdentity::try_of fails for a file that carries a blob range
  but is not a Puffin file, or carries half a range. The manager keeps
  the files as named and converts them per attempt, so the error comes
  out of filter() and cannot be skipped.
/// Borrowed from the producer for one `apply`, so a helper cannot hold a stale
/// table across attempts, and every file written is recorded as owned by the
/// helper that allocates its path.
pub(crate) struct AttemptContext<'a> {

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.

I didn't add builder for this because this is a wrapper struct and all its fields are required

@CTTY
CTTY requested a review from blackmwk December 3, 2026 05:59

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

fail_missing_delete_paths, the v1 rewrite test and the 0.1_f32 case are in, thanks. One test note inline. From my side this is ready. @blackmwk's threads from today (PartitionSpec::resolve, the Puffin check, the retry state) are still open, and I'd like @anoopj to confirm the conflict validation can wait for #3419.

.build(),
delete_filter: ManifestFilterManager::builder()
.content(ManifestContentType::Deletes)
.files_to_remove(intent.removed_delete_files())

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.

Following up on my earlier ask for a delete-file removal test: could we add one that removes a Parquet position or equality delete as well? The only test that sets removed_delete_files removes a Puffin DV (merging.rs), so the RemovedFileIdentity::File path for delete files never runs.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants