Repository navigation
Conversation
|
Workflow [PR], commit [6538d53] Summary: ❌
AI ReviewSummaryThis PR strengthens S3Queue ordered-bucket ownership handling, adds the Findings❌ Blockers
Tests
Final Verdict
|
| return false; | ||
|
|
||
| auto zk_client = ObjectStorageQueueMetadata::getZooKeeper(log, zookeeper_name); | ||
| if (!zk_client->isFeatureEnabled(KeeperFeatureFlag::CHECK_STAT)) |
There was a problem hiding this comment.
Returning here makes the ownership/heartbeat fix a no-op on external ZooKeeper, because CHECK_STAT is a ClickHouse Keeper extension and ZooKeeper-compatible connections do not advertise it. S3Queue still supports external ZooKeeper, and in that mode bucket locks are still persistent nodes cleaned by persistent_processing_node_ttl_seconds with no commit-time ownership check or heartbeat, so the original ownership-loss race remains for any processing that outlives the TTL. Please either add a ZooKeeper-compatible path, disable/reject ordered bucket processing with TTL cleanup when this feature is missing, or clearly scope the fix and add coverage for the unsupported branch.
There was a problem hiding this comment.
The current code still does not preserve ownership on plain ZooKeeper. At src/Storages/ObjectStorageQueue/ObjectStorageQueueOrderedFileMetadata.cpp:822, the fallback heartbeat is a SET with version -1; if TTL cleanup deleted A's lock and processor B already recreated the same buckets/<n>/lock path, A's commit multi overwrites B's lock data with A's processor_info and then succeeds. That lets the stale owner advance the processed pointer after losing the bucket, and its later release can also remove B's lock. The non-CHECK_STAT path needs to fail closed when exact-node ownership cannot be proven, or the mode/configuration should be rejected for external ZooKeeper.
There was a problem hiding this comment.
The current no-CHECK_STAT branch still cannot prove ownership before committing. At current src/Storages/ObjectStorageQueue/ObjectStorageQueueOrderedFileMetadata.cpp:813 it deliberately adds no request, so A can lose the bucket, B can acquire it, and if A prepares the commit before B advances the processed pointer, A still writes the Keeper marker after its insert has already written rows. The version-pinned processed pointer only serializes the marker; it does not prove A still owns the bucket or prevent duplicate insert side effects. For plain ZooKeeper this should fail closed or reject the mode/configuration, unless there is a ZooKeeper-compatible ownership proof before commit.
There was a problem hiding this comment.
The current code still leaves the plain-ZooKeeper branch unsafe. At src/Storages/ObjectStorageQueue/ObjectStorageQueueOrderedFileMetadata.cpp:843-848 the no-CHECK_STAT path deliberately adds no heartbeat or ownership assertion, so the bucket lock's mtime is never refreshed there and any holder that lives past persistent_processing_node_ttl_seconds is still reclaimed even while it is actively committing. StorageObjectStorageQueue::commit still sends the Keeper multi only after the insert has already succeeded (src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp:1070-1138), so the version-pinned processed pointer does not prove the stale owner still held the bucket or prevent duplicate insert side effects once another replica re-acquires it.
|
Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/714 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
…threads-investigation # Conflicts: # src/Common/ErrorCodes.cpp # src/Storages/ObjectStorageQueue/ObjectStorageQueueSettings.cpp
Fixes from the AI review on PR #106718: - Bucket ownership without `CHECK_STAT`: `prepareBucketOwnershipCheckRequests` now always emits the lock-node mtime heartbeat (a plain `SET`, supported by external ZooKeeper) and only adds the atomic `czxid`-match `CHECK` when the Keeper advertises `CHECK_STAT`. The heartbeat keeps the TTL cleanup from removing a lock that is actively committing, and a missing lock fails the commit multi with `ZNONODE` so the file is retried instead of double-committed. Together with the non-atomic `stillOwnsBucket` check on the error path, the ownership-loss race is covered on plain ZooKeeper too; only the `CHECK_STAT` path makes it fully atomic. - `deduplication_v2` alter guard: `checkAlterIsPossible` treated a setting that was missing from the old settings as unchanged, so it skipped the safety guard while `alter` still applied the change. It now treats a missing old setting as changed, matching `alter`, so `ALTER ... MODIFY SETTING deduplication_v2 = 0` on a table that did not set it at creation is rejected without `s3queue_allow_unsafe_alter`. Added `test_alter_deduplication_v2_guard`. - Bucket-lock regression tests: bucket ownership is enabled only when there is more than one bucket, so the tests now use `s3queue_buckets = 2` and discover whichever `buckets/<i>/lock` node is acquired via `_wait_for_any_bucket_lock` instead of waiting on a hard-coded `buckets/0/lock` that could never appear. #106718 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Capture when a bucket lock is acquired and include how long it had been held in the OBJECT_STORAGE_QUEUE_BUCKET_OWNERSHIP_LOST message, so it is clear whether the hold exceeded persistent_processing_node_ttl_seconds. Co-Authored-By: Claude Opus 4.8 <[email protected]>
| { | ||
| LOG_TEST(log_, "Processor {} acquired bucket {} for processing", processor_info, bucket); | ||
|
|
||
| /// Capture the lock node's `czxid` for the commit-time ownership check (see `lock_czxid`). |
There was a problem hiding this comment.
Capturing lock_czxid only protects the commit path; the holder release path can still delete a lock recreated by another processor. If this holder loses the bucket to TTL cleanup, BucketHolder::release reaches the first-attempt tryRemove(bucket_lock_path, -1) with only a chassert ownership check, so release builds remove the new owner's lock. That reintroduces the same ownership-loss loop even when CHECK_STAT made the stale commit fail. Release needs to use the captured czxid as well, e.g. remove only under an atomic stat check when supported, and otherwise fail closed by leaving the old lock for TTL cleanup instead of deleting a lock whose identity is not proven.
There was a problem hiding this comment.
The release path still has a check-then-remove race. In the current code, checkBucketOwnership only reads the lock data, then tryRemove removes the path without tying the remove to the node identity. Interleaving: A reads A's data, TTL cleanup deletes A's lock, B creates the same bucket_lock_path, and A's tryRemove removes B's lock. That is the stale-holder deletion this thread was about. Release needs to remove under the same czxid identity check, or fail closed and leave the lock for TTL cleanup when that cannot be expressed.
There was a problem hiding this comment.
The original race is still present in the current code. BucketHolder::release still does a separate ownership read and then an unguarded remove at src/Storages/ObjectStorageQueue/ObjectStorageQueueOrderedFileMetadata.cpp:276-286: if A reads its own processor_info, the TTL cleanup deletes that lock, B creates the same bucket_lock_path, and then A's tryRemove deletes B's fresh lock. The remove still needs to be tied to the node identity (czxid) or skipped entirely when exact ownership cannot be proven.
- Fail closed without Keeper CheckStat: only heartbeat the bucket lock inside the atomic ownership check, so a blind Set can no longer steal a lock that was cleaned up and re-acquired by another processor. - Guard BucketHolder::release in all build types so it removes the lock only while still owned, instead of deleting the new owner's lock. - Require s3queue_allow_unsafe_alter for RESET SETTING deduplication_v2, which previously bypassed the guard via re-derived defaults. - Handle in-flight bucket ownership loss gracefully (release and re-acquire) instead of asserting, and drop the racy acquire-time ownership assertion. - Add a RESET deduplication_v2 guard regression test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
| ): | ||
| expected = set(tuple(v) for v in total_values) | ||
|
|
||
| def union_distinct(): |
There was a problem hiding this comment.
This helper collapses the destination rows to a set, so the new regression tests pass even if the ownership race duplicates rows. That is one of the unsafe outcomes of two replicas processing the same file after a bucket lock handoff. Please assert multiplicity as well, for example compare the total row count across both destination tables to len(total_values) and check GROUP BY column1, column2, column3 HAVING count != 1 returns no rows before declaring recovery.
|
Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/714 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
The TTL cleanup may remove a persistent processing node (a per-file processing node or a bucket lock) while it is still held, when a long batch does not commit (and therefore does not heartbeat) before `persistent_processing_node_ttl_seconds` elapses, after which another processor may re-acquire it. This is an expected, recoverable condition handled on the commit path, but several node-removal paths still asserted that a held node is always owned via `chassert(checkProcessingOwnership)` / `chassert(checkBucketOwnership)`, which aborts the server in debug/sanitizer builds the moment the cleanup reclaims a live node. Make the ownership check unconditional on these paths: skip removal if the node is no longer ours instead of asserting. Covered paths: - `ObjectStorageQueueIFileMetadata::~ObjectStorageQueueIFileMetadata` and `resetProcessing` (per-file processing node); - `ObjectStorageQueueOrderedFileMetadata::BucketHolder::release` (bucket lock); - the debug ownership re-check in `ObjectStorageQueueSource::FileIterator::getNextKeyFromAcquiredBucket` is downgraded from an assertion to a log line. Tests: `test_ordered_bucket_lock_deleted_during_commit` and `test_ordered_bucket_lock_cleaned_by_ttl` now use a slower materialized view so a single bucket's batch stays uncommitted past the TTL even when files are split across more than one bucket; `test_alter_deduplication_v2_guard` expects the Bool `deduplication_v2` to render as `true`/`false`. #106718 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…tigation' into s3queue-processing-threads-investigation # Conflicts: # src/Storages/ObjectStorageQueue/ObjectStorageQueueOrderedFileMetadata.cpp # src/Storages/ObjectStorageQueue/ObjectStorageQueueSource.cpp
- Assert the absence of permanently-failed files via the authoritative Keeper state (`<keeper_path>/failed`, excluding transient `.retriable` markers) instead of the per-replica in-memory `system.s3queue_metadata_cache`. Under the deliberate lock takeover (and the cluster's Keeper fault injection) a replica's racing local processing attempt could leave a transient `Failed` in its own in-memory cache even though the file was ultimately processed, which made `test_ordered_bucket_lock_deleted_during_commit` flaky. Keeper is the shared source of truth, so it is checked once. - Fix stale literals in `test_reset_deduplication_v2_guard`: the Bool `deduplication_v2` renders as `true`/`false` in `system.s3_queue_settings`, not `1`/`0`. #106718 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
| code = Coordination::Error::ZOK; | ||
| return; | ||
| } | ||
| code = zk_client->tryRemove(processing_node_path); |
There was a problem hiding this comment.
The ownership check is still a separate read from the remove, so this can delete a processing node recreated by another processor. A concrete interleaving is: this holder reads its own processor_info, the TTL cleanup removes processing_node_path, another processor creates the same path for the same file, then this tryRemove removes the new owner's node. That lets a third processor acquire the file while the second one is still inserting, which is the duplicate-processing class this PR is trying to close. The remove needs to be tied to the node identity/version observed during the ownership check, or fail closed and leave the node for TTL cleanup when exact ownership cannot be proven.
There was a problem hiding this comment.
The same check-then-remove race is still present for per-file processing nodes. Both the destructor path at src/Storages/ObjectStorageQueue/ObjectStorageQueueIFileMetadata.cpp:183-199 and resetProcessing at src/Storages/ObjectStorageQueue/ObjectStorageQueueIFileMetadata.cpp:399-411 first read ownership and then remove in a separate request. If the stale node is cleaned up and recreated between those two steps, the current code still deletes another processor's fresh processing node.
After `tryCreate` of a bucket lock succeeds in `tryAcquireBucket`, read the node back with `tryGet` and verify it still holds our `processor_info` instead of only checking existence. Capture `czxid` when ownership is confirmed, otherwise flag ownership as lost and return `nullptr` so the caller skips the bucket. Move `OBJECT_STORAGE_QUEUE_BUCKET_OWNERSHIP_LOST` to `M(779)` after `MEMORY_RESERVATION_FAILED` and revert `END` to `1008`. CI report: #106718 (comment) Related: #106718 Co-Authored-By: Claude Opus 4.8 <[email protected]>
… removals Track the believed heartbeat time of the bucket lock in `BucketInfo`: initialized to the acquisition time and promoted (CAS-max) via the new `finalizeProcessedImpl` hook once a commit containing the czxid-guarded heartbeat `Set` succeeds. The timestamp is recorded before the commit is sent, so it is a conservative lower bound on the lock node's `mtime`. In `getNextKeyFromAcquiredBucket`, when the debug-only ownership check finds the lock lost, `chassert` that the believed heartbeat age reached the TTL: the cleanup may only reclaim a lock whose `mtime` aged past the TTL, so losing a younger lock indicates a bug (cleanup removing fresh nodes, a broken heartbeat refresh, or an external deletion). Legitimate reclaims still drop the holder and re-acquire gracefully. The TTL cleanup now logs the removed node's `mtime` age and the TTL for attribution of lock removals. Run `test_ordered_bucket_lock_deleted_during_commit` and `test_ordered_bucket_lock_cleaned_by_ttl` in release builds only: they force removal of a live bucket lock, which intentionally trips the `chassert` ownership validations in debug/sanitizer builds. Match the cleanup log line by the table-specific Keeper path. Related: #106718 Co-Authored-By: Claude Opus 4.8 <[email protected]>
…threads-investigation
Fixes from an in-depth review of the believed-heartbeat mechanism: - Construct `BucketInfo` in place: the atomic `last_heartbeat_time` member makes it non-copyable, so `make_shared` with a temporary did not compile. - Record `lock_acquired_time` before the create is sent: the node's `mtime` is set when `tryCreate` lands, which can be an earlier retry than the one that reports success, so the previous post-read-back timestamp was not a lower bound on the `mtime`. - Add clock-skew slack to the ownership-loss `chassert`: the asserted chain crosses the committing replica's clock, Keeper's `mtime` and the cleaning replica's clock. - Pin the TTL cleanup removal to the scanned node's `czxid` (via `CheckStat` + `Remove` multi) when Keeper supports it: the data `version` alone cannot detect a node removed and recreated after the scan, so the cleanup could delete another processor's fresh lock. - Reset the cached bucket processor when dropping a stale holder, so the bucket's cached keys are not skipped until the next commit. - Reset `pending_bucket_heartbeat_time` at prepare time to be robust against reuse after a failed commit attempt. - Report `lock_acquired_time` and `last_heartbeat_time` in `BucketInfo::toString`. - Reword the `persistent_processing_node_ttl_seconds` description: live processors that do not commit for longer than the TTL can still have their nodes reclaimed; per-file processing nodes are never refreshed. - Fix a stale comment: a failed commit-time `CheckStat` surfaces as a generic Keeper multi error, not `OBJECT_STORAGE_QUEUE_BUCKET_OWNERSHIP_LOST`. Related: #106718 Co-Authored-By: Claude Opus 4.8 <[email protected]>
| } | ||
| else | ||
| { | ||
| code = zk_client->tryRemove(node, version); |
There was a problem hiding this comment.
On plain ZooKeeper this cleanup path can still delete a fresh processing node or bucket lock that was recreated after the scan. The fallback branch only does tryRemove(node, version), but a recreated znode starts back at version 0, so version alone does not distinguish "the stale node we scanned" from "a new owner that recreated the same path before removal". That means the cleanup thread can still remove another processor's active node whenever CHECK_STAT is unavailable. This needs to fail closed on the no-CHECK_STAT path, or ordered / persistent-processing cleanup needs to be rejected on external ZooKeeper.
|
📊 Cloud Performance Report ✅ AI verdict: This PR is scoped entirely to ObjectStorageQueue/S3Queue bucket-lock ownership, TTL-cleanup safety, and new ALTER guards (the s3queue_allow_unsafe_alter opt-in); it does not touch the query-execution path any ClickBench or TPC-H query exercises. Every flagged clickbench delta was measured against a single-run baseline that reads high, and none can be attributed to the diff, so all five improvements are downgraded to not_sure as baseline variance. Q32's -5.4% is borderline with mixed test signals and is likewise unrelated. No genuine regression or improvement is supported by this change. clickbenchFlagged queries (6 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
|
Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/714 Labels added:
These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 211/270 (78.15%) · Uncovered code |
|
A more simpler fix was merged #110292 |
Fixes from the AI review on PR ClickHouse#106718: - Bucket ownership without `CHECK_STAT`: `prepareBucketOwnershipCheckRequests` now always emits the lock-node mtime heartbeat (a plain `SET`, supported by external ZooKeeper) and only adds the atomic `czxid`-match `CHECK` when the Keeper advertises `CHECK_STAT`. The heartbeat keeps the TTL cleanup from removing a lock that is actively committing, and a missing lock fails the commit multi with `ZNONODE` so the file is retried instead of double-committed. Together with the non-atomic `stillOwnsBucket` check on the error path, the ownership-loss race is covered on plain ZooKeeper too; only the `CHECK_STAT` path makes it fully atomic. - `deduplication_v2` alter guard: `checkAlterIsPossible` treated a setting that was missing from the old settings as unchanged, so it skipped the safety guard while `alter` still applied the change. It now treats a missing old setting as changed, matching `alter`, so `ALTER ... MODIFY SETTING deduplication_v2 = 0` on a table that did not set it at creation is rejected without `s3queue_allow_unsafe_alter`. Added `test_alter_deduplication_v2_guard`. - Bucket-lock regression tests: bucket ownership is enabled only when there is more than one bucket, so the tests now use `s3queue_buckets = 2` and discover whichever `buckets/<i>/lock` node is acquired via `_wait_for_any_bucket_lock` instead of waiting on a hard-coded `buckets/0/lock` that could never appear. ClickHouse#106718 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Linked issues
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
S3Queue: fix "file is already processed" error in ordered bucket mode