Skip to content

Address the review on apache#3046 - #1

Merged
hotcache merged 8 commits into
hotcache:feat/rewrite-files-actionfrom
jopdorp:pr-3046-fixes
Sep 28, 2026
Merged

hotcache merged 8 commits into
hotcache:feat/rewrite-files-actionfrom
jopdorp:pr-3046-fixes

Conversation

@jopdorp

@jopdorp jopdorp commented Sep 18, 2026 •

Copy link
Copy Markdown

What changes are included in this PR?

One commit per review point:

  • Surviving entries of a filtered manifest are written with add_existing_entry, so they keep their status, snapshot id and sequence numbers; test_rewrite_files_partial now reads them back.
  • RewriteFilesAction::data_sequence_number sets the data sequence number of the added files, as RewriteFiles.dataSequenceNumber does in Java, bounded by the new snapshot's sequence number.
  • The producer's validate_added_data_files and validate_duplicate_files run before a rewrite commits.
  • The manifest counter is on the action, which survives commit retries, so a retry no longer writes over the previous attempt's manifest.
  • Manifests an earlier snapshot left all-deleted drop out, as in Java's filter.
  • A rewrite whose starting snapshot is set refuses to commit when a delete manifest landed after it, until the file-level check exists.
  • The compaction and partial rewrite tests also run against a V2 table.
  • cargo fmt, the clippy warning, and public-api.txt.

Are these changes tested?

Each fix has a test in rewrite.rs through Transaction::rewrite_files(), reading the committed manifests back, and fails on the code before it. cargo test -p iceberg, fmt and clippy with -D warnings are clean.

The starting-snapshot check is the interim for apache#2243 (listed as missing on apache#1607). The all-deleted filter follows Java; FastAppend on main keeps those manifests (apache#2545) and is untouched here.

`ManifestFilterManager::filter_manifests` built each surviving entry with
status Existing and the original snapshot id and sequence numbers, then
handed it to `ManifestWriter::add_entry`, which rewrites the status to
Added, replaces the snapshot id with the new snapshot's, and clears the
file sequence number. Survivors of a rewrite were therefore recorded as
newly added files of the rewrite snapshot.

Use `add_existing_entry`, which only sets the status and leaves the ids
the filter already resolved, and drop its `#[allow(dead_code)]`.
Java's `RewriteFiles.dataSequenceNumber` lets a compaction record the
sequence number of the files it replaces, so the rewritten file does not
shadow deletes written concurrently at a higher sequence number. Without
it the added files inherit the rewrite snapshot's own sequence number.

`RewriteFilesAction::data_sequence_number` sets it, and
`write_added_manifest` then writes the added files through
`ManifestWriter::add_file`, which records the given number on the entry.
A number above the one the new snapshot will carry is rejected at commit;
on a V1 table that is 0, matching the V1 entry layout, which records no
sequence number at all.

The parameter is `i64`, not `u64`, to match `ManifestWriter::add_file`
and every other sequence number in the crate.
`commit_snapshot` handed `SnapshotProducer` an empty added-file list and
went straight to `commit_with_manifests`, so neither
`validate_added_data_files` nor `validate_duplicate_files` ever saw the
files a rewrite adds. A file carrying a partition value the default spec
cannot hold, or a path that is already live, was written into a manifest
and committed.

Pass the added files to the producer and run both validations first, and
drop `write_added_manifest`'s own content-type check, which
`validate_added_data_files` now makes unreachable.
`commit_snapshot` created a fresh `(0..)` counter on every call while the
commit uuid stayed fixed for the life of the action, so a retried commit
rewrote `{uuid}-m0.avro` over the manifest the previous attempt had
written under the same name.

Java keeps `manifestCount` on the snapshot producer and never resets it.
The counter cannot live on Rust's `SnapshotProducer`: that is built fresh
inside each `commit_snapshot` call and so resets with it. The object that
survives a retry is the action, which the transaction re-invokes through
an `Arc`, so the counter goes on `MergingSnapshotProducer` as an
`AtomicU64` — `commit` only has `&self`. `fast_append` is unaffected: it
draws a new commit uuid per attempt unless the caller pins one.
The filter carried a manifest forward on `has_deleted_files()`, so a
manifest whose entries are all Deleted stayed in every following snapshot
for the rest of the table's life. Java keeps an existing manifest on
`hasAddedFiles() || hasExistingFiles()`; its third arm matches the
snapshot being produced, which no manifest read from the current snapshot
can carry. The manifests this commit rewrites are produced by the filter
pass and kept on their own.
`starting_snapshot_id` was recorded and never read. A rewrite planned
against one snapshot and committed against a later one silently drops any
delete written in between: the replacement file keeps the deleted rows.

Java resolves this per file in `validateNoNewDeletesForDataFiles`, which
needs a delete-file index this crate does not have yet. Until then the
commit fails closed when the current snapshot carries a delete manifest
with a sequence number above the starting snapshot's.
Every rewrite test used the V3 fixture, so nothing covered the V2
manifest and entry layout the action also writes. Both cases now run on
V2 as well, through a V2 catalog fixture alongside the V3 one.
`cargo fmt` over the two new modules, and `public-api.txt` regenerated
for `Transaction::rewrite_files`. The clippy warning on the unnecessary
parentheses around the manifest counter went with the counter itself.
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.

2 participants