Repository navigation
Conversation
The waitBlobRemoval() function loops up to 100 times calling triggerAndWait(), each of which blocks indefinitely until the BlobKillerThread completes a full cleanup round. Under sanitizer builds (TSAN/MSAN), each round can take many seconds due to overhead. 100 slow rounds blocks MergeTreeCleanupThread for minutes, causing "Possible deadlock on shutdown" when DatabaseCatalog::shutdown() tries to deactivate the cleanup thread. Add a 30-second total timeout. If exceeded, break the loop and log a warning. Remaining blobs will be cleaned up asynchronously by the next scheduled BlobKillerThread run — the metadata already records them for removal, so no data is lost. This is safe because: 1. The metadata transaction has already committed by the time waitBlobRemoval() is called — blobs are queued for removal 2. BlobKillerThread runs on a schedule and will clean them up 3. The timeout only triggers under extreme conditions (sanitizer overhead, slow I/O) — normal operation completes in <100ms Fixes: ClickHouse#101383
Pre-PR Validation GateSession: a) Deterministic repro? b) Root cause explained? c) Fix matches root cause? d) Test intent preserved? e) Both directions demonstrated? f) Fix is general? |
|
cc @Michicosun @kssenii — could you review this? It adds a 30-second timeout to |
|
cc @alesapin — requesting a second opinion on this approach. The previous attempt (#101454) used a shutdown flag; this one is simpler — a contained 30-second timeout in the existing |
|
Could someone add the |
There was a problem hiding this comment.
First, I thought about how bad it is that we introduced a constant in the code. But then noticed that we already have another, @Michicosun
|
Workflow [PR], commit [1730e14] Summary: ⏳
AI ReviewSummaryThis PR bounds Final VerdictStatus: ✅ Approve |
Michicosun
left a comment
There was a problem hiding this comment.
It is not correct, it will just hide the issue that blobs are not removed fast enough.
|
@Michicosun I understand the concern — the timeout doesn't address the underlying speed of blob removal, it just caps the wait. That said, the issue is still very active despite the performance improvements you made in March (parallel trigger, batch Azure remove, narrower tasks, configurable batch sizes):
88 hits in 7 days, A few questions:
|
…ck-blob-removal-timeout
…e it configurable This addresses the two clickhouse-gh[bot] reviews on PR ClickHouse#101680 (2026-05-16) and @Michicosun's earlier `CHANGES_REQUESTED`: Bot review 1 (DiskObjectStorageTransaction.cpp:70): > "This timeout does not actually bound the blocking wait, because the check > happens only after `triggerAndWait()` returns. `triggerAndWait` waits in > `waitRound` without a deadline, so a single slow or stuck round can still > block here indefinitely (or far beyond 30s)." Bot review 2 (DiskObjectStorageTransaction.cpp:65): > "This introduces a behavior change for `wait_for_blob_removal=true`. The > new behavior is not configurable or documented." @Michicosun: > "It is not correct, it will just hide the issue that blobs are not removed > fast enough." The previous version of the patch added a 30s timeout *around* the `triggerAndWait` call, so a wait that stalled inside `BlobKillerThread::waitRound` would never be interrupted. This rewrite pushes the deadline into `waitRound` itself and surfaces the budget as a documented `ServerSetting`. Changes: * `BlobKillerThread::waitRound` now uses `std::condition_variable::wait_until` with a caller-supplied deadline instead of `std::atomic<int64_t>::wait` (which has no timeout). Returns `bool` (`true` = round completed, `false` = deadline expired). Existing call sites pass `time_point::max()` via the default argument and keep their "wait indefinitely" semantics. * `BlobKillerThread::run` increments `finished_rounds` under the new mutex before `notify_all`, the standard predicate-CV pattern that avoids missed wake-ups. * New `ServerSetting` `disk_object_storage_blob_removal_wait_timeout_ms` (default 30000) bounds the synchronous wait in `DiskObjectStorageTransaction::commit`. The contract is documented in the setting description; `0` restores the strict pre-fix behavior so operators who prefer it can opt back in. * `DiskObjectStorageTransaction::waitBlobRemoval` reads the setting, computes the deadline once before the loop, and propagates it into every `triggerAndWait` call so a stuck round is bounded by the same budget as the outer loop. Other callers of `triggerAndWait` (`DiskObjectStorage::waitBlobsCleanup`, `InterpreterSystemQuery::SYSTEM SYNC FILE CACHE`) are unaffected because they rely on the default argument and discard the return value. Re: CI report https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=b5e6e9088e1324d4a610b4f2a2afe90b74f928a8&name_0=MasterCI&name_1=Stress%20test%20%28azure%2C%20amd_msan%29 PR: ClickHouse#101680 Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Thanks for both follow-ups, @clickhouse-gh, and @Michicosun — your previous review was the missing piece. I've reworked the patch (3d2f70b) so the design actually addresses all three concerns rather than papering over the deadlock. Summary first, then point-by-point. What changed in the new commitInstead of a 30s wall-clock check around
Diff is small (4 files, +87 / -26) — Re: @clickhouse-gh, first review — "timeout does not actually bound the blocking wait"You were right. With the old code, if In the new commit the deadline is enforced inside Re: @clickhouse-gh, second review — "behavior change not configurable or documented"Now configurable via
The semantics are documented inline in Re: @Michicosun — "it will just hide the issue that blobs are not removed fast enough"I agree this is a real concern and the new design tries to give it a proper outlet:
That said — if you'd prefer the strict contract to remain the default and treat 30s as opt-in rather than opt-out, that's a one-line change in CIDB after the previous pushSince 2026-04-10 (your CHANGES_REQUESTED), tracked from PR-monitor cron:
Not blocking, just empirical context for prioritization. Verification
Re-requesting review from @Michicosun (code owner), @kssenii, @alesapin. Happy to iterate further or flip the default if you prefer the strict contract opt-in. |
…ck-blob-removal-timeout # Conflicts: # src/Disks/DiskObjectStorage/Replication/BlobKillerThread.h
…ck-blob-removal-timeout
Addresses the clickhouse-gh[bot] inline review on PR ClickHouse#101680 asking for a deterministic regression test that proves both directions of the new bounded-wait contract introduced by commit 3d2f70b. Changes: 1. New `PAUSEABLE` failpoint `blob_killer_thread_pause_in_run` registered in `src/Common/FailPoint.cpp` and triggered at the top of `BlobKillerThread::run`. While enabled it blocks every cleanup round so `finished_rounds` cannot advance and a concurrent `waitRound` exercises exactly the code path the bot flagged. 2. Per-disk `wait_for_blob_removal_timeout_ms` config option, mirroring the existing per-disk `wait_for_blob_removal` pattern. Falls back to the server setting when absent. Stored on `DiskObjectStorage`, propagated into `DiskObjectStorageTransaction` so the deadline used by `waitBlobRemoval` is per-disk and per-transaction rather than re-read from the global server settings on every commit. This is what lets the stateless test exercise both `timeout > 0` and `timeout = 0` without touching server-wide config. 3. Stateless test `04301_blob_removal_wait_timeout.sh` that drives both directions through the failpoint: Test 1 (`wait_for_blob_removal_timeout_ms = 500`): after enabling the failpoint, `DROP TABLE SYNC` triggers `waitBlobRemoval`; with the fix the bounded wait returns within ~500 ms once the parked round fails to complete. A regression that ignored the deadline or dropped the `false` return from `triggerAndWait` would hang the DROP past the 30 s `timeout` cap and the assertion would fail. Test 2 (`wait_for_blob_removal_timeout_ms = 0`): DROP runs in the background; `SYSTEM WAIT FAILPOINT ... PAUSE` deterministically synchronises on the killer having paused. After a 1 s sleep the test asserts the foreground DROP is still blocked (strict pre-fix semantics). `SYSTEM DISABLE FAILPOINT` releases the round and the DROP completes. A regression that treated `0` as "immediate timeout" would let the DROP finish before the failpoint is released. The test uses `disk(type = 'object_storage', object_storage_type = 'local_blob_storage', metadata_type = 'local', use_fake_transaction = 0, ...)` so the commit path actually goes through `DiskObjectStorageTransaction` rather than `FakeDiskTransaction` (which would short-circuit the entire wait path being tested). Tagged `no-fasttest, no-parallel, no-shared-merge-tree` because the failpoint is server-wide and inline `disk(...)` is unsupported on SMT. Verified locally with the fix in place: - `DROP TABLE t_timeout_short SYNC` completes with the warning "Waiting for blob removal timed out after 500 ms (1 iterations, configured limit 500 ms)" ~626 ms after the DROP, confirming the bounded wait path. - `DROP TABLE t_timeout_zero SYNC` blocks until `SYSTEM DISABLE FAILPOINT`; commit log shows "Waiting for blob removal took 1186 ms" spanning the pause-and-release window, confirming the strict wait path. Co-Authored-By: Claude Opus 4.7 <[email protected]>
…lock-blob-removal-timeout # Conflicts: # src/Disks/DiskObjectStorage/DiskObjectStorage.cpp # src/Disks/DiskObjectStorage/DiskObjectStorageTransaction.cpp
|
CI fully finished on HEAD CI ledger for this SHA — every failure tracked, none PR-caused:
This PR's fix path ( Awaiting bot re-review and @ Michicosun re-review on this SHA. Session: cron:our-pr-ci-monitor:20260604-050120 |
…ck-blob-removal-timeout Resolve conflict in src/Common/FailPoint.cpp: both branches appended a new failpoint to APPLY_FOR_FAILPOINTS. Keep both blob_killer_thread_pause_in_run (this PR) and mt_mutate_task_can_skip_conversion_to_nullable_force_null_column_desc (master). Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
CI finished on One non-green check: All 145 functional, stateless, stress, integration and unit jobs pass. The 2026-05-30 regression-test commit ( |
Because he didn't answer questions from GroeneAI.
|
@groeneai, a few questions: If a transaction does not wait for the blob removal completely, does it affect the logical consistency? Is leaving some garbage in certain cases acceptable? If an operation left some garbage, will it be cleaned up eventually? The same two questions, if we interrupt blob removal on shutdown to prevent hanging for a long time. |
|
@groeneai, and more questions: What is the actual reason for BlobKiller to exist - why don't we remove blobs synchronously like before, and why was it invented? |
|
The short answer to the consistency questions: the metadata transaction commits first, the blob wait happens after, so the timing of physical blob deletion never affects logical consistency. The only thing a not-fully-waited or interrupted removal can leave behind is unreferenced object-storage data (garbage), never a wrong/visible result. Grounding in the code (this PR's HEAD): Ordering. In Q1: transaction does not wait for blob removal completely
Q2: interrupting blob removal on shutdownTwo clarifications first:
Q3: why does BlobKiller exist, instead of synchronous removal like before?It came in with the multi-location / replicated object-storage work ("sync disks", Mikhail Artemenko), which is why it lives under
The slowness is observable via The original design intent is best confirmed by the sync-disks author, but the above is what the current code structure implements. |
…ck-blob-removal-timeout
|
Merged current That flake — No code change in this merge: the net diff versus |
|
CI on the fresh master merge (
Neither failure touches the change. The deterministic regression test ( |
|
this pr has no relation to |
|
Agreed, no objection to closing. Recording the reasoning for the record: The hung-check failures currently firing on master are hung queries (the dumps show fuzzer query analysis: That shutdown symptom is also no longer active: of the 22 "Possible deadlock on shutdown" failures on master in the last 45 days, 0 implicate |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
What this PR does
Adds a 30-second total timeout to
DiskObjectStorageTransaction::waitBlobRemoval().Problem:
waitBlobRemoval()loops up to 100 times callingBlobKillerThread::triggerAndWait(), each of which blocks indefinitely until a full cleanup round completes. Under sanitizer builds (TSAN/MSAN), each round takes many seconds due to overhead. This blocksMergeTreeCleanupThread::iterate()for minutes, causingcleanup_thread.stop()(called duringDatabaseCatalog::shutdown()) to hang — triggering the "Possible deadlock on shutdown" stress test failure.Fix: After each
triggerAndWait()call, check total elapsed time. If >30 seconds, break the loop with a warning. Remaining blobs will be cleaned up by the next scheduledBlobKillerThreadrun — the metadata already records them for removal, so no data is lost.Why this is safe:
BlobKillerThreadruns on a schedule and will process remaining blobsEvidence: 3 master failures on April 2 alone — highest single-day count. gdb.log from
amd_tsanandarm_tsanshowsMergeTreeCleanupThreadblocked inwaitBlobRemoval → triggerAndWait → waitRoundwhileBlobKillerThread::run()executes slowgetBlobsToRemove. Full analysis in PR #101454.CIDB query for failure trend:
Fixes: #101383
This is a follow-up to the analysis in #101454. The previous PR used an
is_shutdownflag; this approach is simpler — a contained timeout inwaitBlobRemoval()with no new state or APIs.Note
Medium Risk
Touches object-storage cleanup/commit blocking behavior and thread synchronization; while intended to prevent indefinite waits, it can change timing (async cleanup) and could expose latent race/cleanup assumptions under load.
Overview
Prevents
DiskObjectStorageTransaction::commitfrom blocking indefinitely on object-storage blob cleanup by introducing a new server settingdisk_object_storage_blob_removal_wait_timeout_ms(default 30s,0= infinite) and enforcing a deadline inwaitBlobRemovalwith a warning when exceeded.Updates
BlobKillerThreadwaiting semantics to support time-bounded waits:triggerAndWait/waitRoundnow accept a deadline and use a mutex + condition variable (instead ofstd::atomic::wait) to avoid missing wakeups and to allow timeouts, ensuring a single slow/stuck cleanup round can’t block callers past the configured budget.Reviewed by Cursor Bugbot for commit 7d21f91. Bugbot is set up for automated code reviews on this repo. Configure here.