Skip to content

Corrupted table history due to CREATE OR REPLACE TABLE & Snapshot Expiration at the same time #13651

Closed as not planned

Description

@ggadon

Apache Iceberg version

None

Query engine

Spark

Please describe the bug 🐞

Hey team,

It seems like running snapshot expiration and CREATE OR REPLACE TABLE at the same time can cause table history corruption. The following happens:

  1. The base metadata, X, contains snapshots for expiration
  2. The replace operation loads the metadata X and uses it as base
  3. Snapshot expiration runs, creates metadata X+1, and commits it successfully, deleting old snapshots' data
  4. The replace operation finishes, and commits it successfully, with what seems to be X as its base, instead of X+1. It seems like the replace operation ignores commit conflicts during the replace operation

Initial Observations

If I'm looking at this correctly, the code that commits the replace transaction seems to have a logic that looks like ignores changes done to the base metadata, here:

// because this is a replace table, it will always completely replace the table
// metadata. even if it was just updated.
if (base != underlyingOps.current()) {
this.base = underlyingOps.current(); // just refreshed
}

In our scenario, current seems to include the history before cleanup, while base after the lines above is actually the clean metadata without the snapshots that were just expired. When the commit occurs a few lines below, it seems like it commits the new metadata with the old history in it, causing the corruption.

Am I reading this correctly? What was the logic behind this? Is it only for efficiency reasons since there is no real need to handle commit conflicts in these cases as all data files are replaced?

On a sidenote

I know there are active mailing list discussions around this (thread), and also an issue that was closed recently about this subject (with @RussellSpitzer 's comment about corrupted metadata). Would love to hear your thoughts about possible next steps here.

Thanks!

Willingness to contribute

  • I can contribute a fix for this bug independently
  • I would be willing to contribute a fix for this bug with guidance from the Iceberg community
  • I cannot contribute a fix for this bug at this time

Activity

  1. added
    bug
    on Jul 23, 2025
  2. RussellSpitzer commented on Aug 7, 2025

    @RussellSpitzer
    Member

    I think this was mentioned on the mailing list as well, but yes we definitely need to fix this. Even if we do change the behavior in the future that won't be for a long time and this is a bug now.

  3. ggadon commented on Aug 9, 2025

    @ggadon
    Author

    Opened a PR here: #13764

  4. github-actions commented on Feb 6, 2026

    @github-actions

    This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.

  5. github-actions commented on Feb 20, 2026

    @github-actions

    This issue has been closed because it has not received any activity in the last 14 days since being marked as 'stale'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugstale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions