Skip to content

Iceberg remove_orphan_files with a recent older_than deletes an in-flight INSERT's files; the INSERT succeeds and the table is unreadable #125331

Closed

Description

@zlareb1

Company or project name

ClickHouse

Describe what's wrong

An INSERT into an Iceberg table writes its data files, manifest and manifest list before it commits the new metadata. If ALTER TABLE ... EXECUTE remove_orphan_files(older_than = <recent time>) runs in that window, it deletes those files. The INSERT then commits and returns success, and from then on every query on the table fails with FILE_DOESNT_EXIST. The table stays broken until someone repairs the metadata by hand.

Two things together make this a silent, permanent data loss:

  • older_than has no minimum. Spark's remove_orphan_files refuses intervals under 24 hours unless explicitly overridden, and Trino refuses anything under iceberg.remove-orphan-files.min-retention, 7 days by default.
  • The INSERT does not check that its own files still exist before it commits metadata that references them.

With the default older_than (3 days, iceberg_orphan_files_older_than_seconds) the same sequence is safe.

Does it reproduce on the most recent release?

Yes, master 26.10.1.2179 (62b7ea5).

How to reproduce

The failpoint only makes the window deterministic.

CH="clickhouse-client --allow_insert_into_iceberg=1 --allow_iceberg_remove_orphan_files=1"
$CH -q "CREATE TABLE t (id Int32) ENGINE = IcebergLocal('/var/lib/clickhouse/user_files/t/'); INSERT INTO t VALUES (1)"
$CH -q "SYSTEM ENABLE FAILPOINT iceberg_writes_pause_before_commit"
$CH -q "INSERT INTO t VALUES (2)" &      # pauses before its commit
$CH -q "SYSTEM WAIT FAILPOINT iceberg_writes_pause_before_commit PAUSE"
sleep 2
$CH -q "ALTER TABLE t EXECUTE remove_orphan_files(older_than = '$($CH -q 'SELECT toString(now())')')"
# deleted_data_files_count 1, deleted_manifest_files_count 1, deleted_manifest_lists_count 1, deleted_metadata_files_count 1
$CH -q "SYSTEM DISABLE FAILPOINT iceberg_writes_pause_before_commit"; wait   # the INSERT returns OK
$CH -q "SELECT count() FROM t"
# Code: 107. DB::ErrnoException: Cannot get metadata of file .../metadata/snap-...avro: errno: 2 ... (FILE_DOESNT_EXIST)

Expected behavior

At least one of these:

  • remove_orphan_files refuses an older_than closer to now than a configurable minimum, as Spark and Trino do.
  • The INSERT fails, instead of committing metadata that points at files that no longer exist.

Related: #114194
Related: #99127

Version info

Activity

  1. added
    potential bug
    on Oct 12, 2026
  2. zlareb1 commented on Oct 12, 2026

    @zlareb1
    MemberAuthor
  3. added
    bug
    and removed
    potential bug
    on Oct 12, 2026
  4. groeneai commented on Oct 12, 2026

    @groeneai
    Collaborator

    Acknowledged. I'm investigating remove_orphan_files deleting the files of an in-flight INSERT; I'll follow up here with a PR (or my findings) shortly.

  5. added
    minor
    on Oct 12, 2026
  6. added
    comp-datalake
    on Oct 12, 2026
  7. groeneai commented on Oct 12, 2026

    @groeneai
    Collaborator

    I opened #125376: remove_orphan_files now rejects an older_than less than iceberg_orphan_files_min_retention_seconds (default 1 day, 0 disables) before now, for an explicit older_than, the setting-derived one, and dry_run. Your failpoint sequence is refused with BAD_ARGUMENTS and the table keeps both rows. I did not add the pre-commit existence check in the INSERT: a sweep can still delete the files right after it.

    Your #125329 passes older_than = now in 05366/05371, so whichever PR lands second needs iceberg_orphan_files_min_retention_seconds = 0 there.

  8. added
    comp-iceberg
    and removed
    comp-datalake
    on Nov 22, 2026
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

    bugcomp-icebergminor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions