Skip to content

Fix S3Queue ALTER TABLE ... MODIFY SETTING applying unconverted and unvalidated values - #122986

Open
groeneai wants to merge 7 commits into
ClickHouse:masterfrom
groeneai:groeneai-s3queue-alter-setting-values
Open

groeneai wants to merge 7 commits into
ClickHouse:masterfrom
groeneai:groeneai-s3queue-alter-setting-values

Conversation

@groeneai

@groeneai groeneai commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #108283
Related: #103417

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 ALTER TABLE ... MODIFY SETTING of S3Queue and AzureQueue tables. A value written as a string (for example polling_min_timeout_ms = '20000') is now converted as in CREATE instead of failing with BAD_GET, and the new settings are validated before anything is changed. Before, a failed statement could leave its other settings changed in Keeper, and a value that CREATE rejects (for example processing_threads_num = 0) was accepted, which made the table fail to attach after a restart; cleanup_interval_min_ms set to cleanup_interval_max_ms + 1 also crashed the server.

Description

On 26.9.6.6, ALTER TABLE <S3Queue table> MODIFY SETTING polling_min_timeout_ms = '20000' fails with BAD_GET although CREATE accepts it, and MODIFY SETTING cleanup_interval_min_ms = 1001 with a maximum of 1000 crashes the server with SIGFPE.

Root cause. StorageObjectStorageQueue::alter hands the raw literals to typed safeGet reads and never runs the conversion and checks of CREATE/ATTACH. Keeper is written first, so a later failing read leaves it changed: after MODIFY SETTING after_processing = 'delete', polling_min_timeout_ms = '10000' the next ATTACH fails with METADATA_MISMATCH. -1, 5000000000 for a UInt32 setting, processing_threads_num = 0 or a minimum above the maximum go into the definition, which the next ATTACH rejects. A minimum of the maximum plus one makes generateRescheduleInterval divide by zero. Tables with the same keeper_path share these bounds, so a value valid for the altered table can still invert them.

Change. Before changing anything, alter loads and validates the new definition's settings as ATTACH does and applies the typed values; a bad value fails with the CREATE error and changes nothing. Change detection resolves old setting names and compares converted values, so '4' over a stored 4 is not a change. generateRescheduleInterval returns the minimum for inverted bounds. A Keeper or disk fault after the Keeper write can still split the state, as before.

Validation. 05293_s3queue_alter_setting_values fails on master and passes with the fix (50/50 randomized runs).

🤖 Generated with Claude Code


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

groeneai and others added 2 commits September 29, 2026 22:22
…applying them

`StorageObjectStorageQueue::alter` passed the literals of `MODIFY SETTING` as parsed
(`String` for '20000', `Int64` for -1) to 36 typed `Field::safeGet` reads in
`ObjectStorageQueueMetadata::alterSettings`, the member chain of `alter` and
`ObjectStorageQueueMetadata::updateSettings`, while `CREATE`/`ATTACH` convert every value
(`ObjectStorageQueueSettings::loadFromQuery`) and check the cross-setting rules
(`validateSettings`).

Consequences, observed on master 80508bd and on the official 26.9.6.6 build:
- `polling_min_timeout_ms = '20000'` (accepted by CREATE) failed with BAD_GET.
- `alterSettings` writes Keeper before the member chain runs, so
  `after_processing = 'delete', polling_min_timeout_ms = '10000'` failed with BAD_GET
  after Keeper already said `delete`, and the next ATTACH failed with METADATA_MISMATCH.
- `-1` for a UInt64 setting and `5000000000` for a UInt32 setting were applied as
  18446744073709551615 and 705032704, and `processing_threads_num = 0` or
  `after_processing = 'tag'` without a key were accepted. Each was written into the
  definition, which the next ATTACH rejected.
- `cleanup_interval_min_ms = cleanup_interval_max_ms + 1` made `generateRescheduleInterval`
  compute `rng() % 0`: SIGFPE in the cleanup task about 1 s after the ALTER, and after the
  restart the table did not load.

Now `alter` loads the settings of the new definition with `loadFromQuery` and
`validateSettings` (is_attach = true, as ATTACH does) before the first state change, and
uses the typed values for the changed settings. A bad value fails with the CREATE error and
changes nothing. AzureQueue shares the code.

The two cleanup bounds live in the `ObjectStorageQueueMetadata` that all tables of a
server with the same `keeper_path` share, and `updateSettings` changes only the bound that
was altered. With table `a` at 100/100 and table `b` on the same path, `ALTER TABLE b
MODIFY SETTING cleanup_interval_min_ms = 101` is valid for `b`, left the bounds at 101/100
and crashed the cleanup task the same way. `generateRescheduleInterval` now returns the
minimum when the bounds are inverted.

Test 05293_s3queue_alter_setting_values fails on master and passes with the fix (50/50
randomized runs). Mutants without the typed values, with the validation after the Keeper
write, without the validation, without the `cleanup_interval_min_ms` check, and without
the guard in `generateRescheduleInterval` each fail it. The integration test
test_storage_s3_queue/test_4.py::test_alter_settings passes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the two-line comment above the settings validation in StorageObjectStorageQueue::alter to one line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet labels Sep 29, 2026
@groeneai

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

Pre-publication review by an independent model (engine: codex; 3 rounds, 3 findings, the last round clean) plus my own review.

# Sev Finding Verdict Evidence / action
1 ⚠️ The test pinned neither cleanup_interval_min_ms = cleanup_interval_max_ms + 1 (the SIGFPE case) nor an out-of-range UInt32 value, so removing the cleanup check in validateSettings left it green AGREE, fixed in this PR two rejected ALTERs, a live read of both cleanup settings before DETACH, both in the read after ATTACH; a mutant without the check fails the test
2 ⚠️ The cleanup bounds belong to the metadata shared by all tables of a server with one keeper_path, and ALTER changes one bound, so ALTER TABLE b MODIFY SETTING cleanup_interval_min_ms = 101 (valid for b) with another table at 100/100 still divided by zero AGREE, fixed in this PR generateRescheduleInterval returns the minimum for inverted bounds; test arm with two tables on one path, which kills the server without the guard. Not by validating against the other table's bound: that would reject a value CREATE of b accepts
3 💡 The draft text said any minimum above the maximum divides by zero; only max + 1 gives % 0 AGREE, fixed wording
4 💡 Commit message: same imprecision, -1 attributed to the UInt32 row, one unwrapped line AGREE, fixed commit message

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

Session id: cron:clickhouse-review-slot-9:20260929-223200

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. 05293_s3queue_alter_setting_values fails on every master run (first ALTER gives BAD_GET). By hand on master and on 26.9.6.6: a quoted number gives BAD_GET; after_processing = 'delete', polling_min_timeout_ms = '10000' leaves Keeper at delete and the next ATTACH fails METADATA_MISMATCH; cleanup_interval_min_ms = 1001 with max 1000 kills the server with SIGFPE about 1 s later.
b Root cause explained? StorageObjectStorageQueue::alter feeds the raw literals to typed safeGet reads, writes Keeper before the read that throws, and never runs loadFromQuery / validateSettings, so invalid values reach the definition, and cleanup_interval_min_ms = cleanup_interval_max_ms + 1 reaches rng() % 0 in generateRescheduleInterval.
c Fix matches root cause? Yes. The new settings are converted and validated once, with the functions ATTACH uses, before the first state change. Tables with one keeper_path share the cleanup bounds, so a valid ALTER of one of them can still invert the pair; generateRescheduleInterval, the only consumer that needs min <= max, returns the minimum for inverted bounds.
d Test intent preserved / new tests added? New .sql test: quoted values accepted and converted; a parse error, two range errors and three validateSettings errors (one is cleanup_interval_min_ms above the maximum) rejected with Keeper, the live settings and the definition unchanged; DETACH/ATTACH round trip; two tables with one keeper_path where an ALTER of one inverts the shared bounds. Five mutants (no typed values, validation after the Keeper write, no validation, no cleanup_interval_min_ms check, no inverted-bounds guard) each fail it; without the guard the server dies with SIGFPE about 0.1 s after that ALTER.
e Both directions demonstrated? Yes. Fix [ OK ] and 50/50 randomized; master [ FAIL ], and a statement-by-statement replay on master shows every checked line differs.
f Fix is general across code paths? The 36 typed reads (alterSettings, the member chain, updateSettings) are all fed from the same list, now typed. RESET SETTING defaults take the same path. AzureQueue shares the function (checked by hand). Both callers of generateRescheduleInterval (table startup and the cleanup reschedule) get the guard.
g Fix generalizes across inputs (params/datatypes/wrappers)? Matrix over UInt64, UInt32, Bool, String and enum settings, Keeper and non-Keeper ones, with quoted, numeric, negative, out-of-range and wrong-type values: valid spellings are applied, invalid ones fail with the CREATE error, and every table re-attaches.
h Backward compatible? (maintainer-approved exception only) No setting or format change. Values rejected now were already fatal at the next ATTACH. A change through an intermediate state that ATTACH rejects (for example after_processing = 'tag' before its key and value) now has to be one statement.
i Invariants and contracts preserved? Whatever ALTER stores loads again on ATTACH, and a rejected statement changes nothing: the check runs before the Keeper write and the streaming-task deactivation. Every replica of a Replicated database runs the same check on the same definition. With inverted shared bounds the cleanup task keeps rescheduling (every min ms); for min <= max the interval is computed as before. test_4.py::test_alter_settings passes.

Session id: cron:clickhouse-impl-slot-6:20260929-193500

@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [03d1b9f]

Summary: ✅


AI Review

Summary

PR #122986 converts and validates S3Queue and AzureQueue setting changes before updating Keeper or runtime state, compares equivalent values and legacy names consistently, and protects cleanup scheduling from inverted shared bounds. Reviewed the current code, regression coverage, and all prior discussion at 03d1b9fc7f09b81bc53a9d3bb965ed4681f32160; no actionable findings remain.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 29, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-s3queue S3Queue/AzureQueue engines (queue-based ingestion from object storage). label Sep 30, 2026
`checkAlterIsPossible` and `alter` compared the raw literals to decide whether a
setting changes, so `buckets = '4'` over a stored `buckets = 4`, or `false` over
`0`, counted as a change. The change-only guards then rejected a statement that
changes nothing: `buckets` with attached materialized views, and any setting
that the table's mode does not allow to change. Both now compare the values as
the setting parses them, in `isSettingValueChanged`.

For a setting that is in the definition, a value that does not parse now fails
with its parse error also when the mode does not allow changing the setting,
instead of `SUPPORT_IS_DISABLED`.

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

clickhouse-gh Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 03d1b9fc7 with master 809ae9786 (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.

Object file sizes

6 object files changed (+19.58 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp.o 1.20 MiB 1.22 MiB +16.23 KiB (+1.32%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

15 translation units recompiled, 84 s compile time in total, 15 of them have a recent master baseline.

Job report

`ObjectStorageQueueSettings::hasBuiltin` accepts `enable_logging_to_s3queue_log`
through `adjustSettingName`, but `applyChanges` and `get` do not, so an `ALTER`
of that setting failed with `UNKNOWN_SETTING` instead of `SUPPORT_IS_DISABLED`,
and a no-op in another spelling was rejected. Add
`ObjectStorageQueueSettings::castValueUtil`, which resolves names as `hasBuiltin`
does, like `MergeTreeSettings::castValueUtil`, and compare the values with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`ALTER TABLE ... MODIFY SETTING` and `RESET SETTING` stripped the `s3queue_`
prefix from setting names, but kept the old name `enable_logging_to_s3queue_log`
apart from `enable_logging_to_queue_log`. A statement that named the setting
differently from the table definition added a second entry instead of replacing
the first: restating the current value was rejected with `SUPPORT_IS_DISABLED`,
and `RESET SETTING` under the other name did nothing.

Both now resolve names as `loadFromQuery` does, through the new
`ObjectStorageQueueSettings::resolveName`. As with the prefix, the next `ALTER`
stores such a setting under its current name.

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

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 5e020b7

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
Upgrade check (amd_release) / Part all_1_1_1 intersects next part all_1_5_1 in PartLoadingTree::add (STID 3562-39cd) logical error while the upgraded server loads a table's parts, so the server goes down; the same signature on 23 other PRs and 0 true-master runs in 30 days #121708 (mine, open)
Upgrade check (amd_release) / Cannot check whether the mutation submitted before the upgrade was finished Connection refused: the server of the row above was already down, not a second defect #121708 (mine, open)
Sync - CH Inc sync (private, not actionable by me)

Mergeable Check and PR are aggregators of the rows above, not separate failures.

Neither row comes from this diff, which touches only ALTER TABLE ... MODIFY SETTING of the queue engines and cannot reach MergeTree part loading.

Session id: cron:our-pr-ci-monitor:20260930-080205

…ter-setting-values

# Conflicts:
#	src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp
The `ALTER` of a setting named in the query also counts as a change when
its value differs from the queue's shared or Keeper value (ClickHouse#129383). That
comparison used the raw literal, so the current value written as a string
(`buckets = '4'`) was a change again: on an `Ordered` queue it was refused
because `s3queue_migrate_old_metadata_to_buckets` is not set, and it
rewrote the Keeper metadata for the other Keeper settings. Compare the
value converted by its setting instead, as for the table definition.

This branch has not been deployed

No deployments
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-s3queue S3Queue/AzureQueue engines (queue-based ingestion from object storage). groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant