Skip to content

Refuse to migrate an Ordered S3Queue that already uses buckets - #130733

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:s3queue-refuse-buckets-migration-when-bucketed
Nov 12, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:s3queue-refuse-buckets-migration-when-bucketed

Conversation

@groeneai

@groeneai groeneai commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

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 buckets with s3queue_migrate_old_metadata_to_buckets = 1 on an Ordered S3Queue or AzureQueue table created without buckets. Such a table already spreads its files over processing_threads_num buckets, so the migration rewrote a layout it does not handle, and files that were already processed could be ingested again. The ALTER is now rejected with SUPPORT_IS_DISABLED.

Description

Found by the AST fuzzer (Logical error: 'Buckets: 16', STID 2508-48a2): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128397&sha=c73851844138eede9c5cea8e9fc60ecf3e7ee388&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29

On 26.10.2.103 (the same code is in 26.8 and 26.3), ALTER TABLE q MODIFY SETTING buckets = 2 is accepted on an Ordered queue created without buckets, and after a server restart files it had already processed are ingested again (measured: all 64 processed files, 128 rows instead of 64).

When buckets is unset, the effective bucket count is processing_threads_num, which defaults to at least 16, and the queue's Keeper layout already has that many buckets/N nodes. The buckets branch of ObjectStorageQueueMetadata::alterSettings checked only the raw buckets value, so it called migrateToBucketsInKeeper, whose chassert(buckets_num == 1) aborts a debug build. A release build switches the queue to 2 buckets while each new bucket keeps only the processed pointer of old bucket 0 or 1. The guard now checks the effective count, which is the precondition the migration asserts. AzureQueue shares this code.

Behaviour change: this ALTER is refused on any Ordered queue whose effective bucket count is above 1, including buckets = <current count>, and on queues created before 24.6 with s3queue_processing_threads_num above 1 (made backward incompatible by #64349). The setting is documented as migration-only.

Not changed here: a queue created with buckets = 1 gets no bucket nodes from this migration, which is a separate path in migrateToBuckets.

Validation: 05339_s3queue_ordered_migrate_to_buckets gets a third case. It fails on master (the debug server aborts) and passes with the fix, 50/50 with randomized settings and 10/10 in the Database Replicated shape.


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

Version info

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

`ALTER TABLE ... MODIFY SETTING buckets` with `s3queue_migrate_old_metadata_to_buckets = 1`
moves the single `processed` node of an old Ordered queue into `buckets/N/processed`. The
guard in `ObjectStorageQueueMetadata::alterSettings` refused the migration only when the raw
`buckets` setting was above 1. With `buckets` unset the effective bucket count is
`processing_threads_num`, which defaults to `max(cores, 16)`, so a default Ordered queue
already has that many `buckets/N` nodes and still passed the guard.

`migrateToBucketsInKeeper` then failed its `chassert(buckets_num == 1)` in debug builds
(`Logical error: 'Buckets: 16'`, found by the AST fuzzer on an `AzureQueue` clone of
05339). A release build has no assertion: it switched the queue to the new bucket count
while each new bucket kept only the processed pointer of old bucket 0 or 1, and after a
restart the already processed files were ingested again (measured on 26.10.2.103: 64
files, 128 rows).

Check the effective count `buckets_num`, which is the precondition the migration asserts.
The refusal happens before any Keeper write. 05339 gets a case for a queue created
without `buckets` and `processing_threads_num`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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; 0 findings) plus my own review (2 nits).

# Sev Finding Verdict Evidence / action
1 💡 The header of 05339_s3queue_ordered_migrate_to_buckets.sql says processing_threads_num = 1 is pinned everywhere; the new third case leaves it unset on purpose AGREE, noted, not blocking the test diff stays additions only
2 💡 A queue created with buckets = 1 passes the guard, and migrateToBuckets then reads buckets/0/processed, which such a queue never writes out of scope: separate PR different code (ObjectStorageQueueOrderedFileMetadata.cpp, source path choice), unchanged here, stated in the description

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

Session id: cron:clickhouse-review-slot-8:20261111-094400

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Ordered S3Queue without buckets/processing_threads_num, SET s3queue_migrate_old_metadata_to_buckets = 1, ALTER TABLE q MODIFY SETTING buckets = 2: the master debug server aborts with Logical error: 'Buckets: <processing threads>' every time.
b Root cause explained? alterSettings refused only a raw buckets > 1, while the effective count buckets_num falls back to processing_threads_num (default at least 16), so the migration ran on a queue that already uses buckets and broke migrateToBucketsInKeeper's buckets_num == 1 precondition.
c Fix matches root cause? Yes. The guard checks buckets_num > 1, the precondition the migration asserts, and throws before any Keeper write.
d Test intent preserved / new tests added? 05339_s3queue_ordered_migrate_to_buckets gets a third case (additions only): the ALTER is refused, the definition keeps no buckets, and at least 16 bucket nodes prove the queue really uses buckets.
e Both directions demonstrated? Master debug: the test kills the server at the new case. Fix: OK. A mutant that reverts only the condition: fails the same way. 50/50 randomized runs and 10/10 Database Replicated runs OK.
f Fix is general across code paths? One implementation for S3Queue and AzureQueue (the fuzzer hit AzureQueue). Unordered/Exclusive are refused earlier. RESET SETTING buckets with buckets unset stays a no-op. Every host derives the count from the same Keeper metadata.
g Fix generalizes across inputs (params/datatypes/wrappers)? Default threads, explicit processing_threads_num > 1, explicit buckets > 1 (the existing buckets = 4 refusal still fires), single-bucket sources (still migrate, cases 1 and 2), target equal to the current count (now refused). Type wrappers: N/A.
h Backward compatible? (maintainer-approved exception only) No format or setting change. The only new refusal is where the migration's own precondition already fails. Tables created before 24.6 with several processing threads cannot use this ALTER (unsupported since #64349).
i Invariants and contracts preserved? "The migration runs only while buckets_num == 1" now holds on every path. On refusal Keeper and the table definition are unchanged (measured).

Session id: cron:clickhouse-impl-slot-5:20261111-090300

@clickhouse-gh

clickhouse-gh Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a8cde0d]

Summary: ✅


AI Review

Summary

PR #130733, head a8cde0dfa3a440a4fba7f8f1a49165cafdb0f9b9, rejects bucket migration on ordered S3Queue and AzureQueue tables whose effective bucket count already exceeds one. This prevents an unsupported migration from losing processed-file progress. The focused regression case exercises an unset buckets setting with the default processing-thread count. No actionable findings.

Missing context / blind spots
  • ⚠️ Tests were not run locally; no ClickHouse build is available in this checkout. Current-head functional CI has no result yet. Runtime evidence comes from the author's reported before/after regression runs, including randomized settings and a replicated database.
Final Verdict

Status: ✅ Approve.

@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-s3queue S3Queue/AzureQueue engines (queue-based ingestion from object storage). labels Nov 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a8cde0dfa with master 039d5de47 (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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.56, programs/clickhouse-keeper ×0.62 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 6.3 s 9.4 s +5.9 s (+166%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.5 s 7.1 s +5.1 s (+257%)
Compile time of recompiled translation units

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

Job report

@alexey-milovidov alexey-milovidov self-assigned this Nov 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 12, 2026
lazerg pushed a commit to lazerg/ClickHouse that referenced this pull request Nov 12, 2026
…t one bucket

The readers of the Ordered Keeper layout treat a queue with at most one
bucket as the layout without buckets (last processed file in
`<keeper_path>/processed`) and a queue with more buckets as one
`buckets/<i>/processed` per bucket (`useBucketsForProcessing`).
`ObjectStorageQueueOrderedFileMetadata::migrateToBuckets`, run by
`ALTER TABLE ... MODIFY SETTING buckets` under
`s3queue_migrate_old_metadata_to_buckets = 1`, disagreed with that:

- for a source created with `buckets = 1` it read the pointer from
  `buckets/0/processed`, which such a queue never writes;
- when it found no pointer it returned before creating the `buckets/<i>`
  nodes, while `migrateToBucketsInKeeper` still switched the queue to the
  new count. The readers then look for nodes that do not exist: a debug
  build aborts on `chassert(bucket_exists)` in `tryAcquireBucket`, a release
  build loops on `Failed to set file processing, error: No node` and never
  ingests another file (measured on 26.10.2.103);
- it migrated to the raw `buckets` value: a target of 1 moved the pointer
  to `buckets/0/processed` and removed `<keeper_path>/processed`, so after a
  restart the queue ingests every processed file again (measured on
  26.10.2.103: 32 rows for 16 files); a target of 0 created no bucket
  although the queue then uses `processing_threads_num` buckets.

Now `migrateToBucketsInKeeper` passes the new effective bucket count
(`getBucketsNum` of the new metadata), and `migrateToBuckets` does nothing
when that count is at most 1, creates the bucket nodes before looking for
the pointer, and looks for it first in `buckets/0/processed` (where older
versions put it after a migration to one bucket, and where the initiator
replica has just put it) and then in `<keeper_path>/processed`. The
"migrated concurrently by another replica" return is keyed on the source
being bucket 0's node, which is what `prev_value != 0` meant before.

A `buckets = 1` source whose `processed` node has children (partitioned
layout) is now refused with `SUPPORT_IS_DISABLED`, as an unset source
already was, instead of being switched to a layout without a pointer.

The new test is a new file rather than a 05339 extension, because ClickHouse#130733
extends 05339.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged via the queue into ClickHouse:master with commit b20d013 Nov 12, 2026
368 of 370 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 12, 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-s3queue S3Queue/AzureQueue engines (queue-based ingestion from object storage). 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.

3 participants