Repository navigation
Don't use backoffs on concurrent inserts conflicts - #119238
Conversation
`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]>
|
Workflow [PR], commit [50df5a5] Summary: ❌
AI ReviewSummaryThis PR tries to remove wasted backoff when an Iceberg REST catalog commit loses an optimistic-concurrency race, but it does that by changing Missing context / blind spots
Findings❌ Blockers
Final VerdictChanges requested. The Iceberg motivation is valid, but the current implementation applies that application-specific |
| 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}; |
There was a problem hiding this comment.
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?
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline. |
Backport #119238 to 26.7: Don't use backoffs on concurrent inserts conflicts
Backport #119238 to 26.6: Don't use backoffs on concurrent inserts conflicts
Backport #119238 to 26.8: Don't use backoffs on concurrent inserts conflicts
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.
Cherry pick #119238 to 26.3: Don't use backoffs on concurrent inserts conflicts
…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]>
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]>
Backport #119238 to 26.3: Don't use backoffs on concurrent inserts conflicts
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]>
- 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`.
- 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.
In case when we have catalog + iceberg concurrent inserts we can get a lot of errors like this:
In fact, there is no need of backoffs here, so let's just cancel them
Changelog category (leave one):
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
26.8.4.5