Skip to content

Retry transient MinIO InvalidPart on S3 CompleteMultipartUpload - #109364

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-s3-completempu-invalidpart-retry
Jul 12, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-s3-completempu-invalidpart-retry

Conversation

@groeneai

@groeneai groeneai commented Jul 3, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #93192

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

Fixed a transient Code: 499 ... InvalidPart (S3_ERROR) failure on S3 multipart uploads (for example INSERT INTO ... hits_s3). MinIO can briefly report a just-uploaded part as missing on CompleteMultipartUpload; this error is now retried like the already-handled NoSuchKey, bounded by s3_max_unexpected_write_error_retries.

Description

WriteBufferFromS3::completeMultipartUpload() had a retry loop bounded by max_unexpected_write_error_retries that tolerated one known MinIO eventual-consistency quirk, but only NoSuchKey. MinIO also transiently reports a just-uploaded part as missing on completion with InvalidPart (and can with InvalidPartOrder), which is the same class of flake. Those fell into the else branch and threw immediately:

Code: 499. DB::Exception: Message: Unable to parse ExceptionName: InvalidPart
Message: One or more of the specified parts could not be found. ...
(S3_ERROR) (in query: INSERT INTO test.hits_s3 SELECT * FROM test.hits ...)

Root cause of the "Unable to parse ExceptionName" wording: InvalidPart / InvalidPartOrder are not in the AWS SDK's typed S3Errors enum and are not mapped by S3ErrorMapper, so AWSErrorMarshaller::Marshall leaves GetErrorType() == UNKNOWN and keeps the raw code only in GetExceptionName(). A fix keyed on the typed enum would not match, so the retry predicate matches by exception name, mirroring the existing PreconditionFailed string check in the single-part path.

The retry stays bounded by max_unexpected_write_error_retries, logs at INFO like the existing branch, and the terminal throw now reports the actual last error instead of a hardcoded NoSuchKey. InvalidPart is a CompleteMultipartUpload-only error, so the single-part PutObject path is intentionally left unchanged. Sorting parts in ascending order is guaranteed by the request builder, so a genuine (non-transient) InvalidPartOrder cannot originate here.

Regression test: src/IO/tests/gtest_writebuffer_s3.cpp (WBS3/SyncAsync.CompleteMPURetriesInvalidPart) injects InvalidPart on the first CompleteMultipartUpload and asserts the upload then succeeds. It fails on master and passes with this change. The test also fills retryStrategy in the mock client config (the mock builds DB::S3::Client directly, bypassing ClientFactory::create which normally sets it), unblocking the whole MockS3 suite under chassert in debug/sanitizer builds.

Version info

  • Merged into: 26.7.1.838-master (included in 26.7 and later)
  • Backported to: 26.3.40.15

completeMultipartUpload() retried only NO_SUCH_KEY. MinIO also transiently
reports a just-uploaded part as missing on completion with InvalidPart (and
can with InvalidPartOrder), the same eventual-consistency class as the
already-handled NO_SUCH_KEY. Those fell into the else branch and threw
immediately (Code 499), failing e.g. the hits_s3 stateful fixture load.

InvalidPart / InvalidPartOrder are not in the typed S3Errors enum, so the AWS
SDK leaves GetErrorType() == UNKNOWN and keeps the raw code only in
GetExceptionName() (see AWSErrorMarshaller::Marshall). Match by exception name,
mirroring the existing PreconditionFailed string check in the single-part path.
The retry stays bounded by max_unexpected_write_error_retries; the terminal
throw now reports the actual last error instead of a hardcoded NO_SUCH_KEY.

The mock in gtest_writebuffer_s3.cpp builds DB::S3::Client directly, bypassing
ClientFactory::create() which fills retryStrategy; set it here too so
chassert(client_configuration.retryStrategy) does not abort the suite in
debug/sanitizer builds.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. gtest WBS3/SyncAsync.CompleteMPURetriesInvalidPart (sync+async) injects InvalidPart on the first CompleteMultipartUpload via the existing MockS3 injection framework. Deterministic every run.
b Root cause explained? MinIO transiently reports a just-uploaded part as missing on CompleteMultipartUpload with InvalidPart. The retry loop matched only S3Errors::NO_SUCH_KEY (typed enum). InvalidPart/InvalidPartOrder are absent from the typed S3Errors enum and unmapped by S3ErrorMapper, so AWSErrorMarshaller::Marshall sets GetErrorType() == UNKNOWN and keeps the code only in GetExceptionName(). It therefore fell into the else branch and threw Code 499 immediately.
c Fix matches root cause? Yes. The retry predicate now also matches InvalidPart/InvalidPartOrder by exception NAME (the exact shape the SDK produces for these un-typed errors), retried like the already-handled NoSuchKey, bounded by max_unexpected_write_error_retries. Not a band-aid: retrying is precisely the existing design for this eventual-consistency class.
d Test intent preserved / new tests added? New regression test added (CompleteMPURetriesInvalidPart). No existing test weakened. Also set retryStrategy in the mock client config (the mock builds DB::S3::Client directly, bypassing ClientFactory::create which normally fills it), which un-breaks the whole MockS3 suite under chassert in debug/sanitizer builds.
e Both directions demonstrated? Yes. Without the source fix the test FAILS: C++ exception ... "One or more of the specified parts could not be found ..., Key: complete_mpu_invalid_part_retry ..." thrown in the test body. With the fix it PASSES and the object is stored (completion attempted twice: 1 injected fail + 1 success).
f Fix is general across code paths? The single-part PutObject path (makeSinglepartUpload) has the same NoSuchKey-only pattern, but InvalidPart is a CompleteMultipartUpload-only error (a single PUT has no parts), so adding it there would be dead code and is intentionally omitted. copyS3File.cpp is a separate path handled elsewhere. Not guarding a symptom: the error IS the transient condition, matching the existing NoSuchKey handling.
g Fix generalizes across inputs? Matches both InvalidPart and InvalidPartOrder. This is an upload-protocol error, not column/datatype dependent, so type wrappers (Nullable/LowCardinality/Array/...) do not apply. Works for any part count; retry stays bounded by max_unexpected_write_error_retries.
h Backward compatible? Yes. No setting default change, no on-disk/wire/metadata format change, no new validation on existing data; SettingsChangesHistory.cpp not applicable. It only widens a retry predicate: an error that was previously fatal is now retried (bounded), never the reverse.
i Invariants and contracts preserved? The retry re-issues the identical CompleteMultipartUpload (same multipart_upload_id, same already-uploaded parts) — no new state, no lock/ownership change. Parts are always listed in ascending order by the request builder, so a genuine (non-transient) InvalidPartOrder cannot originate here. The terminal throw now reports the actual last error instead of a hardcoded NoSuchKey (strict improvement).

Session id: cron:clickhouse-worker-slot-2:20260703-201700

@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

cc @CheSema @kssenii — could you review? This extends the existing NoSuchKey retry in WriteBufferFromS3::completeMultipartUpload() to also cover the transient MinIO InvalidPart (and InvalidPartOrder), matched by exception name since the AWS SDK leaves those as UNKNOWN type. Closes #93192. Regression test added in gtest_writebuffer_s3.cpp; it also sets retryStrategy on the mock config so the MockS3 suite stops aborting on chassert in debug builds.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [30e8098]

Summary: ✅


AI Review

Summary

This PR widens the transient CompleteMultipartUpload retry predicate to cover MinIO's untyped InvalidPart / InvalidPartOrder responses in both WriteBufferFromS3 and the shared multipart-completion helper used by copyDataToS3File / copyS3File, and it adds focused regression tests for both paths. I did not find remaining correctness, propagation, or evidence gaps in the current head.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 3, 2026
Comment thread src/IO/WriteBufferFromS3.cpp Resolved
…path

The retry predicate was only in WriteBufferFromS3::completeMultipartUpload().
UploadHelper::completeMultipartUpload() in copyS3File.cpp (which backs
copyDataToS3File / copyS3File, i.e. MinIO-backed backups and DiskObjectStorage
server-side copies) still retried only NO_SUCH_KEY, so those flows could still
fail with Code 499 InvalidPart on multipart completion.

Extract the predicate into a shared isTransientCompleteMultipartUploadError()
in S3Common (single source of truth for NO_SUCH_KEY / InvalidPart /
InvalidPartOrder) and use it from both completion sites.

Add a copyDataToS3File regression test that injects InvalidPart on the first
CompleteMultipartUpload and asserts the copy still succeeds. Reading the mock
request body by content length (istream::read) instead of operator<<(rdbuf)
so it works with the ReadBuffer-backed body used by the copy path.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

Follow-up to @clickhouse-gh[bot]'s review: the fix now covers both multipart-completion sites via a shared predicate. Updated pre-PR validation gate for the widened scope.

Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. WBS3Test.CopyDataToS3FileRetriesInvalidPart injects InvalidPart on the 1st CompleteMultipartUpload of a copyDataToS3File flow; fails on demand without the fix.
b Root cause explained? UploadHelper::completeMultipartUpload (copyS3File.cpp, backing copyDataToS3File/copyS3File = backups + DiskObjectStorage server-side copies) retried only NO_SUCH_KEY. MinIO also transiently reports InvalidPart on completion (same eventual-consistency class), which the SDK leaves as GetErrorType()==UNKNOWN with the code only in GetExceptionName(), so the else-branch threw Code 499. Same gap the WriteBufferFromS3 path had.
c Fix matches root cause? Yes. Extracted isTransientCompleteMultipartUploadError() (matches NO_SUCH_KEY + InvalidPart/InvalidPartOrder by exception name) into S3Common; both completion sites use it. Not centralized in DB::S3::Client::CompleteMultipartUpload because both callers already wrap it in their own max_unexpected_write_error_retries loop.
d Test intent preserved / new tests added? Added CopyDataToS3FileRetriesInvalidPart for the helper path (alongside the existing CompleteMPURetriesInvalidPart for WriteBufferFromS3). No existing test weakened.
e Both directions demonstrated? Yes. Without the copyS3File change the new test FAILS (throws Code: 499 ... One or more of the specified parts could not be found); with it, PASSES. Full WBS3 suite: 29 passed / 1 skipped.
f Fix is general across code paths? Yes. This commit closes exactly the sibling path the reviewer flagged. The two ->CompleteMultipartUpload( call sites in the tree (WriteBufferFromS3.cpp, copyS3File.cpp) now share one predicate. Single-part PutObject path intentionally untouched (InvalidPart is CompleteMPU-only).
g Fix generalizes across inputs? Predicate matches both InvalidPart and InvalidPartOrder by name (neither is in the typed S3Errors enum). Retry stays bounded by max_unexpected_write_error_retries; ascending part order means a genuine InvalidPartOrder cannot originate at these call sites.
h Backward compatible? Yes. No setting/format/wire change; only widens which transient errors are retried within the existing bounded loop.
i Invariants and contracts preserved? Yes. Retry loop bound, abort-on-final-failure, and part-list ordering unchanged. The mock harness now reads request bodies by content length (istream::read, i.e. what the SDK does) instead of operator<<(rdbuf), which is required for the ReadBuffer-backed body used by the copy path and is behaviorally identical for the memory-backed bodies the other 28 tests use (all still pass).

Session id: cron:clickhouse-worker-slot-3:20260703-215300

@clickhouse-gh

clickhouse-gh Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.50% 85.60% +0.10%
Functions 92.60% 92.70% +0.10%
Branches 77.70% 77.80% +0.10%

Changed lines: Changed C/C++ lines covered: 106/111 (95.50%) · Uncovered code

Full report · Diff report

@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.

This is funny.

@alexey-milovidov alexey-milovidov self-assigned this Jul 12, 2026
@alexey-milovidov
alexey-milovidov merged commit a5a740f into ClickHouse:master Jul 12, 2026
173 of 174 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 12, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…mpletempu-invalidpart-retry

Retry transient MinIO InvalidPart on S3 CompleteMultipartUpload
@PedroTadim

Copy link
Copy Markdown
Member

Have to backport this to fix CI

@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 2, 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 Oct 2, 2026
PedroTadim added a commit that referenced this pull request Oct 2, 2026
Backport #109364 to 26.3: Retry transient MinIO InvalidPart on S3 CompleteMultipartUpload
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors 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-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.3-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CompleteMultipartUploadRequest fails with InvalidPart Message: One or more of the specified parts could not be found.

6 participants