Repository navigation
Refresh S3Queue bucket locks so the TTL cleanup does not remove them mid-processing - #110292
Conversation
…oViews by it Change the default of `persistent_processing_node_ttl_seconds` from 6 hours to 24 hours. Log elapsed time of the whole `streamToViews` execution and stop starting new iterations once elapsed time reaches half of the TTL, so that the execution finishes before processing nodes and the bucket lock could be cleaned up as abandoned. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [ff76e2c] Summary: ❌
AI ReviewSummaryThis PR adds bucket-lock refreshes and lost-ownership detection for Findings❌ Blockers
Final VerdictChanges requested: the current implementation still leaves live-ownership expiry holes on supported ordered-mode paths, and the live-setting behavior around |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
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. |
When streamToViews breaks out of the loop because elapsed time reached half of persistent_processing_node_ttl_seconds, drop the shared file iterator instead of keeping it cached. releaseFinishedBuckets keeps the last non-finished bucket holder, so a cached iterator would keep holding the bucket lock with a stale mtime - the exact situation the early stop is meant to avoid. Dropping the iterator releases all held buckets (via BucketHolder destructors) once the last streaming task stops using it, and the next execution re-acquires bucket locks with a fresh iterator. Co-Authored-By: Claude Fable 5 <[email protected]>
…user Add a force_release_unfinished flag to releaseFinishedBuckets which allows to release also the last non-finished bucket holder. When streamToViews stops on reaching half of persistent_processing_node_ttl_seconds and no other streaming task uses the shared file iterator (checked via use_count under streaming_mutex, which prevents new copies), release all buckets explicitly and keep the iterator cached, so the next execution reuses its listing state and re-acquires buckets with fresh lock nodes. If other streaming tasks still use the iterator (parallel_inserts), force release is not safe - they can have in-flight files from the non-finished bucket - so keep dropping the shared iterator and let the buckets be released when the last task stops using it. Co-Authored-By: Claude Fable 5 <[email protected]>
The previous stop condition measured each streamToViews execution separately, but bucket locks are held by the shared file iterator, which outlives a single execution: with parallel_inserts, a task which adopted the iterator just before another task dropped it could keep streaming for another half TTL on its own clock, so in the worst case the bucket lock hold time approached the full persistent_processing_node_ttl_seconds and cleanup could remove a lock still in use. Base the stop condition on the iterator age instead (no bucket lock can be held longer than the iterator which acquired it), so all streaming tasks sharing the iterator stop within their current iteration once the age reaches half of the TTL. The task which stops last (use_count == 1 after the shared pointer is dropped, when no new user can appear) force releases all buckets explicitly; BucketHolder destructors remain as a backstop in case of a race between the last two users. Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
Replace the file iterator age clock with the age of the oldest currently held bucket lock (a stopwatch on BucketHolder started at acquisition), which is the resource the TTL cleanup actually applies to. With no locks held (e.g. unordered mode) the check never fires, so the iterator is not pointlessly dropped and re-listed every half TTL, and a lock acquired late in the iterator lifetime gets its full half-TTL of work. Since releasing the locks resets this clock, the sole-user case no longer needs to stop streaming at all: release the buckets under streaming_mutex (so no other task can adopt the iterator mid-release) and continue with the same iterator, re-acquiring locks as needed. With concurrent streaming tasks the behavior is as before: drop the shared iterator, all tasks stop on the shared clock, the last one releases the buckets. Co-Authored-By: Claude Fable 5 <[email protected]>
Instead of stopping streaming and releasing bucket locks before persistent_processing_node_ttl_seconds passes, keep the locks alive from inside the file iterator: BucketHolder::refresh rewrites the lock node data with a version-guarded set, updating its mtime, and the iterator refreshes every held lock older than half of the TTL on each iterator step. The TTL cleanup already removes nodes with a version check, so a refreshed lock cannot be removed by a cleanup which read a stale stat, and the TTL now only reaps locks of genuinely dead servers - its original purpose. This removes the whole stop/release machinery from streamToViews: the iterator drop, the use_count checks and the force_release_unfinished flag of releaseFinishedBuckets. Streaming is never interrupted, and lock refresh works during long iterations too, since it happens on every iterator step rather than between them. Co-Authored-By: Claude Fable 5 <[email protected]>
If the lock node is gone or owned by another server when refreshing, throw LOGICAL_ERROR instead of logging a warning, failing the current streaming execution. The holder is marked released first, so that release() and the destructor do not remove someone else's lock node. Co-Authored-By: Claude Fable 5 <[email protected]>
e6776c8 to
222d4e3
Compare
Scanning bucket holders on every iterator step is too often. Scan them at most once per quarter of persistent_processing_node_ttl_seconds, so each lock is still refreshed before 3/4 of the TTL passes. Co-Authored-By: Claude Fable 5 <[email protected]>
| files_path = f"{table_name}_data" | ||
| files_to_generate = 300 | ||
|
|
||
| # With TTL = 2 sec a bucket lock must be refreshed once it was not |
There was a problem hiding this comment.
This still only exercises the "many short files" case, where the iterator reaches next() often enough to call refreshExpiringBucketLocks(). The remaining failure mode is one slow reader->pull() or a long commit spanning persistent_processing_node_ttl_seconds: in that path the refresh hook is never reached, and the per-file processing node is not refreshed at all. Please add a focused repro for one active file held past the TTL, ideally with a second node trying to acquire the same bucket, so the test matches the contract this PR is trying to enforce.
A commit can take a long time (Keeper retries with backoff), during which no thread calls `next` on the file iterator, so bucket locks could age past the TTL and be removed as abandoned by the cleanup. Refresh the locks right after each commit in `streamToViews`, so that the locks which survive into the next batch enter it with most of the TTL budget left. Also consolidate the refresh into a single `refreshExpiringBucketLocks` method with a single threshold (a quarter of the TTL) and drop the scan throttle: the scan itself is an in-memory walk over a handful of holders, and Keeper is only touched for locks that actually aged. Co-Authored-By: Claude Fable 5 <[email protected]>
persistent_processing_node_ttl_seconds is changeable at runtime, while the cleanup task gating flag is fixed at metadata creation. Altering the TTL to zero on a table with the cleanup running made it treat every processing node and bucket lock as stale and remove live ownership state immediately. The opposite direction stays a known pre-existing limitation: the cleanup task is only created at startup, so a table created with a zero TTL does not start it when the TTL is enabled later. Addresses: #110292 (comment) Co-Authored-By: Claude Fable 5 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 93/156 (59.62%) · Uncovered code |
Cherry pick #110292 to 26.3: Refresh S3Queue bucket locks so the TTL cleanup does not remove them mid-processing
…anup does not remove them mid-processing
Cherry pick #110292 to 26.5: Refresh S3Queue bucket locks so the TTL cleanup does not remove them mid-processing
…anup does not remove them mid-processing
Backport #110292 to 26.7: Refresh S3Queue bucket locks so the TTL cleanup does not remove them mid-processing
Backport #110292 to 26.5: Refresh S3Queue bucket locks so the TTL cleanup does not remove them mid-processing
Backport #110292 to 26.3: Refresh S3Queue bucket locks so the TTL cleanup does not remove them mid-processing
Backport #110292 to 26.6: Refresh S3Queue bucket locks so the TTL cleanup does not remove them mid-processing
…he TTL cleanup does not remove them mid-processing
Linked issues
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
S3Queue/AzureQueueordered mode with persistent processing nodes: bucket locks are now refreshed during streaming, so that the TTL cleanup (persistent_processing_node_ttl_seconds) does not remove locks of a live processor. If lock ownership is nevertheless lost, it is detected and reported (a logical error and theObjectStorageQueueBucketLockLostOwnershipprofile event), and streaming recovers with a fresh file iterator.Version info
26.8.1.195(included in26.8and later)26.7.2.23,26.6.2.125,26.5.6.83,26.3.17.84