Skip to content

Do not retry an Iceberg commit when the storage refuses the metadata write - #125406

Merged
alesapin merged 1 commit into
ClickHouse:masterfrom
groeneai:iceberg-refused-metadata-write-propagates
Oct 16, 2026
Merged

alesapin merged 1 commit into
ClickHouse:masterfrom
groeneai:iceberg-refused-metadata-write-propagates

Conversation

@groeneai

@groeneai groeneai commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #125343
Related: #115390
Related: #125026

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

An Iceberg commit (for example ALTER TABLE ... EXECUTE expire_snapshots) whose new metadata file the storage refuses to write, such as Permission denied on a local directory or S3 AccessDenied, now fails at once with that error instead of being retried as a commit conflict until LIMIT_EXCEEDED.

Description

ALTER TABLE ... EXECUTE expire_snapshots on an Iceberg table whose metadata/ the writer cannot write fails with LIMIT_EXCEEDED, and the real error is only logged.

Iceberg::writeMetadataFile is the commit point of every storage-side Iceberg commit. It turned every write failure except UNSUPPORTED_METHOD into false, which all callers read as a lost commit race and retry. A refused write is refused again on every round. ALTER, DELETE/UPDATE, INSERT and OPTIMIZE share this commit point.

Change: a refused write now propagates, as UNSUPPORTED_METHOD already does: READONLY (a read-only disk), ErrnoException with EACCES, EPERM or EROFS, and S3Exception with ACCESS_DENIED, INVALID_ACCESS_KEY_ID, INVALID_SIGNATURE or SIGNATURE_DOES_NOT_MATCH. Everything else stays retryable. A refusal after the write was sent (the s3_check_objects_after_upload check) propagates only while the file is absent. I did not switch to "retry only on a conflict": S3 reports a lost race (412) as an untyped error, so parallel INSERT sinks would fail, and a timeout after the PUT may have committed (#115390). Azure is unchanged: its layer retries 403 on purpose. #125026 only lowers the log level in this catch arm.

This is an Improvement, not a Bug Fix: a misleading error, not a wrong result.

Validation: gtest_iceberg_commit_propagation gains errno and S3 refusal tests, which fail on master, plus lost-race controls that must stay retryable. The issue's repro (non-root, chmod 555) gives LIMIT_EXCEEDED after 999 logged attempts on master, and Permission denied at once with the fix. ALTER ADD COLUMN, an anonymous read-only MinIO bucket and a read-only disk behave the same way. Parallel INSERTs still retry lost races on local and MinIO. No SQL test: stateless CI runs as root, with no read-only disk or S3 identity.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/125406]

Version info

  • Merged into: 26.11.1.80-master (included in 26.11 and later)

…write

`Iceberg::writeMetadataFile` is the single storage-side commit point (an
`If-None-Match: *` create of `vN.metadata.json`). It turned every write failure
except `UNSUPPORTED_METHOD` into `false`, and every caller (expire_snapshots,
INSERT, DELETE/UPDATE, ALTER, DROP PARTITION, OPTIMIZE) reads `false` as a lost
commit race and retries. A write the storage refused (no permission) is refused
again on every round, so the loop ended in `LIMIT_EXCEEDED` and the real error
was only logged (ClickHouse#125343).

Propagate a refused write, extending the `UNSUPPORTED_METHOD` carve-out:
`READONLY` (a read-only disk refuses every write before sending it),
`ErrnoException` with EACCES/EPERM/EROFS (local storage; the temporary file is
opened, and the target linked, before anything is published) and `S3Exception`
with the codes `S3::isAuthenticationError` recognises (ACCESS_DENIED,
INVALID_ACCESS_KEY_ID, INVALID_SIGNATURE) plus SIGNATURE_DOES_NOT_MATCH (a
403/401 is answered before the request is applied).

A refusal that comes after the write was sent, e.g. of the
`s3_check_objects_after_upload` request, may follow a PUT that landed, so it
propagates only when the file is absent; a refused pre-write existence check
propagates directly.

Every other failure stays retryable:
- S3 reports a lost race (412 PreconditionFailed) as an untyped `UNKNOWN`
  error, so "retry only on a recognised conflict" would fail the parallel sinks
  of a multi-threaded INSERT.
- A timeout or 5xx after the PUT may have committed; that case is ClickHouse#115390's.
- Azure's layer classifies 403 as retryable on purpose (RBAC propagation lag),
  so Azure is unchanged.
`S3Exception::isRetryableError` is not reused: its non-retryable set includes
NO_SUCH_KEY/NO_SUCH_UPLOAD, which can follow a PUT that landed.

The callers' exception paths clean up only this attempt's uncommitted staged
files and rethrow, which is correct for a write that did not happen.

The gtest stub now takes the error to throw and the answers of `exists`. The
`UNSUPPORTED_METHOD` test also covers READONLY. New tests cover the errno and
S3 refusals, a refusal of a write that may have landed (the file is there
afterwards, or the check fails), and a refused pre-write existence check. The
retryable control gains the local lost race (FILE_ALREADY_EXISTS), an I/O
error (EIO) and the S3 lost race (412), so a classifier that propagated every
ErrnoException or S3Exception fails it.

Closes ClickHouse#125343

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 12, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; round 0: 2 findings, round 1: 0, round 2: 0) plus my own review (round 0: 2, round 1: 2, round 2: 1).

# Sev Finding Verdict Evidence / action
1 ❌ With s3_check_objects_after_upload, the check after the upload could be refused after the PUT landed. The refusal was propagated as "nothing written", so INSERT cleanup could delete a committed snapshot's files (Utils.cpp, WriteBufferFromS3.cpp) AGREE, fixed in round 1 a refusal propagates only before the write is sent, or when the metadata file is confirmed absent; a gtest covers both branches
2 💡 Changelog category should be Bug Fix DISAGREE the prior symptom is a misleading LIMIT_EXCEEDED for an operation that cannot succeed; nothing is returned wrong or lost (row count and metadata are the same before and after on master)
3 💡 The S3 codes duplicate S3::isAuthenticationError AGREE, fixed in round 1 reused the helper
4 💡 No control pins a non-refusal ErrnoException as retryable AGREE, fixed in round 1 added an EIO control
5 ⚠️ A read-only disk (<readonly> local blob storage) refuses the write with READONLY, which was still retried until LIMIT_EXCEEDED AGREE, fixed in round 2 READONLY joins UNSUPPORTED_METHOD; the gtest covers both codes
6 💡 The description overstated that INSERT/DELETE/OPTIMIZE show the same symptom (they usually fail earlier, on their data or manifest write) AGREE, fixed reworded to "share this commit point"
7 💡 The "No SQL test" sentence did not mention the read-only disk route AGREE, fixed CI has no read-only disk either (tests/config), and the Iceberg disk setting only names a configured disk; the description now says so

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The issue's repro as uid 1000 (chmod 555 t/metadata) gives LIMIT_EXCEEDED after 999 logged Permission denied attempts on every master run. An anonymous read-only MinIO bucket (NOSIGN) and a read-only disk (SETTINGS disk = ...) give the same result.
b Root cause explained? Iceberg::writeMetadataFile returned false for every write failure except UNSUPPORTED_METHOD. All seven storage-side commit callers read false as a lost compare-and-swap and retry. A refused write is refused again on every round, so the loop ends in the generic retry-limit error.
c Fix matches root cause? Yes. A refused write is classified where it was turned into "lost race". No caller, retry count or guard changed.
d Test intent preserved / new tests added? The existing gtest is extended with READONLY, errno (EACCES/EPERM/EROFS) and S3 (4 codes) refusal tests, a refusal of a write that may have landed (must stay retryable), a refused pre-write existence check (must propagate), and local, EIO and S3 lost-race retryable controls. The existing assertions are kept. There is no SQL test because stateless CI runs as root, with no read-only disk or read-only S3 identity.
e Both directions demonstrated? Yes. A master-equivalent classifier fails the three propagation tests, dropping READONLY fails its iteration, dropping the absence check fails the may-have-landed test, dropping the pre-write short-circuit fails the refused-existence-check test, and an over-broad errno classifier fails the retryable control. End to end on the master vs fix binaries, master gives LIMIT_EXCEEDED, and the fix gives CANNOT_OPEN_FILE ... errno: 13 locally, S3_ERROR: Access Denied. on MinIO and READONLY on a read-only disk.
f Fix is general across code paths? It is the single commit point for expire_snapshots, INSERT, DELETE/UPDATE, ALTER, DROP PARTITION and both OPTIMIZE paths. createInitial already rethrows. The version-hint write is deliberately unchanged, because it must not throw after a durable commit. Catalog commits are out of scope (#115580).
g Fix generalizes across inputs (params/datatypes/wrappers)? Backends: local (errno), a read-only disk (READONLY), S3 and S3-compatible (4 codes), HDFS (unchanged), Azure (deliberately unchanged, since its layer retries 403 for RBAC lag). Compressed metadata goes through the same path. A refusal after the write was sent (e.g. the s3_check_objects_after_upload check) propagates only while the metadata file is absent; a refused pre-write existence check propagates without the write. Lost races on local and S3 stay retryable (10 parallel-sink INSERTs each: 100000 10000 rows, 28 and 30 retries).
h Backward compatible? (maintainer-approved exception only) Yes. There is no setting and no format change. A refused write now fails at once with its own error.
i Invariants and contracts preserved? false is returned only for an outcome a retry can change, and a refusal is thrown only when nothing was written (nothing sent, or the file absent afterwards). Callers clean up only this attempt's uncommitted files and rethrow, which is correct because a refused write committed nothing. Measured after the failed runs: count() = 2, metadata unchanged, no leftover temp files, and the control expire succeeds after chmod 755.

Session id: cron:clickhouse-impl-slot-41:20261012-114200

@groeneai
groeneai requested review from alesapin and arsenmuk October 12, 2026 12:21
@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e5e789b]

Summary: ✅


AI Review

Summary

This PR fixes the main bug well: stable Iceberg metadata-write refusals now propagate instead of being misreported as commit conflicts, and the new gtests cover the local/S3 cases and the "write may already have landed" cleanup hazard. I found one remaining local-object-storage gap, though: permission failures that surface as std::filesystem::filesystem_error still bypass the new classifier and keep retrying to LIMIT_EXCEEDED.

Findings
  • ⚠️ src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp:419 — local permission-denied failures from std::filesystem are still handled by catch (...), so an unsearchable metadata/ directory continues to retry 1000 times instead of failing immediately with the real error.
Final Verdict

⚠️ Needs one more fix before merge: the new refusal classifier does not yet cover the local std::filesystem permission-error path.

if (e.code() == ErrorCodes::UNSUPPORTED_METHOD)
/// A refused write is not a lost race, and retrying the commit cannot get past it. Once the write was sent,
/// a refusal (e.g. of the check after an upload) proves nothing was written only while the file is absent.
if (isRefusedWrite(e) && (!write_attempted || isKnownAbsent(object_storage, storage_metadata_path)))

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.

LocalObjectStorage::exists still makes this incomplete on the local-permission path. That method calls throwing std::filesystem::exists (src/Disks/DiskObjectStorage/ObjectStorages/Local/LocalObjectStorage.cpp:180), so an unsearchable metadata/ directory (chmod 000) raises std::filesystem::filesystem_error, not DB::Exception. In that case we never reach isRefusedWrite, we fall through catch (...), and the commit is still retried 1000 times until LIMIT_EXCEEDED instead of surfacing the permission error.

Could you classify the local std::filesystem permission-denied case here as a refused pre-check too, or translate it to a DB::Exception before this helper sees it?

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Oct 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e5e789b20 with master 56e72cfad (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 18 s compile time in total, 7 of them have a recent master baseline.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - e5e789b

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05210_lightweight_update_materialized_cte_in_ignore flaky, not from this PR (it only changes how the Iceberg metadata write classifies a refused write): Code: 60 ... Unknown table expression identifier '_materialized_cte_c_...' with parallel replicas, 147 of 147 reruns passed; it failed on 167 PRs and 30 master commits in the last 7 days #123121 (mine, open)
Mergeable Check, PR praktika rollups of the row above #123121 (mine, open)

CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261013-000014

@alesapin alesapin self-assigned this Oct 16, 2026
@alesapin
alesapin added this pull request to the merge queue Oct 16, 2026
Merged via the queue into ClickHouse:master with commit 1f26f7d Oct 16, 2026
351 of 353 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 16, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 25, 2026
…state-unknown-cleanup

Conflicts in Iceberg/Utils.cpp and the commit-propagation gtest, both
against master's refused-write propagation (ClickHouse#125406).

Utils.cpp: keep master's `isRefusedWrite`/`isKnownAbsent` and its
`write_attempted` flag, which replaces this branch's `put_started`
(same meaning). The refusal check stays the first statement of the
catch arm, so a refused write whose target is absent still propagates
as itself; every other failure after the write was sent is reconciled.

gtest: port master's refusal cases onto the reconciling stub (the write
failure is now a thrower, and the target's existence probe can be
answered per call). Two of master's expectations encoded "an ambiguous
outcome returns false" and change with this branch: a non-refused
failure with an absent target, or a failing check after a refusal, is
now UNKNOWN_STATUS_OF_TRANSACTION; a refusal after an upload whose bytes
landed is committed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov pushed a commit that referenced this pull request Nov 9, 2026
Resolve the conflict in Iceberg/Utils.cpp: both regions came from #125406
(`READONLY`, `isRefusedWrite`, `isKnownAbsent`), which is not on 26.10. Keep
the 26.10 side and add only #125026's own lines (the three error codes and
`isConditionalWriteConflict`). Per file, the change against 26.10 is the same
set of added and removed lines as #125026's diff against master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-improvement Pull request with some product improvements 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.

Iceberg expire_snapshots treats a permission error on the metadata write as a commit conflict and fails with LIMIT_EXCEEDED

3 participants