Skip to content

feat(transaction): RewriteFilesAction + Validation Support + Process Delete Manifests - #1606

Closed
CTTY wants to merge 22 commits into
apache:mainfrom
CTTY:ctty/pure-rewrite
Closed

CTTY wants to merge 22 commits into
apache:mainfrom
CTTY:ctty/pure-rewrite

Conversation

@CTTY

@CTTY CTTY commented Aug 15, 2025 •

Copy link
Copy Markdown
Collaborator

Which issue does this PR close?

What changes are included in this PR?

  • Implemented RewriteFilesAction
  • Added SnapshotValidator and implemented it for RewriteFilesOperation
  • Added logic to process delete files in SnapshotProducer and generate manifests

Are these changes tested?

Not tested so far


for entry in manifest.entries() {
match entry.content_type() {
DataContentType::Data => {

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.

These are the exact same code blocks? So why does the ManifestEntry's DataContentType matter? Why not just do:

for entry in manifest.entries() {
    if snapshot_producer
        .deleted_data_files
        .iter()
        .any(|f| f.file_path == entry.data_file.file_path())
     {
         delete_entries.push(copy_with_deleted_status())
     }
        
}

@CTTY CTTY Nov 5, 2025 •

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.

It looks very similar with one little difference: one block iterates thru deleted_data_files and another iterates thru deleted_delete_files

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Feb 27, 2026
@CTTY
CTTY force-pushed the ctty/pure-rewrite branch from 336c974 to 4d984e0 Compare March 6, 2026 00:06
@github-actions github-actions Bot removed the stale label Mar 6, 2026
Aman-singh-7 pushed a commit to Aman-singh-7/iceberg-rust that referenced this pull request Mar 17, 2026
Details a concrete, file-by-file plan to implement RewriteFilesAction
in iceberg-rust — the compaction primitive that atomically swaps old
data files for new ones in a single Replace snapshot.

Key design decisions documented:
- Extend SnapshotProducer with deleted_data_files + write_deleted_manifest()
- New RewriteFilesOperation implementing SnapshotProduceOperation with
  Operation::Replace and manifest-level skip logic for deleted files
- Public RewriteFilesAction API mirroring FastAppendAction patterns
- Expose via Transaction::rewrite_files()
- 7 unit tests covering basic flow, error cases, and catalog round-trip
- Notes how this infrastructure enables OverwriteFiles and DeleteFiles next

Relates to open upstream issue: apache#1606

https://claude.ai/code/session_01EkUKvhB7p4jz4qZxYaneBb
wasifaleem added a commit to Supermetal-Inc/iceberg-rust that referenced this pull request Apr 1, 2026
wasifaleem added a commit to Supermetal-Inc/iceberg-rust that referenced this pull request Apr 1, 2026
wasifaleem added a commit to Supermetal-Inc/iceberg-rust that referenced this pull request Apr 1, 2026
wasifaleem added a commit to Supermetal-Inc/iceberg-rust that referenced this pull request Apr 1, 2026
@github-actions

github-actions Bot commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Apr 5, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@github-actions github-actions Bot closed this Apr 12, 2026
@CTTY CTTY mentioned this pull request May 6, 2026
brgr-s added a commit to lakekeeper/iceberg-rust that referenced this pull request Jun 2, 2026
brgr-s added a commit to lakekeeper/iceberg-rust that referenced this pull request Jun 2, 2026
wasifaleem added a commit to Supermetal-Inc/iceberg-rust that referenced this pull request Nov 2, 2026
…ove files

`SnapshotProducer` writes manifests only for added data files. Upstream's
apache#3253 lets an operation remove data files, counting them
from a list the caller supplies. The row delta and overwrite actions need
more. Add it.

- The producer takes added delete files and the data and delete files a
  commit removes. Added delete files get their own deletes manifests.
- `delete_entries` is now used: the entries an operation reports are written
  with DELETED status. The summary counts these entries, with the metrics the
  table recorded for them, instead of the caller's list. A removal can then
  name a file by its identity alone, such as a deletion vector's path and
  referenced data file. This replaces apache#3253's check that the caller's list
  matches the manifests.
- Every added or removed file is written to a manifest, and counted in the
  summary, under the partition spec it was written with, typed by the newest
  schema its partition values fit: the current one unless a source column
  of that spec has since been dropped or promoted (such as int to long).
  Manifests are grouped by spec, schema and content type. Using the default
  spec and current schema instead mislabels files of older specs and panics
  when the spec's fields or their types have changed. Partition values are
  kept as written, because delete files are matched to data files by exact
  partition value. Column bounds are fitted to the manifest's schema:
  promoted along type promotions, or dropped when they cannot be encoded
  in it, such as a long bound in a manifest whose schema predates the
  promotion; otherwise the manifest cannot be read.
- Operations implement `SnapshotValidator`, whose `validate` runs before the
  snapshot is produced. The default accepts.
- Duplicate-file checks cover added delete files too.

From the RewriteFilesAction work in apache#1606 (closed), built
on apache#3253's `truncate_full_table`, omitted negative totals and spec-aware
`new_manifest_writer`.

Co-authored-by: Wasif <[email protected]>
wasifaleem added a commit to Supermetal-Inc/iceberg-rust that referenced this pull request Nov 2, 2026
Truncating or replacing a table's contents needs a commit that deletes
specific files and optionally adds new ones in one `overwrite` snapshot.
Upstream has no such action.

`Transaction::overwrite_files` deletes data and delete files and adds new
ones:

- Deleted files are matched like a row delta's removed delete files: by
  path, or by path and content offset or referenced data file for deletion
  vectors, rejecting ambiguous path-only matches. Only live entries are
  matched and kept.
- Deleted files get DELETED entries; a manifest that keeps live entries is
  rewritten with the survivors as EXISTING, under its own partition spec and
  schema.
- `full_table_overwrite` marks the overwrite as replacing the whole table,
  which resets the table totals in the summary; it fails unless every live
  file is deleted, so files added after the caller listed the table, or a
  delete list naming files that are gone, cannot survive under totals of
  zero. A partial overwrite keeps the totals.
- Added files get the same validation as a row delta's.
- Before committing, the delete files added since `set_starting_snapshot_id`
  by overwrite or delete snapshots are checked, and the commit fails if any
  apply to a deleted data file. This catches a concurrent merge-on-read
  delete that the overwrite would otherwise drop. Each snapshot's deletes
  are indexed separately, and only live entries sequenced after the starting
  snapshot count, so a replaced deletion vector or a delete that predates
  the starting snapshot is not a conflict. v1 tables have no delete files
  and skip the check.
- The rewrite rules carried over: there must be files to delete, and files
  of a content type can only be added if files of that type are deleted.

Built on the RewriteFilesAction from apache#1606 (closed); the
validation follows Java's `validateNoNewDeletesForDataFiles`. Closing the
delete file index channel before the lookups is from the fix for validation
hanging on concurrent deletes.

Co-authored-by: Shawn Chang <[email protected]>
Co-authored-by: Kumar Ujjawal <[email protected]>
wasifaleem added a commit to Supermetal-Inc/iceberg-rust that referenced this pull request Nov 3, 2026
…ove files

`SnapshotProducer` writes manifests only for added data files. Upstream's
apache#3253 lets an operation remove data files and counts them from a list the
caller supplies. The row delta and overwrite actions need more, and this commit adds it.

- The producer takes added delete files and the data and delete files a commit removes. Added
  delete files get their own deletes manifests.
- The entries an operation reports from `delete_entries` are written with DELETED status. The
  summary counts these entries, with the metrics the table recorded for them, in place of the
  caller's list. A removal can then name a file by its identity alone, such as a deletion
  vector's path and referenced data file. This replaces the check in apache#3253 that the caller's list
  matches the manifests.
- Every added or removed file goes into a manifest, and into the summary, under the partition
  spec it was written with. The newest schema its partition values fit types those values. That
  is the current schema unless a source column of the spec has since been dropped or promoted,
  such as from int to long. Manifests are grouped by spec, schema and content type. The default
  spec and current schema would mislabel files of older specs and panic once the spec's fields
  or their types change. Partition values stay as written, because delete files match data files
  by exact partition value. Column bounds are fitted to the manifest's schema. A bound is
  promoted along type promotions, or dropped when the schema cannot encode it, such as a long
  bound in a manifest whose schema predates the promotion. An unfitted bound makes the manifest
  unreadable.
- Operations implement `SnapshotValidator`, whose `validate` runs before the snapshot is
  produced. The default accepts every commit.
- Duplicate file checks cover added delete files too.

This builds on the RewriteFilesAction work in apache#1606, which closed, and on the
`truncate_full_table`, omitted negative totals and spec aware `new_manifest_writer` from apache#3253.

Co-authored-by: Wasif <[email protected]>
wasifaleem added a commit to Supermetal-Inc/iceberg-rust that referenced this pull request Nov 3, 2026
Truncating or replacing a table's contents needs a commit that deletes specific files and
optionally adds new ones in one `overwrite` snapshot. Upstream has no such action.

`Transaction::overwrite_files` deletes data and delete files and adds new ones. It behaves as
follows.

- Deleted files are matched as a row delta matches removed delete files, by path, or by path and
  content offset or referenced data file for deletion vectors. An ambiguous path only match
  fails. Only live entries are matched and kept.
- Deleted files get DELETED entries. A manifest that keeps live entries is rewritten under its
  own partition spec and schema with the survivors as EXISTING.
- `full_table_overwrite` marks the overwrite as replacing the whole table, which resets the table
  totals in the summary. It requires every live file to be deleted, so files added after the
  caller listed the table, or a delete list naming files that are gone, never survive under
  totals of zero. A partial overwrite keeps the totals.
- Added files get the same validation as in a row delta.
- Before committing, the action checks the delete files that overwrite or delete snapshots added
  since `set_starting_snapshot_id`, and fails if any apply to a deleted data file. That catches a
  concurrent merge on read delete the overwrite would otherwise drop. Each snapshot's deletes are
  indexed separately, and only live entries sequenced after the starting snapshot count, so a
  replaced deletion vector or a delete older than the starting snapshot passes. Partition values
  written before an int or float partition source was promoted are widened, as the scan widens
  them, so a delete written after the promotion still matches. v1 tables have no delete files
  and skip the check.
- The rewrite rules carry over. There must be files to delete, and a content type can be added
  only when files of that type are deleted.

This builds on the RewriteFilesAction from apache#1606, which closed. The validation
follows Java's `validateNoNewDeletesForDataFiles`. Closing the delete file index channel before
the lookups comes from the fix for validation hanging on concurrent deletes.

Co-authored-by: Shawn Chang <[email protected]>
Co-authored-by: Kumar Ujjawal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add RewriteFiles support to iceberg-rust

2 participants