Repository navigation
Fix S3 native copy silently ignoring the requested byte range - #112392
Merged
murphy-4o merged 2 commits intoJul 30, 2026
Merged
Conversation
copyS3File() accepted `src_offset`/`src_size` to copy a part of a source
object, but nothing told it whether the copy was actually partial: the route
was chosen purely by size, and the single-operation path (CopyObject) carries
no byte range. A partial copy that fell under max_single_operation_copy_size
was therefore issued as a whole-object CopyObject, copying the entire source
instead of the requested range.
Rather than add a flag to the existing function, split the two meanings into
two explicit entry points, so a whole-object copy and a ranged copy cannot be
confused:
* copyS3File(..., src_size, ...) copies the whole source object.
* copyS3FileRange(..., src_offset, src_size, ...) copies exactly
[src_offset, src_offset + src_size) of a larger source. It always uses
multipart UploadPartCopy, which sets a CopySourceRange per part, or the
buffered ranged read when multipart copy is unavailable; it never reaches
CopyObject (enforced by a chassert).
Both forward to a shared helper with an internal is-ranged flag, so no caller
can leave that decision at a wrong default.
The backup readers get the same split: IBackupReader::copyFileToDisk() keeps
its whole-file meaning, and the new copyFileRangeToDisk() copies exactly
[offset, size). The buffered implementation of the latter lives once in
BackupReaderDefault, so the Disk, File, Azure and Memory readers inherit a
correct ranged copy without touching their whole-object fast paths (fs::copy,
IDisk::copyFile and the Azure native copy carry no range). Only
BackupReaderS3 overrides it, to use copyS3FileRange().
BackupWriterS3::copyFileFromDisk() now decides between the two by comparing
the requested length against the real size of the source file, instead of
testing `start_pos != 0`: a prefix [0, length) of a bigger file is a range
too. For an encrypted source the entry's size is the encrypted one, so the
comparison uses getEncryptedFileSize(); the native path is only taken when the
disk's `is_encrypted` matches `copy_encrypted`, so that call is never made on
a disk without encryption support. The size comes from the disk's metadata,
which the preceding getBlobPath() call has already consulted, so this costs no
extra request to object storage.
Tests: CopyS3FileRoutingTest covers a whole object -> CopyObject, a mid-object
range -> UploadPartCopy, and a prefix range [0, n) with n < size ->
UploadPartCopy.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [5c28acb] Summary: ❌
AI ReviewSummaryThis PR splits whole-object and ranged S3 copy paths so partial copies can no longer silently fall through Final VerdictStatus: ✅ Approve |
AWS accepts x-amz-copy-source-range only when the source object is greater than 5 MB and answers InvalidRequest otherwise, so a range of a smaller source cannot be server-side copied at all. Decide before issuing any request: a ranged copy of a source at or below that size goes through the buffered ranged read, everything else keeps the multipart UploadPartCopy path. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 227/261 (86.97%) · Uncovered code |
Merged
via the queue into
ClickHouse:master
with commit Jul 30, 2026
24fce03
351 of 354 checks passed
10 of 30 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Description
Extracted from #111030 at review request.
copyS3File()takessrc_offset/src_size, but picked its route by size alone: a partial copy belowmax_single_operation_copy_sizewent throughCopyObject, which carries no byte range and copies the entire source. The range parameters silently did not work.Split into two entry points rather than adding a flag (a prefix range
[0, n)is partial despiteoffset == 0):copyS3File(...)— whole object; thesrc_offsetparameter is removed.copyS3FileRange(offset, size, ...)— always multipartUploadPartCopy, neverCopyObject.Same split on the reader:
IBackupReader::copyFileToDisk()is unchanged, and a newcopyFileRangeToDisk()copies an explicit range (buffered default inBackupReaderDefault, native override inBackupReaderS3).BackupWriterS3::copyFileFromDisk()compares the copied length against the real source size — the encrypted size for encrypted sources — instead of guessing from the offset.Not reachable today: the only variable-offset caller is taken solely for immutable-file entries, which never match a base backup partially.
copyFileRangeToDisk()is used by #111030.Version info
26.8.1.396(included in26.8and later)