Skip to content

Reject s3_strict_upload_part_size greater than s3_max_upload_part_size - #129578

Merged
PedroTadim merged 4 commits into
ClickHouse:masterfrom
groeneai:s3-reject-strict-above-max-upload-part-size
Nov 6, 2026
Merged

PedroTadim merged 4 commits into
ClickHouse:masterfrom
groeneai:s3-reject-strict-above-max-upload-part-size

Conversation

@groeneai

@groeneai groeneai commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #103394
Related: #128857

Changelog category (leave one):

  • Improvement

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

An S3 disk or query whose s3_strict_upload_part_size is greater than s3_max_upload_part_size is now rejected up front with INVALID_SETTING_VALUE, as Azure already does. Before, such a configuration was accepted and every write larger than max(s3_max_single_part_upload_size, s3_max_upload_part_size) failed with the logical error Part size exceeded max_upload_part_size. To keep such a configuration working, lower s3_strict_upload_part_size or raise s3_max_upload_part_size.

Description

La Casa Del Dolor (amd_debug) hit Logical error: 'Part size exceeded max_upload_part_size ... part size 29304992, max_upload_part_size 16777216' in WriteBufferFromS3::writePart. The S3 disk had s3_strict_upload_part_size 83 MiB and s3_max_upload_part_size 16 MiB.

S3RequestSettings::validateUploadSettings runs every part-size check under if (!strict_upload_part_size), so strict is never compared with max. A non-zero strict size selects fixed-size buffers, a write larger than max_single_part_upload_size goes multipart, and its first part exceeds max. The Azure version rejects this (#103394). The check now runs in both modes, before the S3 client is built.

The Dolor generator draws s3_strict_upload_part_size up to 100 MiB against a 16 MiB floor for max. It is now capped at 16 MiB (bits=24), as #128857 did for Azure; without that, the new check would stop such a server from starting.

Category Improvement: the only symptom on released versions is a late logical error from a contradictory configuration.

Validation: the new test fails on master, passes 50/50 with randomized settings, and flipping > to >= breaks its strict == max case. A 3 MB write with strict 2 MiB and max 1 MiB aborts the old binary through s3() and through an S3 disk. Generator: 15.32% strict > max in 1M draws before, 0 after.

Not changed: with strict set, S3 still skips its min_upload_part_size checks, and settings are still validated per layer, so a layered config whose merged settings are valid can be rejected (#129670). With s3_validate_request_settings = 0 the logical error in writePart stays reachable. #128707 (open) edits the same properties.py line.

🤖 Generated with Claude Code


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

Version info

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

groeneai and others added 2 commits November 5, 2026 18:31
S3RequestSettings::validateUploadSettings ran every part-size check under
`if (!strict_upload_part_size)`, so a non-zero strict size was never compared
with max_upload_part_size. A strict size selects FixedSizeBufferAllocationPolicy,
so WriteBufferFromS3 fills buffers of up to strict bytes; a write larger than
max_single_part_upload_size goes multipart and writePart throws the
LOGICAL_ERROR "Part size exceeded max_upload_part_size" on the first part
(La Casa Del Dolor (amd_debug), STID 2991-407b: strict 83 MiB, max 16 MiB).

Mirror the Azure check (cc4b9fe, ClickHouse#103394): reject strict > max with
INVALID_SETTING_VALUE in both modes. Every S3 request-settings entry point goes
through this function (disk creation, config reload, <s3> sections, s3() and
S3 engine query settings, query overrides on an S3 disk, BACKUP/RESTORE), so
such a configuration now fails up front instead of on the first large write.

La Casa Del Dolor drew s3_strict_upload_part_size up to 100 MiB against a
16 MiB floor for s3_max_upload_part_size (15.32% strict > max in direct draws,
3.83% of generated S3 disks). Cap it at 16 MiB with bits=24, as ClickHouse#128857 did for
Azure, so the new check does not stop Dolor servers from starting.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop a comment that restates the new check's error message.

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

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding) plus my own cold review (2 nits).

# Sev Finding Verdict Evidence / action
1 ❌ On config reload, S3ObjectStorage::applyNewSettings can merge a disk section and a matching <s3> endpoint section that are each valid into strict > max without re-validating, so a background write still hits the late logical error DISAGREE (out of scope: separate PR) The unvalidated merge is pre-existing code this PR does not touch and lets every rule of validateUploadSettings through alike; every foreground read/write of such a disk re-validates the installed settings and is rejected with INVALID_SETTING_VALUE
2 💡 s3_validate_request_settings = 0 still reaches the runtime guard DISAGREE The setting skips all checks by contract, unchanged
3 💡 Open #128707 edits the same properties.py line AGREE Noted in the description

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261105-183400

@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse local with --s3_strict_upload_part_size=2097152 --s3_max_upload_part_size=1048576 --s3_max_single_part_upload_size=1024 and INSERT INTO FUNCTION s3(...) SELECT randomString(3000000) aborts master every run with Logical error: 'Part size exceeded max_upload_part_size ... part size 2097152, max_upload_part_size 1048576' at WriteBufferFromS3::writePart, the CI site. Same through a disk(type = 's3', ...) MergeTree table.
b Root cause explained? Yes. S3RequestSettings::validateUploadSettings runs every part-size check under if (!strict_upload_part_size), so strict is never compared with max; fixed-size buffers of strict bytes then exceed max on the first multipart part.
c Fix matches root cause? Yes. The missing check is added where all S3 request settings are validated, mirroring Azure (#103394); the runtime guard in writePart is unchanged.
d Test intent preserved / new tests added? New 05508_s3_strict_upload_part_size_above_max: an S3 disk case, an s3() query-settings case and a strict == max case. The Dolor generator change ships no test, as in #128857.
e Both directions demonstrated? Yes. On master statements 1 and 2 succeed (test red); with the fix 50/50 green with randomized settings; > mutated to >= reddens the strict == max case. With the CI disk values master starts, the fix refuses the config.
f Fix is general across code paths? Yes. Rejected at disk creation (startup and disk()), s3() read and write, S3 engine INSERT, query overrides on an S3 disk, BACKUP TO S3. Azure already had it; GCS uses the S3 settings.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. strict == max accepted (pinned by the mutation), strict = 0 unaffected, the CI magnitudes rejected; a 14 MB write with strict = max = 6 MiB completes. UInt64 settings, no type wrappers.
h Backward compatible? (maintainer-approved exception only) No default changes. A configuration with strict > max is now rejected up front instead of failing every large write with a logical error; the changelog entry names the workaround.
i Invariants and contracts preserved? Yes. "An uploaded part is never larger than max_upload_part_size" now holds whenever validation runs; s3_validate_request_settings = 0 still skips all checks, as before.

Session id: cron:clickhouse-impl-slot-5:20261105-175400

@clickhouse-gh clickhouse-gh Bot added the can be tested Allows running workflows for external contributors label Nov 5, 2026
@groeneai

groeneai commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator Author

cc @PedroTadim @Michicosun, could you review this? S3 request-settings validation compared part sizes only when strict_upload_part_size was 0, so strict > max was accepted and the first multipart part failed with a logical error in WriteBufferFromS3::writePart; the check now runs in both modes (as Azure does), and the La Casa Del Dolor generator caps the strict size at 16 MiB.

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Nov 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [dc2069f]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) FAIL
05401_quota_on_profile_events_query_result_cache FAIL cidb IGNORED
03273_group_by_in_order_still_used_when_group_by_key_doesnt_match_order_by_key NOT_FAILED cidb IGNORED
01513_optimize_aggregation_in_order_memory_long NOT_FAILED cidb IGNORED
01283_max_threads_simple_query_optimization NOT_FAILED cidb IGNORED
01414_push_predicate_when_contains_with_clause NOT_FAILED cidb IGNORED

AI Review

Summary

PR #129578, reviewed at dc2069f7254e3234843f79e634f5517f762486a3, rejects s3_strict_upload_part_size above s3_max_upload_part_size, caps the Dolor generator accordingly, and adds a stateless regression test. One previously reported regression remains: validation can reject valid effective settings before endpoint overrides are applied. No distinct new inline findings.

Missing context / blind spots
  • ⚠️ Current-head functional CI is still running, and no local ClickHouse binary was available for independent execution. Completed current-head regression results would close this validation gap.
Findings

⚠️ Majors

  • src/IO/S3RequestSettings.cpp:218 — Validate effective settings after endpoint overrides. [dismissed by author -- https://github.com/Reject s3_strict_upload_part_size greater than s3_max_upload_part_size #129578#discussion_r4484985380] The author deferred this to PR #129670, which remains open; the regression is still present in this head. With global <s3> max_upload_part_size = 16777216, an endpoint override of 67108864, and query s3_strict_upload_part_size = 33554432, the effective 32 MiB / 64 MiB pair is valid. However, BackupReaderS3 and BackupWriterS3 call loadFromConfig at src/Backups/BackupIO_S3.cpp:398 and :537, validating the intermediate 32 MiB / 16 MiB pair before applying the endpoint override. Previously working BACKUP and RESTORE operations therefore fail with INVALID_SETTING_VALUE; ordinary s3 queries have the same ordering problem. Defer intermediate validation and retain validation after all overrides, either by landing the prerequisite fix first or incorporating it here.
Tests
  • ⚠️ The new test covers invalid standalone settings and equality, but not valid merged settings. Add a focused regression using the global maximum, endpoint maximum, and query strict size above, proving BACKUP, RESTORE, and an s3 query accept the final valid configuration.
Final Verdict

Status: ⚠️ Request changes. Ensure the final-settings validation fix and its regression coverage land before this new check introduces the known rejection of valid configurations. The existing inline thread is left unchanged; no duplicate comments were posted.

ErrorCodes::INVALID_SETTING_VALUE,
"Setting max_part_number cannot be zero");

if ((*this)[S3RequestSetting::strict_upload_part_size] > (*this)[S3RequestSetting::max_upload_part_size])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Major: validate the effective backup settings after endpoint overrides

BackupReaderS3 and BackupWriterS3 call S3Settings::loadFromConfig before merging endpoint settings (src/Backups/BackupIO_S3.cpp:398 and :537). The request-settings constructor used there fills missing config fields from query settings and immediately calls this validator.

For example, configure global <s3><max_upload_part_size>16777216</max_upload_part_size>…</s3>, give the matching endpoint max_upload_part_size = 67108864, and run BACKUP or RESTORE with SETTINGS s3_strict_upload_part_size = 33554432. This new check throws on the temporary 32 MiB strict / 16 MiB maximum pair before the endpoint's 64 MiB maximum is merged. The effective 32 MiB / 64 MiB configuration is valid and was accepted before this change, so legitimate backups and restores now fail.

Defer validation of these intermediate settings until endpoint and query overrides have been applied, retain validation of the final settings in both backup paths, and add a regression for this layered configuration.

@PedroTadim PedroTadim self-assigned this Nov 5, 2026
@PedroTadim

Copy link
Copy Markdown
Member

🕵️ @groeneai The new check and the Dolor cap look right. With bits=24 the rare maximum is 2**24 - 1, so strict stays at or below the 16 MiB floor of s3_max_upload_part_size, as #128857 does for Azure.

The LOGICAL_ERROR in WriteBufferFromS3::writePart is still reachable without this check, in three ways:

  • s3_validate_request_settings = 0, which BuzzHouse already randomizes (SessionSettings.cpp). Turning validation off shouldn't let a query trigger a logical error.
  • The disk reload merge in S3ObjectStorage::applyNewSettings, which the bot flagged.
  • The backup path. BackupWriterS3 and BackupReaderS3 validate the <s3> layer in loadFromConfig, then merge the endpoint settings with updateIfChanged without validating again. So an <s3> strict of 32 MiB and an endpoint max of 16 MiB pass each check separately and fail late on the first part.

A one-line fix covers all three: throw INVALID_CONFIG_PARAMETER instead of LOGICAL_ERROR there, as the max_part_number check a few lines above already does. The early check then stays as the friendly error at configuration time.

The bot's other finding holds too, in the opposite direction: validating each layer separately can reject an endpoint override that would make the merged settings valid. But the existing max_upload_part_size < min_upload_part_size check already has the same problem, so validating once on the merged settings is better left to a follow-up.

@clickhouse-gh clickhouse-gh Bot added the comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. label Nov 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing dc2069f72 with master 0b4cecfc1 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of d2364ed14; 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, 9 s compile time in total, 7 of them have a recent master baseline.

Job report

WriteBufferFromS3::writePart threw LOGICAL_ERROR when a part was larger than
max_upload_part_size. That state is reachable from configuration, not only from
a bug: with s3_validate_request_settings = 0, or after a config reload that
merges an S3 disk section with an endpoint section without validating the
result. A strict_upload_part_size above max_upload_part_size then aborted debug
and sanitizer builds on the first multipart part.

Throw INVALID_CONFIG_PARAMETER instead, as the max_part_number check right above
already does. The up-front check in validateUploadSettings stays as the error
at configuration time.

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

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Done in c083ee2: writePart now throws INVALID_CONFIG_PARAMETER, and the test has an s3_validate_request_settings = 0 case that aborted the previous head with the logical error.

I'll send validation of the merged settings as a separate PR. The per-layer check also hits plain s3() queries, not only backups: with a profile s3_strict_upload_part_size of 32 MiB, a global <s3> max_upload_part_size of 16 MiB and an endpoint section that raises it to 64 MiB, INSERT INTO FUNCTION s3(...) and SELECT ... FROM s3(...) fail with INVALID_SETTING_VALUE (measured on this PR's build).

@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Validation of the merged S3 request settings is in #129670.

Comment thread src/IO/WriteBufferFromS3.cpp Resolved
This reverts commit c083ee2.

The strict > max check in validateUploadSettings is what fixes the CI failure,
so this PR does not need to change the error code in WriteBufferFromS3::writePart.
The s3_validate_request_settings = 0 case of the test goes with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PedroTadim
PedroTadim enabled auto-merge November 6, 2026 12:04
@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - dc2069f

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05401_quota_on_profile_events_query_result_cache flaky, not in this PR's diff: Code: 201, Quota ... has been exceeded: SelectQuery = 2/1 when the quota user's reads run on parallel replicas; 48 of 48 reruns passed; the same failure appeared on master and on 16 other PRs in the last 30 days #129672 (mine, open)
Mergeable Check / PR praktika rollups of the row above #129672 (mine, open)

CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261106-123005

@PedroTadim

Copy link
Copy Markdown
Member

🕵️ @groeneai For a follow-up PR: with a strict size set, S3RequestSettings::validateUploadSettings skips the min_upload_part_size checks, while Azure's RequestSettings::validateUploadSettings keeps them and only skips the multiply-factor ones. Master accepts both of these:

  • s3_strict_upload_part_size = 1048576, s3_max_upload_part_size = 1048576, s3_min_upload_part_size = 16777216
  • s3_strict_upload_part_size = 1048576, s3_min_upload_part_size = 0

WriteBufferFromS3 ignores the min size in strict mode, so writes work. But copyS3File does not use the strict size and checks min and max again in calculatePartSize, so a native copy (a backup to S3, a copy between S3 disks) later fails with INVALID_CONFIG_PARAMETER: max_upload_part_size must not be less than min_upload_part_size or min_upload_part_size must not be 0. This doesn't lead to a logical error, but moving the two min checks out of if (!strict_upload_part_size), as Azure does, would reject such a configuration up front.

@PedroTadim

Copy link
Copy Markdown
Member

The CI failure is unrelated

@PedroTadim
PedroTadim added this pull request to the merge queue Nov 6, 2026
@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Acknowledged. I'm investigating moving the two min_upload_part_size checks out of if (!strict_upload_part_size) in S3RequestSettings::validateUploadSettings; I'll follow up here with a separate PR (or my findings) shortly.

Merged via the queue into ClickHouse:master with commit 1f96853 Nov 6, 2026
184 of 186 checks passed
@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Opened the follow-up: #129747. The two min_upload_part_size checks (not zero, not above max_upload_part_size) now run whatever the strict size, as in Azure, so both configurations you listed are rejected up front with INVALID_SETTING_VALUE instead of failing later in copyS3File.

jsc0218 pushed a commit to jsc0218/ClickHouse that referenced this pull request Nov 6, 2026
… set

S3RequestSettings::validateUploadSettings ran the "min_upload_part_size
cannot be zero" and "max_upload_part_size can't be less than
min_upload_part_size" checks only when no strict part size was set.
Writes with a strict size use fixed-size parts and never read the min,
but copyS3File / copyDataToS3File ignore the strict size and split by
min and max in calculatePartSize. So such a configuration was accepted,
and a native copy (a BACKUP to S3, a copy between S3 disks) failed
later with INVALID_CONFIG_PARAMETER.

Run both checks in both modes, as Azure's
RequestSettings::validateUploadSettings already does (ClickHouse#103394). Only the
multiply-factor checks stay strict-only; without a strict size nothing
changes.

Test 05508: the three existing statements set s3_min_upload_part_size
to 1 MiB, since the default 16 MiB min is now rejected with a 1 MiB max;
this also keeps the strict > max cases testing only that check. New
cases: an S3 disk and s3() for each check, and a BACKUP.

Requested in
ClickHouse#129578 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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. manual approve Manual approve required to run CI pr-improvement Pull request with some product improvements 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.

3 participants