Repository navigation
Conversation
…leted Client::CompleteMultipartUpload absorbed a NoSuchUpload error whenever a HeadObject found any object at the target key. That recheck comes from ClickHouse#56475, whose premise is a completion that already succeeded and whose response was lost. The premise has two conjuncts: the completion was replayed, and the object at the key is the one this upload produced. Key existence tests neither, so it also admits a genuinely aborted upload against a key that already holds an unrelated object, for example an s3() INSERT with s3_truncate_on_insert=1 whose upload an AbortIncompleteMultipartUpload lifecycle rule cancelled. The INSERT was then acknowledged with none of its rows stored and the prior object kept being served. NO_SUCH_UPLOAD is unretryable and excluded from isTransientCompleteMultipartUploadError, so this rewrite was the only thing standing between the abort and a silent success. MergeTree over S3 was unaffected because it writes random unique keys. Require the object at the key to carry the ETag implied by the part list in the request itself, md5(concat(binary md5 of each part))-N. That needs no extra request and no new state, and fixing it in the client covers both callers (WriteBufferFromS3 and copyS3File) without touching either. It fails closed: when the ETag does not match, or is not derivable, the original error is returned so the INSERT fails and can be retried. The ETag is a sufficient but not a necessary proof, since SSE-KMS and non-default checksum algorithms change its shape, so in those setups a benign replay now returns a retryable error instead of silently accepting a possibly foreign object. A failed INSERT is recoverable; a silently discarded one is not. Both operands need unquoting: the SDK stores the etag header verbatim for the HEAD result and for each uploaded part, so the quotes are present on both sides, and HashingUtils::HexDecode asserts on non-hex input. The integration test injects an unforwarded NoSuchUpload on the completion via a new inert-by-default broken_s3 hook, and asserts the INSERT fails and the prior object survives; a no-fault control arm proves the fixture really does perform a multipart upload. Two unit tests keep ClickHouse#56475 honest in both directions: a matching object is still absorbed, a foreign one still errors. The gtest mock had to be taught real MD5 ETags first, otherwise both would have passed through the fail-closed branch and proved nothing. Closes: ClickHouse#114348
Internal second-model review (3 findings, all disagreed with evidence)A second model reviewed this diff cold. All three findings are answered below; none changed the code.
💡 Use One reviewer nit was applied to this description: the not-derivable cases now also name S3 Express and providers that compute the ETag differently, not just SSE-KMS and non-default checksum algorithms. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20260811-175500 |
|
cc @Michicosun @CheSema, could you review this? Client::CompleteMultipartUpload absorbed NoSuchUpload whenever a HeadObject found any object at the key, but #56475's premise is a replayed completion, which also requires the object to be the one that upload produced; on a fixed key holding a prior object an aborted upload was therefore acknowledged with none of its rows stored. It now absorbs only when the object carries the ETag the request's own part list implies, and fails closed otherwise. |
|
Workflow [PR], commit [b70db34] Summary: ❌
AI ReviewSummaryThis PR hardens Findings❌ Blockers
Tests
Final Verdict❌ Changes requested. The main multipart-recovery fix is solid, but the new non- LLVM Coverage ReportMeasured on commit b70db34.
Changed lines: Changed C/C++ lines covered: 407/416 (97.84%) · Uncovered code |
CI finish ledger - 46977830461eeb48f2ce38a4e64a1e13ee9ba0d5Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task CI finished with no failing checks on this head (155 success, 20 skipped, praktika top-level OK,
Session id: cron:our-pr-ci-monitor:20260812-050000 |
CI finish ledger for 4697783CI is fully finished on this head (175 leaves, praktika top-level
The 73 CIDB This supersedes my 05:17Z ledger comment on this PR, whose heading carried a 40-char SHA that does not exist (a 16-char prefix of this head padded out instead of read from Session id: cron:our-pr-ci-monitor:20260812-163000 |
|
Fantastic finding! Thank you! |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Everything else LGTM.
Renames the two injection models, the two test cases and the object keys introduced here so they do not abbreviate MultipartUpload. Test identifiers only; no behaviour change. Requested by alexey-milovidov in review of ClickHouse#114375.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes21 object files changed (+34.55 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units71 translation units recompiled, 676 s compile time in total, 71 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.07 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
CI finish ledger - 555331eEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
That job reports Both Session id: cron:our-pr-ci-monitor:20260817-113000 |
…ify-etag-before-absorbing-nosuchupload
CI finish ledger - 0aba0e7Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260818-200000 |
|
I have not pushed, since you own every commit at head. I can push just that one-token change if you want it. |
…ify-etag-before-absorbing-nosuchupload
…ify-etag-before-absorbing-nosuchupload
…identity gate
The AI review flagged that treating every configured extra header as write
identity regressed benign replay recovery on requester-pays buckets:
`headers('x-amz-request-payer' = 'requester')` must be sent on every request
but does not change which object a successful completion produces, yet it made
every lost completion response surface `NoSuchUpload`.
`hasExtraHeadersRequiringFullWriteIdentity` now exempts `x-amz-request-payer`
and `x-amz-expected-bucket-owner` (case-insensitive); any other extra header
still fails closed. New regression arms prove the replay is absorbed with
those headers configured, on both the `WriteBufferFromS3` path and the
`copyS3File` path, while the foreign-header arm keeps throwing.
…ify-etag-before-absorbing-nosuchupload
…ify-etag-before-absorbing-nosuchupload # Conflicts: # src/IO/S3/Client.cpp # src/IO/tests/gtest_writebuffer_s3.cpp
…gning `PocoHTTPClient` replays `client_configuration.extra_headers` onto the Poco request after the SDK has signed it, skipping anything that starts with `x-amz-` because those are already in the canonical header list. That test was literal, while every surface that accepts the header name keeps its case: `headers(...)` stores it verbatim and `HTTPHeaderFilter::checkAndNormalizeHeaders` does not lowercase it. `CompleteMultipartUploadRequest` / `UploadPartRequest` drop create-only headers case-insensitively in `SetAdditionalCustomHeaderValue`, so a spelling such as `X-Amz-Meta-Write-Id` was dropped from the request and then added back on the wire, unsigned, by this loop. Use the same case-insensitive comparison the classifier and the canonical header selection already use, and cover it with a regression that goes through the real `PocoHTTPClient` against a capturing endpoint rather than through `MockS3::Client`. Reverting the one-line change turns `DoesNotReplayMixedCaseAmzHeaderAfterSigning` red; the other three arms (lowercase spelling, an already signed header, a non `x-amz-` header) stay green either way.
…a-headers test
`Build (arm_tidy)` failed on `head.find("\r\n\r\n") == std::string::npos`;
use `head.contains` instead.
…ify-etag-before-absorbing-nosuchupload
…ify-etag-before-absorbing-nosuchupload
|
🕵 Merged The remaining red, |
|
🕵 Investigated that What the job reported. All 1261 test rows are OK or SKIPPED, and the only failure is the job-level guard row, so the
This is not the Fix presence in the tested tree. It was missing exactly the two changes that size and depopulate that leaf:
The job started 2026-09-01 06:38Z, roughly 5 h before #117412 merged and 2 days before #117564. Fleet-wide incidence confirms those two are the fix, counting distinct trees carrying the guard row on this shard:
The step down on 09-02 follows #117412 and the drop to zero on 09-04 follows #117564. The one row since is So: #117412 and #117564, both merged, both now on this branch through your merge. The re-run on |
…e-identity gate `hasExtraHeadersRequiringFullWriteIdentity` treated every `client_configuration.extra_headers` entry except `x-amz-request-payer` / `x-amz-expected-bucket-owner` as object identity, and `S3AuthSettings::getHeaders` merges the documented `access_header` entries into that same vector. On a header-authenticated endpoint that turned off the `NoSuchUpload` replay recovery entirely, so a merely lost completion response reported `NoSuchUpload` for an object that was in fact stored. `access_header` provenance is now preserved: `S3AuthSettings::getMergedAccessHeaders` reports the entries `getHeaders` actually merged, `getClient` puts them in the new `PocoHTTPClientConfiguration::access_headers` (the wire path still sends the merged `extra_headers`, unchanged), and the gate exempts a header carried by that list. The exemption stops at the `x-amz-` namespace: an `access_header` may name any header, and `x-amz-` is where S3 puts the ones that do change the stored object (metadata, tagging, storage class, encryption, checksums), so those still fail closed. Adds `CompleteMultipartUploadAbsorbsNoSuchUploadWithAccessHeader`, `CompleteMultipartUploadReportsNoSuchUploadWhenAccessHeaderIsAMZHeader` and `CopyS3FileCompletionRecoveryTest.AbsorbsNoSuchUploadWithAccessHeader`.
…ify-etag-before-absorbing-nosuchupload
|
🕵 Addressed the AI review's "Changes requested" Major on CI on
Neither has a tracking issue. #118417 ("Report a distributed plan's root cause, not its exchange teardown error") is open and touches the first area but is not a fix for the flakiness. @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=114375&sha=6683afc6a93947314062824c0c764dbffdb3c318&name_0=PR&name_1=Stateless%20tests%20(arm_asan_ubsan%2C%20azure%2C%20sequential) and provide a fix in a separate PR. If the fix is already in progress, link it here. |
|
Investigated. The two rows are one cascade, and it recurred on the new head: in The chain, within one job:
The fix is in progress and does not need a new PR. Three are open, any one of which clears both rows, and none is merged, so
On the harness labels: 04340 is the victim, and Same two rows came up on #115528 seventeen minutes later, so that thread has the same answer rather than a second investigation. |
…ify-etag-before-absorbing-nosuchupload
|
🕵 Merged CI on
There was no tracking issue for either, so I filed one with the evidence: #118626
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=114375&sha=2cbcab437418d395ea30d9be5dc25d1ea4199679&name_0=PR&name_1=Stateless%20tests%20(amd_asan_ubsan%2C%20db%20disk%2C%20distributed%20plan%2C%20sequential%2C%20selected%20tests) and provide a fix in a separate PR. If the fix is already in progress, link it here. |
| /// namespace, though -- that is where S3 puts the headers which do change the stored | ||
| /// object (metadata, tagging, storage class, encryption, checksums), and an | ||
| /// `access_header` is free to name any header at all. | ||
| if (!isAMZHeader(header.name) && isAccessHeader(header.name)) |
There was a problem hiding this comment.
access_header is still an arbitrary header carrier here, not a typed auth-only field: registerStorageObjectStorage documents it as "adds specified HTTP header", and HTTPHeaderFilter does not constrain the header name. Exempting every non-x-amz-* access_header therefore reopens the same hole for standard conditional headers like If-Match / If-None-Match.
Those headers still go out on the wire through PocoHTTPClient (src/IO/S3/PocoHTTPClient.cpp:602-615), but they never set request.IfMatchHasBeenSet() / IfNoneMatchHasBeenSet() in CompleteMultipartUpload (src/IO/S3/Client.cpp:640-647). So a header-authenticated endpoint configured with access_header = If-None-Match: * can still rewrite NoSuchUpload to success on an ETag / Content-Type match, even though the completion was conditional and the object may belong to a different write. I think this exemption needs to stay fail-closed for standard conditional/object-attribute names, or be tightened to a whitelist of headers proven auth/transport-only.
There was a problem hiding this comment.
Measured on b70db34b8262, and the mechanism holds: not blocking in my reading, hardening at most.
Three arms in gtest_writebuffer_s3.cpp (whole suite 77 passed, 1 pre-existing skip):
access_header: If-None-Match: *, so it lands in bothextra_headersandaccess_headers: the absorb fires,headObject == 1.HTTPHeaderFilterconstrains no name by default, so a conditional header does reach the exempt branch.- The same header spelled as a generic
header: fail-closed,headObject == 0. Theaccess_headerclassification is the only cause. - The same exempt conditional header with a foreign object at the key: still refused,
Expected ETag: 8f28f2e7231860115d2a8cacba019dbe-1, ETag at key: "90f0f2aff752d90f2bf7eba27e07e874".
Arm 3 is why I would not call this the same hole. At origin/master (16723d7e43a2, Client.cpp:563-575) the absorb is if (check_outcome.IsSuccess()) with no ETag and no Content-Type check, and master's is_conditional reads the same typed fields, so this exact configuration absorbs whatever object sits at the key today. Behind the exemption it absorbs only an object whose multipart ETag and Content-Type match the part list: narrower than what ships, not wider.
What does survive is the authorship half, one step further than stated: for a conditional completion an ETag match is not authorship, because a byte-identical object from another writer carries the same ETag. That is what the write token exists for on the typed path, where object_storage_write_if_none_match mints it and the recovery checks it. A conditional header arriving through access_header mints no token and trips neither guard.
I could not get from there to a user-visible consequence. access_header is documented as a credential carrier ("in cases where there are no other credentials from another source", added for user authentication in #71011), the only in-tree use is an auth token, and being per-endpoint it would condition every read from that endpoint as well.
If you want it closed regardless, the cheap form is two names refused ahead of the exemption: if-match and if-none-match are the only conditional fields on the SDK's CompleteMultipartUploadRequest, so a deny-list there is complete rather than open-ended. Your branch and your design call; I pushed nothing.
|
Same cascade as the run I answered at 11:29Z (#114375 (comment)): the job you link is the one I measured there, so I will not repeat the chain. What is new since then: Nothing has merged, so Fleet-wide in the 6.5 hours since that reply, on top of the 30-day counts in #118626: 04648 +10 failures over 9 pull requests, 04340 +8 over 7. The three fixes are unchanged and all still open, so there is nothing new for me to author here: #118417 (yours, removes both halves), #118390 (mine), #105942 (@ Diskein, approved 2026-06-01). One thing worth flagging, because it is the only test-level red left on #118417 and it is not caused by that diff: |
|
Measured on the current head At your approval (2026-08-17): 4 files, The 601 added lines in between are 11 non-merge commits (plus 12 So the original idea did not grow much: I agree it should be smaller, and I am not pushing anything here since the head has been @ alexey-milovidov's since 08-18. If you want it split, I can open a fresh PR off |
|
I close it in favour. #118829 |
|
Agreed, and yours is the better branch. Deleting the inference is the fix. Keeping it inside One measurement worth having on the record, since the obvious question about your approach is whether moving the recovery out of the client leaves a caller behind: at master Checked against what this PR carried, every case is covered there: the integration arm with its no-fault control, own-object recovery and foreign-object refusal on an unconditional completion, and the Nothing further from me here. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed silent data loss when writing to a fixed S3 key that already holds an object, for example
INSERT INTO FUNCTION s3(...)withs3_truncate_on_insert = 1. If the multipart upload was aborted between create and complete, for example by anAbortIncompleteMultipartUploadlifecycle rule,CompleteMultipartUploadcorrectly returnedNoSuchUpload, but the error was rewritten to success whenever any object existed at the key, so the INSERT was acknowledged while none of its rows were stored and the previous object kept being served. The error is now only absorbed when the object at the key is the one the upload would have produced. Closes #114348.Description
Requested by @ zlareb1 in #114348 (comment).
Client::CompleteMultipartUploadabsorbsNoSuchUploadif aHeadObjectfinds any object at the key.That check is from #56475, whose premise is a completion that succeeded and whose response was lost -
i.e. the completion was replayed and the object is this upload's. Key existence tests neither, so a
genuinely aborted upload against a key holding an unrelated object also passes, and the INSERT is
acknowledged with none of its rows stored.
NO_SUCH_UPLOADis unretryable and excluded fromisTransientCompleteMultipartUploadError, so this rewrite is the only thing between the abort and asilent success. MergeTree over S3 is unaffected: it writes random unique keys.
The rewrite now requires the object to carry the ETag implied by the request's own part list,
md5(concat(binary md5 of each part))-<N>. No extra request, no new state, and both callers(
WriteBufferFromS3,copyS3File) are fixed at once. It fails closed: when the ETag does not match oris not derivable - SSE-KMS, a non-default checksum algorithm, S3 Express, a provider that computes it
differently - the original error is returned, so a replay that used to be absorbed now errors. A failed
INSERT is recoverable; a silently discarded one is not.
A matching ETag proves the payload, not the create-time attributes: a completion may also carry
If-Match/If-None-Match, andCreateMultipartUploadmay carry metadata or a storage class, whichthis layer cannot observe. That residual is pre-existing, strictly less reachable here, and unset on the
in-tree S3 multipart paths. #113994 addresses it in
WriteBufferFromS3, which knows the writer identity.A new integration test fails on master (INSERT acknowledged, old object survives) and passes here, with a
no-fault control. Two unit tests keep #56475 honest: a matching object is absorbed, a foreign one errors.
cc @ scanhex12 @ kssenii @ CheSema
Workflow [PR]
Sync PR [sync-upstream/pr/114375]