Skip to content

Downgrade S3 PreconditionFailed log level from Error to Info - #99371

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-iceberg-precondition-failed-log-level
Mar 14, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-iceberg-precondition-failed-log-level

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 13, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Downgrade PreconditionFailed (HTTP 412) S3 response log level from Error to Info in both PocoHTTPClient and WriteBufferFromS3
  • 412 is an expected outcome of conditional writes (If-None-Match: *) used by Iceberg metadata commits — it should not be logged at Error level
  • Fixes flaky test 03800_mv_from_iceberg which failed because Error-level logs leaked to stderr via --send_logs_level=warning

The root cause: during CREATE TABLE IF NOT EXISTS for an Iceberg table, the first S3 PUT for v1.metadata.json timed out but actually succeeded on MinIO. The S3 SDK retried and got 412 PreconditionFailed. The Error-level log was forwarded to the client's stderr, causing the test to fail.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=a5483cedba19a14e57f9c27fe76b707f5a1a45bb&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan%2C%20distributed%20plan%2C%20parallel%2C%202%2F2%29

Test plan

  • Build succeeds locally (release build)
  • Existing 03800_mv_from_iceberg test should no longer fail due to PreconditionFailed stderr output
  • Other S3 error scenarios (non-PreconditionFailed) still log at Error level

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):

...

🤖 Generated with Claude Code


Note

Low Risk
Low risk: only adjusts logging severity for expected S3 conditional-write failures (HTTP 412 / PreconditionFailed) while keeping other error handling unchanged.

Overview
Reduces noise from expected S3 conditional-write failures by downgrading HTTP 412 PreconditionFailed responses from error to info logs.

This is applied in both the low-level PocoHTTPClient HTTP status logging and the WriteBufferFromS3 single-part PutObject failure path, while preserving error-level logging for other non-expected failures.

Written by Cursor Bugbot for commit b5143bb. This will update automatically on new commits. Configure here.

The `PreconditionFailed` (412) HTTP response is an expected outcome
of conditional S3 writes using `If-None-Match: *` headers — it means
the object already exists, and the caller handles this case. Previously,
both the S3 HTTP client and `WriteBufferFromS3` logged it at Error level,
which caused it to be forwarded to the client via `--send_logs_level=warning`
and appear in stderr.

This was observed in the `03800_mv_from_iceberg` test: a `CREATE TABLE
IF NOT EXISTS` for an Iceberg table writes `v1.metadata.json` with
`If-None-Match: *`. When the first S3 PUT times out but actually succeeds
on the server side, the S3 SDK retries and gets 412. The Error-level log
leaked to the client's stderr, causing the test to fail.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=a5483cedba19a14e57f9c27fe76b707f5a1a45bb&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan%2C%20distributed%20plan%2C%20parallel%2C%202%2F2%29

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

clickhouse-gh Bot commented Mar 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b5143bb]

Summary: ✅


AI Review

Summary

This PR downgrades S3 PreconditionFailed (HTTP 412) logging from Error to Info in PocoHTTPClient and in the single-part upload path of WriteBufferFromS3 to avoid noisy/false-failure stderr output for expected conditional-write conflicts. The change is narrowly scoped and preserves exception propagation, but there is one reliability nit in how PreconditionFailed is detected in WriteBufferFromS3.

Findings

  • 💡 Nits
    • [src/IO/WriteBufferFromS3.cpp:786] Detection uses GetExceptionName() == "PreconditionFailed", which is string-based and brittle if SDK naming changes.
    • Suggested fix: compare GetErrorType() against the enum (e.g. Aws::S3::S3Errors::PRECONDITION_FAILED).

ClickHouse Rules

Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ➖
SettingsHistory.cpp ➖
Safe rollout ✅
Compilation time ✅

Final Verdict

  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Mar 13, 2026
outcome.GetError().GetExceptionName(), outcome.GetError().GetMessage(), bucket, key, content_length);
/// PreconditionFailed is an expected response for conditional writes (e.g. If-None-Match: *),
/// not a genuine error — the caller handles it.
if (outcome.GetError().GetExceptionName() == "PreconditionFailed")

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.

Using GetExceptionName() == "PreconditionFailed" is brittle and may miss equivalent 412 responses if SDK naming changes; prefer checking GetErrorType() against the enum (e.g. Aws::S3::S3Errors::PRECONDITION_FAILED) for stable behavior.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok.

@clickhouse-gh

clickhouse-gh Bot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.80% 83.80% +0.00%
Functions 23.90% 23.90% +0.00%
Branches 76.30% 76.30% +0.00%

PR changed lines: PR changed-lines coverage: 80.95% (17/21, 0 noise lines excluded)
Diff coverage report
Uncovered code

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Mar 13, 2026
@alexey-milovidov alexey-milovidov self-assigned this Mar 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Mar 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Mar 13, 2026
Merged via the queue into master with commit bbed0a3 Mar 14, 2026
160 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-iceberg-precondition-failed-log-level branch March 14, 2026 02:41
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 14, 2026
alexey-milovidov pushed a commit to canhld94/ClickHouse that referenced this pull request Nov 8, 2026
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]>
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