Skip to content

Retry an Iceberg commit only when its metadata version is taken - #129555

Open
groeneai wants to merge 4 commits into
ClickHouse:masterfrom
groeneai:iceberg-commit-retry-only-lost-race
Open

groeneai wants to merge 4 commits into
ClickHouse:masterfrom
groeneai:iceberg-commit-retry-only-lost-race

Conversation

@groeneai

@groeneai groeneai commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #126287

Changelog category (leave one):

  • Improvement

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

An Iceberg write (INSERT, ALTER TABLE ... DELETE/UPDATE, ALTER TABLE ... ADD COLUMN, DROP PARTITION, OPTIMIZE TABLE ... MANIFEST) whose metadata file cannot be written now fails with the write's own error right away, instead of retrying the commit up to 100 times as if it had lost a race and then failing with LIMIT_EXCEEDED, DATALAKE_DATABASE_ERROR or LOGICAL_ERROR. Running out of retries in OPTIMIZE TABLE ... MANIFEST is now reported as LIMIT_EXCEEDED instead of LOGICAL_ERROR.

Description

Iceberg::writeMetadataFile returned false for every write error except a list of refused writes (#125406), and every caller reads false as a lost commit race and retries. In #126287 (gzip metadata, output_format_compression_level = 18) zlib rejects the level before anything is written, so OPTIMIZE TABLE ... MANIFEST ended in LOGICAL_ERROR after 100 attempts (an abort in debug builds), INSERT in DATALAKE_DATABASE_ERROR and ALTER TABLE ... DELETE in LIMIT_EXCEEDED.

A failed write now counts as a lost race only when a file holds the target version afterwards: the error propagates while the file is absent, and the commit is retried, as before, when the file is present or the check cannot tell. An error of the existence check before the write also propagates. This replaces the refused-write list: lost races on local storage, S3 (412) and Azure (409) all leave the competing commit's file. The MANIFEST compaction loop now reports exhaustion as LIMIT_EXCEEDED, like the other commit loops.

Behaviour change: an error that the storage returns (after the client's own retries) now fails the statement instead of restarting the commit. Unchanged: the version-hint write (it runs after the commit has landed), and a file present because this commit's own write landed before the error. That case, and a write that lands only after the check, are the unknown-outcome case of my open #115390, which reads the file back. My open #125026 only changes the log level in the same catch arm.

Validation: the new test runs the issue's three statements plus UPDATE, ADD COLUMN and DROP PARTITION, and fails on master. The concurrent-writer integration tests pass on local, S3 and Azure, and their logs show real 412/409 conflicts being retried.

🤖 Generated with Claude Code


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

groeneai and others added 3 commits November 5, 2026 14:35
`Iceberg::writeMetadataFile` is the commit point of every storage-side
Iceberg commit (INSERT, DELETE/UPDATE, ALTER, OPTIMIZE [MANIFEST], DROP
PARTITION, expire_snapshots). It returned `false` for every failure except a
short list of refused writes (ClickHouse#125406), and every caller reads `false` as a
lost commit race and retries. Any other error that repeats on every attempt
was therefore retried up to the limit and then reported as something else,
with the real error only in the log, once per attempt. In ClickHouse#126287 gzip
metadata with `output_format_compression_level = 18` makes zlib reject the
level before anything is written: `OPTIMIZE ... MANIFEST` ended in
`LOGICAL_ERROR` after 100 attempts, INSERT in `DATALAKE_DATABASE_ERROR`,
`ALTER ... DELETE` in `LIMIT_EXCEEDED`.

Decide a lost race by the state that defines it, a file at the target path:
after a failed write, the error propagates while the file is absent, and the
commit is retried (as before) when it is present or the check itself fails.
An error of the existence check before the write propagates too, since
nothing was written. The per-backend refused-write list is no longer needed:
every refused write leaves the file absent. No backend's conflict error has to
be recognised, because a lost race on local storage, S3/GCS (412) or Azure
leaves the competing commit's file there. A file that is present because our
own write landed before the response was lost keeps master's behaviour
(ClickHouse#115390 handles that case).

`compactIcebergManifests` reported running out of retries as `LOGICAL_ERROR`;
it is reachable with enough concurrent commits, so report it as
`LIMIT_EXCEEDED` like the other commit loops.

`tryWriteVersionHintFile` keeps retrying everything: it runs after the commit
landed, so propagating its errors would reach the callers' cleanup after the
new snapshot became current.

Related: ClickHouse#126287

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…etadataFile comments

The test now has an arm for each commit caller the changelog entry names: ALTER TABLE ... UPDATE, ALTER TABLE ... ADD
COLUMN and DROP PARTITION (on a partitioned table) next to the issue's OPTIMIZE ... MANIFEST, INSERT and DELETE. On
master each of the three new statements fails with LIMIT_EXCEEDED after about 100 retries; with the fix each fails with
ZLIB_DEFLATE_FAILED on the first attempt. The writeMetadataFile comments no longer say that false means another commit
took the version: the file present after a failed write can also be this commit's own write, as on master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…mmit's in the tests

Three test comments (the ThrowingObjectStorage class comment and the LostRaceStaysRetryable comment in
gtest_iceberg_commit_propagation.cpp, and the header of 05508_iceberg_commit_non_race_write_error.sh) still described
the file present after a failed write as another commit's. It can also be this commit's own write, and a failed check
after the write is retried too, so they now say what the code checks: whether a file holds the target version
afterwards. Comment-only change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 5, 2026

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

Pre-publication review by an independent model (engine: codex; 4 findings over 3 rounds, none in the last) plus my own review.

# Sev Finding Verdict Evidence / action
1 ❌ A file present after a failed write can be this commit's own landed write; returning false retries it and duplicates the entries (Utils.cpp, writeMetadataFile) DISAGREE (remedy) True, and identical on master: master also returned false whenever the file is present, and that branch is unchanged here. The fix needs a read-back with an unknown outcome that keeps the staged files in every caller, which is my open #115390. This PR no longer claims the case: title, entry, source and test comments say "a file holds the version", and the description names it.
2 💡 Category should be Bug Fix, and Closes instead of Related DISAGREE The statements fail before and after the fix; only the error and the 100 retries change, so Improvement (as #125406). Item 3 of #126287 (level vs codec, #129519) is not fixed here, so Closes would close it early.
3 ⚠️ The entry names UPDATE, ADD COLUMN and DROP PARTITION, which the test did not run AGREE, fixed @ 76e51f3 Three arms added to the test; each fails on master with LIMIT_EXCEEDED after about 100 retries.
4 💡 Test comments still call the file after a failed write another commit's AGREE, fixed @ 088fc9a Comments narrowed like the source comments.
5 💡 No test for LIMIT_EXCEEDED when MANIFEST compaction runs out of retries DISAGREE With the fix only 100 real lost races reach it, which no deterministic input produces without a new failpoint; it is the same one-token error code as the four sibling commit loops.

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

@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes: the issue's three statements (gzip metadata, output_format_compression_level = 18) on master give LOGICAL_ERROR after 100 attempts (abort in debug), DATALAKE_DATABASE_ERROR and LIMIT_EXCEEDED, every run.
b Root cause explained? writeMetadataFile treated every write error not on a refused-write list as a lost race (false), and every caller retries false, so a repeating error was retried to the limit and reported as the limit.
c Fix matches root cause? Yes: the lost-race decision itself now uses the defining state (a file at the target path after the failed write); no per-error list, no caller or limit change.
d Test intent preserved / new tests added? New stateless test with one arm per commit caller (the issue's OPTIMIZE ... MANIFEST, INSERT, DELETE, plus UPDATE, ADD COLUMN, DROP PARTITION) and a count(), sum(k) oracle; the gtest contract is updated (version-free failure propagates, lost race stays retryable, failed pre-check propagates).
e Both directions demonstrated? New test fails on master (the debug server aborts on the LOGICAL_ERROR) and passes with the fix. Run one at a time, each statement fails on master after ~100 retries (LOGICAL_ERROR, DATALAKE_DATABASE_ERROR, LIMIT_EXCEEDED for the other four) and with the fix fails with ZLIB_DEFLATE_FAILED on the first attempt. The new gtest arms fail against the old writeMetadataFile and pass with the fix.
f Fix is general across code paths? All storage-side commits go through this function, and each caller (INSERT, DELETE/UPDATE, ADD COLUMN, DROP PARTITION, MANIFEST compaction) has its own arm in the test. Real lost races on local, S3 (412) and Azure (409) are still retried (concurrent-writer integration tests).
g Fix generalizes across inputs (params/datatypes/wrappers)? Any exception type (DB::Exception, errno, S3, non-DB SDK exceptions), format versions 1 and 2, partitioned and unpartitioned tables, version hint on and off; 50/50 randomized runs and a Replicated database run.
h Backward compatible? (maintainer-approved exception only) No setting or format change. Designed behaviour change: an error the storage returns now fails the statement instead of restarting the commit.
i Invariants and contracts preserved? false still means a file already holds this version (or the check after a failed write cannot tell); callers' cleanup only runs while the metadata file is absent; a file present after this commit's own write keeps master's behaviour.

Session id: cron:clickhouse-impl-slot-6:20261105-160600

@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

cc @PedroTadim @SmitaRKulkarni, could you review this and add the can be tested label so CI runs? writeMetadataFile now treats a failed metadata write as a lost race only when a file holds the target version afterwards (otherwise the write's own error propagates instead of being retried 100 times), and MANIFEST compaction reports running out of retries as LIMIT_EXCEEDED instead of LOGICAL_ERROR.

@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3726d65]

Summary: ✅


AI Review

Summary

Reviewed head 3726d65a7a47e0676d0455b398cca586aa79f600. The PR propagates Iceberg metadata-write errors when the target file remains absent, preserves retries when the version is occupied or its existence cannot be established, and reports manifest-compaction retry exhaustion as LIMIT_EXCEEDED. No new actionable findings. The pre-existing ambiguous-commit cleanup problem is explicitly tracked separately in #115390; keeping that fix separate is reasonable.

Missing context / blind spots
  • ⚠️ No local build or ClickHouse executable was available. The new regression test passed five times in CI at 088fc9a119d3. Detailed results for this test at the merged head were unavailable; a completed run there would close that verification gap.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Nov 5, 2026
@PedroTadim PedroTadim added can be tested Allows running workflows for external contributors and removed pr-improvement Pull request with some product improvements labels Nov 5, 2026
@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Nov 5, 2026
@scanhex12 scanhex12 self-assigned this Nov 5, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Nov 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 3726d65a7 with master b6ed65a67 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 4cbc68b27; 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

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

Job report

@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 088fc9a

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
Upgrade check (amd_release) / Error message in clickhouse-server.log (see upgrade_error_messages.txt) not from this PR (it changes only the Iceberg commit retry path): every line is ILLEGAL_DIVISION intDiv(100, x) While executing TTL from a background merge, the intentionally failing case of 05073_column_ttl_recompute_materialized; seen on 61 PRs in 14 days #127731 (mine, open)
Mergeable Check, PR praktika rollups of the row above #127731 (same as above)

Session id: cron:our-pr-ci-monitor:20261105-223008

@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 19, 2026
…y-only-lost-race

Resolve the conflict with ClickHouse#125026 in `writeMetadataFile`: keep its Debug log
for a conditional write conflict, and rethrow from both catch arms while the
metadata file is absent instead of only for the refused-write list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
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... pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants