Skip to content

Fix sporadic PreconditionFailed in CREATE TABLE IF NOT EXISTS for Iceberg - #96121

Merged
alexey-milovidov merged 2 commits into
masterfrom
fix-iceberg-precondition-failed-on-create-if-not-exists
Feb 7, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
fix-iceberg-precondition-failed-on-create-if-not-exists

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 5, 2026 •

Copy link
Copy Markdown
Member

IcebergMetadata::createInitial uses If-None-Match: * when writing v1.metadata.json to S3. This throws PreconditionFailed when the file already exists, e.g. due to leftover S3 data after a DROP TABLE (when iceberg_delete_data_on_drop is off) or a concurrent creation.

The listFiles check before the write is not atomic with respect to the write itself, creating a TOCTOU race. The writeMetadataFileAndVersionHint function already handles this pattern by catching the exception.

Now createInitial also catches the PreconditionFailed S3 error when IF NOT EXISTS was specified, treating it as "table already exists".

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

See https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96111&sha=e7311fadca72f6ff8fd72f1e7a02f4e386282511&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29
#96111

Version info

  • Merged into: 26.2.1.355

… Iceberg

`IcebergMetadata::createInitial` uses `If-None-Match: *` when writing
`v1.metadata.json` to S3. This throws `PreconditionFailed` when the
file already exists, e.g. due to leftover S3 data after a `DROP TABLE`
(when `iceberg_delete_data_on_drop` is off) or a concurrent creation.

The `listFiles` check before the write is not atomic with respect to
the write itself, creating a TOCTOU race. The `writeMetadataFileAndVersionHint`
function already handles this pattern by catching the exception.

Now `createInitial` also catches the `PreconditionFailed` S3 error
when `IF NOT EXISTS` was specified, treating it as "table already exists".

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Feb 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0c7d17c]

Summary: ❌

job_name test_name status info comment
Stress test (amd_ubsan) failure
Logical error: Block structure mismatch in A stream: different number of columns: (STID: 0993-38e6) FAIL cidb, issue

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Feb 5, 2026
@alexey-milovidov alexey-milovidov self-assigned this Feb 7, 2026
@alexey-milovidov
alexey-milovidov merged commit 3e0c859 into master Feb 7, 2026
128 of 129 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-iceberg-precondition-failed-on-create-if-not-exists branch February 7, 2026 01:48
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants