Skip to content

Log a lost Iceberg metadata commit race at Debug, not Error - #125026

Merged
alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
groeneai:iceberg-lost-commit-cas-debug-log
Nov 8, 2026
Merged

alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
groeneai:iceberg-lost-commit-cas-debug-log

Conversation

@groeneai

@groeneai groeneai commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #99371

Changelog category (leave one):

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

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

...

Description

05325_iceberg_mixed_format_top_k_dynamic_filtering fails with having stderror while its output is correct, in 3 unrelated PRs on 2026-10-09 (1, 2, 3). The stderr line is <Error> bool DB::Iceberg::writeMetadataFile(...): ... v3.metadata.json already exists, PreconditionFailed for If-None-Match. (FILE_ALREADY_EXISTS).

Each sink of a parallel INSERT (max_insert_threads > 1) commits its own snapshot, so the sinks race for the same metadata version. The server logs of two of the failed jobs show two sink threads of one query starting v3.metadata.json within 30 us; the loser's conditional write fails, it retries and writes v4. That lost race is the expected outcome of the commit's compare-and-swap, but writeMetadataFile logged it with tryLogCurrentException, i.e. at Error with a stack trace. 05255_object_storage_top_k_dynamic_filtering pins max_insert_threads = 1 only to avoid this line.

Change: a helper Iceberg::isConditionalWriteConflict recognizes a failed conditional write (FILE_ALREADY_EXISTS, STALE_VERSION, or S3 PreconditionFailed). writeMetadataFile and tryWriteVersionHintFile log that case at Debug; every other failure stays at Error. IcebergMetadata::createInitial reuses the helper. This matches the REST catalog commit (409 at Debug) and the S3 layer (412 at Info, #99371). Azure reports a lost condition as an SDK exception and still logs it at Error.

Validation: the new test 05355_iceberg_parallel_insert_commit_conflict (8 sinks, 10 INSERTs, version hint off and on) fails 20/20 without the change and passes 50/50 with it. 05325 passes 50/50.


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

Version info

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

Each sink of a parallel INSERT into an Iceberg table commits its own
snapshot, so with max_insert_threads > 1 the sinks race for the same
metadata version. The loser's conditional write fails with
FILE_ALREADY_EXISTS (local, If-None-Match), STALE_VERSION (local,
If-Match) or an S3 412 PreconditionFailed, and the caller retries on
the next version. writeMetadataFile and tryWriteVersionHintFile logged
that expected outcome with tryLogCurrentException, i.e. at Error with a
stack trace, which reaches the client's stderr with
send_logs_level=warning and fails stateless tests such as
05325_iceberg_mixed_format_top_k_dynamic_filtering ("having stderror"),
although the INSERT succeeds and the data is correct.

Classify such a failure with one helper, isConditionalWriteConflict,
and log only that case at Debug, keeping every other failure at Error.
This matches the REST catalog commit path (409 is logged at Debug) and
the S3 layer, which already logs a 412 at Info (ClickHouse#99371). Control flow
is unchanged. IcebergMetadata::createInitial reuses the helper for its
CREATE ... IF NOT EXISTS race; its behaviour is identical because that
write is If-None-Match only.

The new test runs parallel INSERTs (8 sinks, 10 INSERTs, version hint
off and on) and fails on every run without the change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Oct 10, 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; 2 findings) plus my own review (3 nits).

# Sev Finding Verdict Evidence / action
1 ❌ Real S3 PreconditionFailed keeps logging at Error: the S3 writer keeps only the provider message, which lacks the name (Utils.cpp isConditionalWriteConflict) DISAGREE The 412 code has no typed AWS error, so AWSErrorMarshaller::Marshall (aws-cpp-sdk-core AWSErrorMarshaller.cpp:247) makes the message Unable to parse ExceptionName: PreconditionFailed Message: ..., and WriteBufferFromS3 copies it into the S3Exception. CI logs show exactly that text, e.g. 04034_iceberg_spark_style_location and 04033_iceberg_mismatched_location. The gtest mock builds the AWSError directly and skips the marshaller.
2 ⚠️ The new test never observes a conflict and would not catch an over-broad classifier DISAGREE The stderr check is the conflict detector: without the change the test fails 20/20 with the writeMetadataFile Error line. With only the FILE_ALREADY_EXISTS arm removed from the classifier it fails 10/10. The fixed server logged 246 conflicts at Debug and 0 at Error. The race count per run varies, so a text_log "conflicts > 0" check would be flaky.
3 💡 ExpireSnapshotsExecute.cpp logs its own Warning when a commit loses noted, not blocking expire_snapshots is a single writer, so it only races a concurrent foreign writer, never itself. Outside this change.
4 💡 The version-hint arm does not reliably hit the tryWriteVersionHintFile conflict branch noted, not blocking Same helper. The arm still checks that every commit lands with the hint enabled.
5 💡 An Azure lost condition is an SDK exception and stays at Error noted, not blocking Stated in the description.

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

Session id: cron:clickhouse-review-slot-9:20261010-014200

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. 05355_iceberg_parallel_insert_commit_conflict (8 sinks x 10 INSERTs) fails 20/20 on unmodified master with having stderror (<Error> writeMetadataFile ... PreconditionFailed for If-None-Match), stdout correct.
b Root cause explained? Each sink of a parallel Iceberg INSERT commits its own snapshot; two sinks pass the exists() pre-check for the same vN.metadata.json, the loser's If-None-Match publish throws FILE_ALREADY_EXISTS, and writeMetadataFile logged it with tryLogCurrentException (Error) before returning false for the retry. The client forwards Error lines to stderr.
c Fix matches root cause? Yes. The wrong severity is produced in writeMetadataFile's handler, the only place that knows the write is a retried commit CAS. A lost CAS is logged at Debug, everything else stays at Error; no test pins or tags.
d Test intent preserved / new tests added? 05325 unchanged. New 05355 asserts empty stderr, row counts, and uniqExact(_path) > 10 so it cannot pass with a single sink.
e Both directions demonstrated? Base 20/20 FAIL; fix 50/50 OK (05355 and 05325, randomized settings). Fix server log: 246 races logged at Debug, 0 Error lines. Mutation (drop FILE_ALREADY_EXISTS from the helper): 10/10 FAIL.
f Fix is general across code paths? Every catalog-less commit (insert, mutations, expire snapshots, drop partition, compaction) goes through writeMetadataFile; the version-hint CAS in tryWriteVersionHintFile gets the same classification; createInitial reuses the helper. REST catalog (409) and S3 transport (412) already log below Error.
g Fix generalizes across inputs (params/datatypes/wrappers)? Backend matrix: local If-None-Match / If-Match codes and S3 412 are classified; Azure keeps Error (SDK exception, not a DB::Exception), HDFS still rethrows UNSUPPORTED_METHOD. Test covers version hint off and on.
h Backward compatible? (maintainer-approved exception only) Yes. Log severity only: no setting, format, or control-flow change.
i Invariants and contracts preserved? writeMetadataFile still returns false on every failure and rethrows UNSUPPORTED_METHOD; the hint loop still retries. createInitial behaviour is identical (its write is If-None-Match only).

Session id: cron:clickhouse-impl-slot-6:20261010-004400

@clickhouse-gh

clickhouse-gh Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b079659]

Summary: ✅


AI Review

Summary

PR #125026 logs expected Iceberg conditional-write conflicts at Debug, preserves error logging for other failures, and adds a parallel-insert regression test with version hints disabled and enabled. No actionable findings in the current diff at b0796597e7edd9bd75202f53af1435d5da54e8f4. The preceding completed targeted CI run records 50/50 passes for 05355_iceberg_parallel_insert_commit_conflict.

Missing context / blind spots
  • ⚠️ The current head's targeted stateless job is pending. No local ClickHouse binary or build directory is available to rerun the test; its completed CI result will close this runtime-validation gap.
Final Verdict

Status: ✅ Approve. No code changes requested; current-head CI validation remains pending.

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

clickhouse-gh Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing b0796597e with master 7b5f2bf32 (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

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

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - b83c52f

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_asan_ubsan, azure, sequential) job timeout, not from this PR (which changes how a lost Iceberg metadata commit is logged): all 1180 tests finished (1082 passed, 98 skipped, none failed), then the job hit its 9000 s limit while exporting logs. The same job-level error hit 177 PRs and 25 master runs in 7 days #123849 (mine, open), which splits this job into 2 batches
PR praktika rollup of the row above (the azure job is allow_failure; Mergeable Check passed) #123849 (mine, open)

Session id: cron:our-pr-ci-monitor:20261010-073010

…-cas-debug-log

# Conflicts:
#	src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - d900a59

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) / Changed settings are not reflected in the settings changes history (see changed_settings.txt) not from this PR (it does not touch settings): v26.10.2.103-stable, published 2026-10-24 04:17Z, ships use_query_condition_cache_for_time_conditions = false after #127632, while master's settings history still says its default became true in 26.10. Every PR whose Upgrade check started after 04:17Z reports the same 1 / 0 row #127687 (mine, open)
Mergeable Check, PR praktika rollups of the row above #127687 (the owner of the row above)

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

Session id: cron:our-pr-ci-monitor:20261024-160007

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's perfect.

@alexey-milovidov alexey-milovidov self-assigned this Nov 6, 2026
@alexey-milovidov alexey-milovidov added the blocker This issue / pr blocks a new release label Nov 7, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125026&sha=c14a3e04ad956b20882499f343c6aa8681add106&name_0=PR&name_1=Build%20profile%20diff (LogClusterNotReady: the endpoint never became ready - a CI logs cluster outage, unrelated to this PR) and provide a fix in a separate PR. If the fix is already in progress, link it here - #129675 looks like the matching one. All other checks of this PR are green, and the branch already contains master as of 2026-11-07.

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

The fix is #129675 (open, CI green). In this run all 8 readiness probes connected and then got Read timed out. (read timeout=3) before LogClusterNotReady was raised. With #129675 that case is reported as a CI logs cluster outage (green, nothing compared) instead of failing the check, while a missing secret, a failed connection or a probe the server rejects still fail.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 8, 2026
Merged via the queue into ClickHouse:master with commit cfd9429 Nov 8, 2026
187 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 8, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 8, 2026
zoomxi pushed a commit to zoomxi/ClickHouse that referenced this pull request Nov 9, 2026
The check SELECT over the 80 Iceberg data files pins no settings, so it
gets the runner's random max_threads, which is 1-3 in 97% of runs. Late
in an MSan stateless job that read costs about 220-300 s of CPU, almost
all in IcebergIterator::next, whatever the thread count, so one thread
makes each of the two checks take 250-272 s and the test passes the
600 s limit. The failing job's own query_log on the same server: 604-631 s
with max_threads = 1, 136-139 s without randomization.

Raise the floor of the random max_threads to 8 with a Random settings
limits line. The 32 draw and every other random setting stay; the INSERTs
already pin max_threads = 8 and max_insert_threads = 8 in their own
SETTINGS, so the commit race they create does not change. Locally the
test still fails 10/10 without ClickHouse#125026 and passes 50/50 with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 9, 2026
…state-unknown-cleanup

Conflicts in Iceberg/Utils.h and Utils.cpp, both against master's
`isConditionalWriteConflict` (ClickHouse#125026), which logs a lost metadata
commit race at Debug instead of Error.

Utils.h: declare both `isCommitStateUnknown` and master's
`isConditionalWriteConflict`; keep this branch's `writeMetadataFile`
contract (false only for a known-lost commit).

Utils.cpp: union of the error codes and failpoints. In the catch arm
the refusal check stays first, master's Debug/Error log split follows,
and every failure after the write was sent is still reconciled against
the stored bytes instead of returning false.

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]>
robot-clickhouse-ci-1 added a commit that referenced this pull request Nov 9, 2026
Cherry pick #125026 to 26.10: Log a lost Iceberg metadata commit race at Debug, not Error
robot-clickhouse added a commit that referenced this pull request Nov 9, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 9, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 10, 2026
Backport #125026 to 26.10: Log a lost Iceberg metadata commit race at Debug, not Error
leshikus pushed a commit that referenced this pull request Nov 13, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 20, 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]>
@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

blocker This issue / pr blocks a new release 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-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants