Repository navigation
Fix the S3Queue migration to buckets for an Ordered queue with at most one bucket - #130798
alexey-milovidov merged 5 commits into
Conversation
…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]>
A `buckets = 1` Ordered queue keeps its last processed file in `<keeper_path>/processed`, but older versions migrated `buckets = 1` into `buckets/0/processed` and the queue then kept writing the root node again. Such a queue can therefore carry two pointers, and the root one is the newer one as soon as a file arrived after that migration. Taking the first pointer found copied the stale bucket-0 one into every bucket and ingested the files between the two pointers again. Every file up to the greatest pointer is processed, so the migration now takes the greatest `file_path` of all pointers it finds and removes all of them in the same multi. `buckets/0/processed` is such a legacy whole-queue pointer only while the bucketed layout does not exist yet. After this change a server that migrates an empty queue creates `buckets/<i>` and can then process bucket-0 files, so another server running the same `ALTER` later would find a live bucket-0 pointer; copying it into bucket 1 would skip that bucket's files. `<keeper_path>/buckets/1` exists exactly when some server already created the bucketed layout, so bucket 0 is a candidate only if it did not exist before the migration started. It is checked once, before the retry loop: a retry after a Keeper session loss must not see our own `buckets/1` and drop a legacy source. If removing a pointer fails with ZNONODE, another server migrated it in the meantime, so the lookup is repeated (the previous check of the first response made that branch unreachable); any other failure of a remove is reported as a concurrent modification, and an existing bucket pointer means the migration was already done. The test gets cases for a bucket-0 pointer of an older version, for both pointers with either one greater, and for a live bucket-0 pointer of another server. Those nodes are written with `INSERT INTO system.zookeeper`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`migrateToBuckets` used to create `buckets/<i>` with `createAncestors` before looking for the pointer. `createAncestors` is its own Keeper transaction, so those nodes were committed even when the migration multi then failed: a source remove rejected as a concurrent modification, a partitioned source whose `processed` node has children, or a Keeper error that `StorageObjectStorageQueue::alter` retries around `alterSettings`. The next attempt found `buckets/1`, which is how the migration tells "another server already migrated" from "bucket 0 still holds the pointer older versions put there for `buckets = 1`", so it dropped the legacy bucket-0 candidate, failed with ZNODEEXISTS on `buckets/0/processed` and returned as if migrated: the root pointer orphaned, bucket 0 stale and bucket 1 without a pointer, so every bucket-1 file was ingested again. The missing bucket nodes are now part of the same multi as the migrated pointers (with nothing to migrate nothing can be lost, so they are created directly). `buckets/1` therefore exists only after a committed migration, and the discriminator is re-derived on every iteration from the same `exists()` pass that decides which bucket nodes the multi creates: a snapshot taken once could be made stale by another server that migrates an empty queue and then processes a bucket-0 file, whose live pointer would be copied into bucket 1. When bucket 0 is used as the legacy source the multi contains `create buckets/1`, so a concurrent creator makes it fail with ZNODEEXISTS on a bucket node, which now means "re-check" instead of "already migrated". Test case 8 refuses a `buckets = 1` source whose `processed` node has a child (the shape of a partitioned queue's pointers) and checks that the refusal created no `buckets/1`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop a sentence that narrated the remove requests built right below it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (rounds 1-3): 6 fixed, 2 declined
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261111-123600 |
|
Workflow [PR], commit [5eee039] Summary: ✅
AI ReviewSummaryReviewed #130798 at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No further code changes requested; latest-head CI validation remains pending. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (+39.52 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units8 translation units recompiled, 26 s compile time in total, 8 of them have a recent master baseline. |
… buckets `buckets/1` is not a completion marker: older versions of `migrateToBuckets` created the bucket nodes outside the migration transaction, so a server stopping between the two leaves `buckets/1` while bucket 0 still holds the pointer of the whole one-bucket queue. Retrying the migration then skipped that pointer and switched the queue to two buckets with nothing in bucket 1, so every file of bucket 1 was ingested again. The `buckets` value in `<keeper_path>/metadata` is written only after a migration, so it is the committed state: while it has at most one bucket, bucket 0 of a `buckets = 1` queue is the queue's legacy pointer; once it has more, bucket 0 belongs to bucket 0 only. The metadata version is checked in the migration transaction, so a concurrent migration makes it recheck. Test case 7 now covers both: `buckets/1` left by an interrupted migration, and a migration committed by another server. Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov
left a comment
There was a problem hiding this comment.
Not entirely trivial, but ok.
…ne_bucket in a Memory database
Stress test (amd_msan) failed with "Cannot start clickhouse-server": the
restart could not load q_peer, "Existing table metadata in ZooKeeper
differs in buckets setting. Stored in ZooKeeper: 2, local: 1
(METADATA_MISMATCH)".
The test rewrites the Keeper metadata of q_peer to "buckets":2 to simulate
a migration by another server, then runs ALTER TABLE q_peer MODIFY SETTING
buckets = 2. In between, Keeper has 2 buckets and the table's .sql has 1,
which ATTACH refuses. The stress run's global time limit killed the client
right after the rewrite, stress.py detached (not dropped) the database,
and the restart with async_load_databases = false failed on the table.
Only q_peer has such a state: run up to every statement boundary of the
test, then detached and restarted, every other table loads. So only q_peer
moves into a Memory database, {CLICKHOUSE_DATABASE_1:Identifier}, whose
table metadata a restart never loads, as 05234 does (ClickHouse#122101). USE makes
currentDatabase() and the {database} macro of keeper_path name that
database, so the queries and the reference are unchanged; the other cases
keep running in the test database, including its Replicated variant.
DROP DATABASE is the cleanup because ignore_drop_queries_probability never
ignores it.
Related: ClickHouse#130798
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
ALTER TABLE ... MODIFY SETTING bucketswiths3queue_migrate_old_metadata_to_buckets = 1on an OrderedS3QueueorAzureQueuetable with at most one bucket (buckets = 1, orbucketsunset withprocessing_threads_num = 1). Migrating such a table to more buckets made it stop ingesting new files, and migrating it to one bucket made it ingest its already processed files again after a restart.Description
Related: #130733.
On 26.10.2.103, after
SET s3queue_migrate_old_metadata_to_buckets = 1; ALTER TABLE q MODIFY SETTING buckets = 2on an Ordered queue created withbuckets = 1, the queue never ingests another file (Failed to set file processing, error: No node. (LOGICAL_ERROR)). Withbucketsunset andprocessing_threads_num = 1,ALTER ... buckets = 1makes the queue ingest all processed files again after a restart (measured: 33 rows for 17 files).The readers treat at most one bucket as the layout without buckets (
<keeper_path>/processed), and more as onebuckets/<i>/processedper bucket.ObjectStorageQueueOrderedFileMetadata::migrateToBucketsdisagreed: for abuckets = 1source it readbuckets/0/processed; without a pointer it returned before creating thebuckets/<i>nodes, yet the queue switched to the new count; and it migrated to the raw setting, so a target of 1 moved the pointer where a one-bucket queue does not read it, and a target of 0 created no buckets.The migration now targets the new effective bucket count:
buckets = 0migrates toprocessing_threads_numbuckets, and a migration to one bucket no longer touches Keeper (behaviour change). It migrates the greater of the pointers in<keeper_path>/processedand, while the table metadata in Keeper still has at most one bucket, inbuckets/0/processed, where older versions put it on a migration to one bucket. The bucket nodes are created in the same Keeper transaction, so a refused migration leaves nothing behind. Migrating a partitionedbuckets = 1queue is now refused, as withbucketsunset; before, it was accepted and the pointers were left unread.Validation: 7 of the 8 cases of the new test
05620_s3queue_ordered_migrate_from_one_bucketfail on master and all pass with the fix. End to end with MinIO the queue keeps ingesting without duplicates, also right after 26.10.2.103 migrated it to one bucket.Workflow [PR]
Sync PR [sync-upstream/pr/130798]
Version info
26.11.1.2025-master(included in26.11and later)