Skip to content

Don't use backoffs on concurrent inserts conflicts - #119238

Merged
scanhex12 merged 2 commits into
masterfrom
do-not-retry-http-conflict
Sep 11, 2026
Merged

scanhex12 merged 2 commits into
masterfrom
do-not-retry-http-conflict

Conversation

@scanhex12

@scanhex12 scanhex12 commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

In case when we have catalog + iceberg concurrent inserts we can get a lot of errors like this:

Row 1:
──────
t:       2026-09-10
level:   Trace
message: Failed to make request to '...)","type":"CommitFailedException","code":409}}'. Failed at try 2/10. Will retry with current backoff wait is 100/10000 ms.

In fact, there is no need of backoffs here, so let's just cancel them

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Don't use backoffs on concurrent inserts conflicts (when we use Iceberg + catalog, for example)


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

Version info

  • Backported to: 26.8.4.5

`409 Conflict` reports that a request conflicts with the current state of the
target resource, so resending the same bytes cannot succeed - only the caller,
after re-reading that state, can build a request that does.

It was classified as retriable, so `ReadWriteBufferFromHTTP::doWithRetries`
resent the byte-identical request `http_max_tries` (10) times with a growing
backoff before handing the error back. An Iceberg REST catalog commit is the
worst case: it carries an `assert-ref-snapshot-id` requirement naming a parent
snapshot that a concurrent writer has already replaced, so all 10 attempts are
refused by construction, and every logical commit conflict cost ~32 seconds of
`sleepForMilliseconds`. `IcebergStorageSink` already handles the refusal
properly - `RestCatalog::updateMetadata` returns `false`, the sink re-reads the
branch tip and rebuilds the commit - so the retries only delayed the answer it
was waiting for.

Measured against a mock server counting requests: one `409` cost 10 requests
and 32.9 seconds before, and 1 request and 0.19 seconds after.

Forcing `http_max_tries = 1` for catalog commits instead would also drop the
retries of genuinely transient failures, which the sink's own loop does not
recover from: it treats only `409` as retriable and throws on anything else.

Tests: `05055_http_conflict_is_not_retried` pins the transport behaviour, and
`test_catalog_commit_conflict_reaches_caller_at_once` pins it for a catalog
commit, where a single `INSERT` with `max_insert_threads = 4` makes the conflict
a property of the plan rather than a race - every sink reads the branch tip in
its constructor, and all of them are constructed before the pipeline starts.
The latter fails with `assert 10 == 1` without this change.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [50df5a5]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, targeted) FAIL
05141_time_series_select_join_settings FAIL cidb
05141_time_series_select_join_settings FAIL cidb
05141_time_series_select_join_settings FAIL cidb
05141_time_series_select_join_settings FAIL cidb
05141_time_series_select_join_settings FAIL cidb
Too many test failures FAIL cidb
Stateless tests (amd_debug, parallel) FAIL
05141_time_series_select_join_settings FAIL cidb
05141_time_series_select_join_settings FAIL cidb
Stateless tests (arm_binary, parallel) FAIL
05141_time_series_select_join_settings FAIL cidb
05141_time_series_select_join_settings FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL
Fast test (arm_darwin) DROPPED
Build (amd_darwin) DROPPED
Build (arm_darwin) DROPPED
Build (arm_v80compat) DROPPED
Build (amd_freebsd) DROPPED
Build (ppc64le) DROPPED

AI Review

Summary

This PR tries to remove wasted backoff when an Iceberg REST catalog commit loses an optimistic-concurrency race, but it does that by changing isRetriableHTTPError globally instead of only the catalog write path. That broadens the fix into a transport-wide behavior change for unrelated HTTP clients, so I do not think it is ready to merge as-is.

Missing context / blind spots
  • ⚠️ At review time Praktika exposed only the Build profile diff report. I did not have CI results yet for the new stateless or integration tests, so passing runs for 05055_http_conflict_is_not_retried and test_catalog_commit_conflict_reaches_caller_at_once would close that gap.
Findings

❌ Blockers

  • [src/IO/HTTPCommon.cpp:74] The PR promise is “stop backing off on concurrent Iceberg catalog commit conflicts”, but this line rewrites the shared HTTP retry contract for every caller of isRetriableHTTPError. ReadWriteBufferFromHTTP::doWithRetries uses it for generic url()/web/dictionary/object-storage reads, and FunctionBaseAI::isRetriableProviderError reuses it for AI provider retries. Those callers do not share Iceberg’s assert-ref-snapshot-id invariant, so a transport-wide rule that any 409 is permanently non-retriable can now fail requests that used to recover once the remote state changed. We already keep 409 handling at the caller layer in places like AvroConfluentSchemaRegistry, and ITableFunctionXDBC::getActualTableStructure already shows the other workable pattern: override retry policy for one request instead of changing the global helper.
    Suggested fix: keep the 409 special case in the Iceberg catalog write path, or add a per-request override / non-retriable-status list to ReadWriteBufferFromHTTP so RestCatalog::updateMetadata can disable retries for its optimistic-concurrency POST without changing unrelated HTTP clients.
Final Verdict

Changes requested. The Iceberg motivation is valid, but the current implementation applies that application-specific 409 policy at the shared transport layer.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 10, 2026
@scanhex12 scanhex12 added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 10, 2026
Comment thread src/IO/HTTPCommon.cpp
Poco::Net::HTTPResponse::HTTPStatus::HTTP_NOT_IMPLEMENTED,
Poco::Net::HTTPResponse::HTTPStatus::HTTP_METHOD_NOT_ALLOWED};
Poco::Net::HTTPResponse::HTTPStatus::HTTP_METHOD_NOT_ALLOWED,
Poco::Net::HTTPResponse::HTTPStatus::HTTP_CONFLICT};

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.

Adding HTTP_CONFLICT here changes the shared retry contract for every user of isRetriableHTTPError, not just Iceberg catalog commits. ReadWriteBufferFromHTTP uses it for generic url() reads (src/Storages/StorageURL.cpp:649), and FunctionBaseAI::isRetriableProviderError reuses it for provider retries (src/Functions/FunctionBaseAI.cpp:325). We already handle call-site-specific retry policy in places like ITableFunctionXDBC::getActualTableStructure, which forces max_tries = 1 locally for its POST metadata request (src/TableFunctions/ITableFunctionXDBC.cpp:220). Can we keep the 409 special-case in the catalog write path, or add a per-request override, instead of making every shared HTTP client fail immediately on any 409?

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 10, 2026
@diegomestre2 diegomestre2 self-assigned this Sep 10, 2026

@diegomestre2 diegomestre2 left a comment

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.

LGTM!

@scanhex12
scanhex12 enabled auto-merge September 10, 2026 15:54
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 50df5a519 with master 9b9f4d3aa (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 8a489ac31; 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, 6 s compile time in total, 7 of them have a recent master baseline.

Job report

@scanhex12
scanhex12 added this pull request to the merge queue Sep 11, 2026
Merged via the queue into master with commit 33ad3a2 Sep 11, 2026
169 of 174 checks passed
@scanhex12
scanhex12 deleted the do-not-retry-http-conflict branch September 11, 2026 09:21
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 11, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 11, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 13, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 13, 2026
Backport #119238 to 26.7: Don't use backoffs on concurrent inserts conflicts
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 13, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 13, 2026
Backport #119238 to 26.6: Don't use backoffs on concurrent inserts conflicts
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 13, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 13, 2026
Backport #119238 to 26.8: Don't use backoffs on concurrent inserts conflicts
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 14, 2026
The only textual conflict was in tests/integration/test_database_iceberg/test.py, where both
sides appended to the end of the file: master added
test_catalog_commit_conflict_reaches_caller_at_once (ClickHouse#119238, a 409 is no longer retried by the
transport) and this branch added the catalog commit-outcome arms. Both are kept, master's first.

The src side merged with no conflict, and its delta against master is byte-identical to the
pre-merge one, so the unknown-outcome branch is still present in all three catalog
implementations and all three cleanup call sites still consult isCommitStateUnknown.

One semantic conflict the textual merge could not see: that new test counts the
"updateMetadata conflict" log line, which this branch had renamed to "Lost the commit race" at
LOG_TRACE, so the merged branch failed it with "no writer was refused" (assert 0). The conflict
arm therefore keeps master's wording, level and displayText call; nothing else about the arm
changes, and the ONCE(iceberg_catalog_commit_conflict) test still passes. Measured on the merged
tree: test_catalog_commit_conflict_reaches_caller_at_once,
test_catalog_commit_response_lost_keeps_committed_snapshot, test_catalog_commit_single_attempt
and test_catalog_commit_conflict_cleans_up_and_retries all pass, and reverting only that log
line reddens master's test alone.
robot-clickhouse-ci-2 added a commit that referenced this pull request Sep 17, 2026
Cherry pick #119238 to 26.3: Don't use backoffs on concurrent inserts conflicts
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 17, 2026
alexey-milovidov added a commit to RinChanNOWWW/ClickHouse that referenced this pull request Oct 3, 2026
…9` in `updateSchema`

`HTTP_CONFLICT` is already in the shared non-retriable set of `isRetriableHTTPError`
since ClickHouse#119238, so threading
`{HTTP_CONFLICT}` through `BuilderRWBufferFromHTTP::withCustomNonRetryableError`
into `RestCatalog::sendRequest` changed nothing. Remove that hook.

`RestCatalog::updateSchema` returned `false` for every `HTTPException`, which the
`ALTER` loop in `Mutations.cpp` treats as an optimistic-concurrency conflict, so a
`401`, `500` or malformed catalog response was retried until the query failed with
"Too many unsuccessed retries to alter iceberg table". Return `false` only for
`409` and rethrow anything else, mirroring `updateMetadata`. Add a failpoint and an
integration test for the non-conflict path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
PedroTadim added a commit that referenced this pull request Nov 3, 2026
The auto cherry-pick of #119238 landed a new `isRetriableHTTPError` in
`src/IO/HTTPCommon.cpp`, but on master that symbol is the renamed/relocated
retry gate (declared in `HTTPCommon.h`, called from `ReadWriteBufferFromHTTP.cpp`
and the AI request executor). 26.3 has none of that wiring, so the backported
function was dead code and `409 Conflict` was still retried `http_max_tries`
times, which is exactly what `05055_http_conflict_is_not_retried` caught
(`requests: 10` instead of `1`).

On 26.3 the real retry decision is the file-local `isRetriableError` in
`src/IO/ReadWriteBufferFromHTTP.cpp`. Add `HTTP_CONFLICT` to its
`non_retriable_errors` list and drop the dead `isRetriableHTTPError` the
cherry-pick added, so the backport matches the intent of #119238.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=120586&sha=latest&name_0=BackportPR
PR: #120586

Co-Authored-By: Claude Opus 4.8 <[email protected]>
PedroTadim added a commit that referenced this pull request Nov 3, 2026
Backport #119238 to 26.3: Don't use backoffs on concurrent inserts conflicts
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
The auto cherry-pick of #119238 landed a new `isRetriableHTTPError` in
`src/IO/HTTPCommon.cpp`, but on master that symbol is the renamed/relocated
retry gate (declared in `HTTPCommon.h`, called from `ReadWriteBufferFromHTTP.cpp`
and the AI request executor). 26.3 has none of that wiring, so the backported
function was dead code and `409 Conflict` was still retried `http_max_tries`
times, which is exactly what `05055_http_conflict_is_not_retried` caught
(`requests: 10` instead of `1`).

On 26.3 the real retry decision is the file-local `isRetriableError` in
`src/IO/ReadWriteBufferFromHTTP.cpp`. Add `HTTP_CONFLICT` to its
`non_retriable_errors` list and drop the dead `isRetriableHTTPError` the
cherry-pick added, so the backport matches the intent of #119238.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=120586&sha=latest&name_0=BackportPR
PR: #120586

Co-Authored-By: Claude Opus 4.8 <[email protected]>
blau-ai added a commit to Altinity/ClickHouse that referenced this pull request Nov 16, 2026
- gtest_azure_read_buffer_missing_etag: the Azure SDK pinned on 26.3 reads
  `x-ms-creation-time` and `x-ms-server-encrypted` unconditionally in
  `BlobClient::Download`, so the fake endpoint must send them; otherwise the
  SDK throws `std::out_of_range` before the missing `ETag` is ever checked.
- test_database_iceberg: drop the master-only tests that the upstream
  backport of ClickHouse#119238 dragged in; they need features absent from 26.3
  (failpoint `datalake_get_tables_throw`, OneLake settings, ALTER DATABASE
  settings, ...).
- test_database_glue: use the 26.3 MinIO endpoint `minio:9000` instead of
  master's `minio1:9001`.
blau-ai added a commit to Altinity/ClickHouse that referenced this pull request Nov 17, 2026
- test_database_iceberg: drop the 9 tests that upstream backport ClickHouse#119238
  (deb73a9) dragged in from master. They exercise master-only code that
  26.3 does not have (ALTER DATABASE settings for DataLakeCatalog, the
  `datalake_get_tables_throw` failpoint, the IcebergIterator progress
  callback, catalog-table mutations, the RestCatalog `updateMetadata conflict`
  handling). The file is now identical to antalya-26.3.
- test_database_glue: test_timestamp_types_cache_does_not_keep_metadata used
  upstream's `minio1:9001` endpoint; this suite's MinIO is `minio:9000`.
- gtest_azure_read_buffer_missing_etag: the pinned Azure SDK reads
  `x-ms-creation-time` and `x-ms-server-encrypted` with `std::map::at` in
  `BlobClient::Download`, so the fake response threw `std::out_of_range`
  (abort in debug/sanitizer builds) before reaching the ETag check.
@clickhouse-gh clickhouse-gh Bot added comp-networking The connection layer under the protocols, on the server and on the client side: socket read / wri... 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

comp-networking The connection layer under the protocols, on the server and on the client side: socket read / wri... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants