Skip to content

Support copying an empty object on S3-compatible storages that reject a zero-size CopyObject - #129316

Merged
CheSema merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-copys3file-empty-object-fallback
Nov 6, 2026
Merged

CheSema merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-copys3file-empty-object-fallback

Conversation

@groeneai

@groeneai groeneai commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #129218
Related: #113825

Changelog category (leave one):

  • Improvement

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

Better compatibility with S3-compatible storages that reject CopyObject of an empty object (for example, RustFS): copying an empty object, such as removing an empty file from a plain_rewritable disk, now falls back to a regular upload. A rejected CopyObject is retried as a multipart copy only when multipart copy is allowed (s3_allow_multipart_copy) and the source is larger than 5 MB. Closes #129218.

Description

MinIO and AWS accept a CopyObject of an empty object, but some S3-compatible storages reject it with InvalidArgument, InvalidRequest or EntityTooLarge (RustFS does). There, copying an empty object fails with LOGICAL_ERROR Chosen multipart upload for an empty file. This must not happen instead of completing; debug builds and servers with abort_on_logical_error abort. A plain_rewritable S3 disk reaches it when it unlinks an empty file, because the unlink copies the blob first. Real failing job: STID 0250-04e2 in the RustFS CI experiment #113825 (report).

CopyFileHelper::processCopyRequest retries a rejected whole-object copy as a multipart upload copy without looking at the size, and UploadHelper::calculatePartSize rejects size 0 on purpose. One step further, CopyDataToFileHelper::processPutRequest did the same for a rejected zero-size PutObject (EntityTooLarge / InvalidRequest).

Change:

  • The retry (an UploadPartCopy, which always sends a byte range) now requires what the routing already requires: multipart copy allowed and a source above the 5 MB byte-range minimum. Every other case, an empty object included, takes the existing regular-upload fallback, as AccessDenied already does, so the copy completes.
  • A rejected zero-size PutObject reports the endpoint's own error, since nothing else can write an empty object.

The guard in calculatePartSize is unchanged.

Validation: four new CopyS3FileRoutingTest gtest cases (empty, small, disabled s3_allow_multipart_copy with a positive control, rejected empty PutObject), with a CopyObject rejection hook in the mock client (MinIO and AWS accept such a copy, so a stateless test cannot reach the fallback). Without the fix the empty-object cases abort with this LOGICAL_ERROR and the others fail; reverting any single term reddens its case; with the fix all pass, 50/50.


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

Version info

  • Merged into: 26.11.1.1499-master (included in 26.11 and later)

groeneai and others added 3 commits November 4, 2026 13:43
A whole-object CopyObject rejected with InvalidArgument, InvalidRequest,
EntityTooLarge (or the GCS rewrite error) is retried as a multipart upload
copy whenever the client supports multipart copy, regardless of the object
size. For an empty object UploadHelper::calculatePartSize rejects size 0
with LOGICAL_ERROR "Chosen multipart upload for an empty file. This must
not happen", which aborts debug builds and servers with
abort_on_logical_error. It is reached on endpoints that reject a zero-size
CopyObject (RustFS), e.g. when a plain_rewritable S3 disk unlinks an empty
file, because the unlink copies the blob first (STID 0250-04e2 in the CI of
ClickHouse#113825).

An empty object now takes the existing regular-upload fallback, as it does
for AccessDenied or without multipart copy support: a single-part PutObject
of an empty body, so the copy completes.

The same precondition was violated one step further: a zero-size PutObject
rejected with EntityTooLarge / InvalidRequest also fell back to a multipart
upload. A multipart upload cannot write an empty object either, so the
endpoint's own error is reported instead.

The guard in calculatePartSize stays as the invariant; the callers were
wrong.

Closes ClickHouse#129218

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The multipart retry of a rejected whole-object CopyObject is an
UploadPartCopy, which always sends a byte range. It now requires what the
copy routing already requires: multipart copy allowed
(s3_allow_multipart_copy) and a source larger than the 5 MB byte-range
minimum S3 accepts. Every other case, an empty object included, takes the
existing regular-upload fallback.

Before, the retry ignored s3_allow_multipart_copy, and for a source of
5 MB or less it issued a byte-range copy that S3 rejects with
InvalidRequest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the comment on the rejected-CopyObject fallback condition to one line; the 5 MB rule is documented at MIN_SOURCE_SIZE_FOR_RANGE_COPY.

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

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)
Finding Verdict
⚠️ The multipart retry after a rejected CopyObject ignored s3_allow_multipart_copy and the 5 MB byte-range minimum (size 0 is its extreme case) AGREE, fixed: the retry now uses the same eligibility as the routing
💡 The regular-upload branch keeps its existing log text noted, not blocking

The second review round on the fix returned no findings.

@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. unit_tests_dbms --gtest_filter=CopyS3FileRoutingTest.RejectedCopyOfEmptyObjectUsesRegularUpload aborts on every run without the fix with Logical error: 'Chosen multipart upload for an empty file', same stack as STID 0250-04e2 in #113825.
b Root cause explained? Yes. A rejected whole-object CopyObject is retried as a multipart copy without the checks the routing applies (multipart copy allowed, source above the 5 MB byte-range minimum); for size 0 calculatePartSize rejects it. A rejected zero-size PutObject had the same multipart fallback.
c Fix matches root cause? Yes. The retry uses the routing's eligibility; the upload fallback skips size 0; the guard in calculatePartSize stays.
d Test intent preserved / new tests added? Yes. Four new gtest cases plus a CopyObject injection hook in the mock client; no existing test changed.
e Both directions demonstrated? Yes. Without the fix the empty-object cases abort and the small-object and disabled-setting cases fail; reverting any single new term reddens its case; all pass with the fix, 50/50.
f Fix is general across code paths? Yes. Every caller of performMultipartUpload was checked: two fixed, the others are gated by size > threshold or never get a zero-length range.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. All three copy rejections and both upload rejections; sizes 0, 100 B, exactly 5 MB and above 5 MB; s3_allow_multipart_copy on and off.
h Backward compatible? (maintainer-approved exception only) Yes. No setting default or format change; a source above 5 MB with multipart copy allowed keeps the multipart retry.
i Invariants and contracts preserved? Yes. No multipart upload for an empty object, no byte-range copy of a source S3 cannot range-copy; error propagation and written metadata match the existing AccessDenied fallback.

Session id: cron:clickhouse-impl-slot-4:20261104-141900

@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @CheSema @alesapin, could you review this and add the can be tested label so CI runs? When an endpoint rejects a whole-object CopyObject, copyS3File now retries it as a multipart copy only if multipart copy is allowed and the source is above the 5 MB byte-range minimum, so an empty object takes the existing regular-upload fallback instead of hitting the Chosen multipart upload for an empty file logical error.

@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6cc74a3]

Summary: ✅


AI Review

Summary

The change prevents a rejected empty-object CopyObject or PutObject from reaching the non-empty multipart-upload invariant. It also makes the multipart-copy retry respect s3_allow_multipart_copy and the source-size requirement. The four focused regression tests cover successful recovery, endpoint-error propagation, the size boundary, and both setting values. No actionable findings in the current diff.

Missing context / blind spots
  • ⚠️ The sanitizer unit tests and unit-test bugfix validation are still pending in the CI report. The author reports passing local runs and failing runs without the fix; I could not independently rerun them because this checkout has no build directory or test binary. Completed CI jobs would close this verification gap.
Final Verdict

Status: ✅ Approve. No code changes requested; normal CI validation remains pending.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default can be tested Allows running workflows for external contributors comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. labels Nov 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6cc74a34f with master 989ecd896 (stripped binary size, per-symbol sizes and ThinLTO time; 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, 11 s compile time in total, 7 of them have a recent master baseline.

Job report

@CheSema CheSema self-assigned this Nov 5, 2026
@CheSema
CheSema enabled auto-merge November 5, 2026 14:00
@groeneai groeneai changed the title Fix copyS3File of an empty object when the endpoint rejects CopyObject Support copying an empty object on S3-compatible storages that reject a zero-size CopyObject Nov 5, 2026
@CheSema
CheSema disabled auto-merge November 6, 2026 09:17
@CheSema
CheSema added this pull request to the merge queue Nov 6, 2026
Merged via the queue into ClickHouse:master with commit 3f4c574 Nov 6, 2026
366 of 367 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 Nov 6, 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 comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. pr-bugfix Pull request with bugfix, not backported by default 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.

copyS3File turns a rejected zero-size CopyObject into LOGICAL_ERROR

3 participants