Repository navigation
Do not run BlobKiller and BlobCopier threads for disks that never need them - #118662
Conversation
… need them `BlobKillerThread` and `BlobCopierThread` drain two queues that live in the metadata storage: the dead blobs, submitted for removal by a committed transaction, and the blobs that are still missing in some of the cluster locations. Only the `local` metadata storage ever fills them. The `plain` and `plain_rewritable` metadata storages remove objects synchronously, right inside the metadata transaction, and the `web` and `web_index` ones are read-only, so for all of them both queues stay empty forever. The disk created both threads anyway, and the blob killer is enabled by default with a one second interval, so every such disk woke up a background schedule pool task once a second only to find nothing to do. That is pure overhead for a read-only `MergeTree` table on a `plain_rewritable` disk, and there is usually one such disk per table. Ask the metadata storage with the new `hasDeadBlobsQueue` and `hasMissingBlobsQueue` and skip creating the corresponding thread when it answers `false`. Both default to `true`, so a metadata storage has to opt out explicitly. A cached disk delegates the answer to the storage it wraps. `SYSTEM WAIT BLOBS CLEANUP` keeps working on such a disk: nothing is deferred there, so it returns immediately.
|
Workflow [PR], commit [6895ed2] Summary: ✅
AI ReviewSummaryThe PR avoids periodic Final VerdictStatus: ✅ Approve. |
Michicosun
left a comment
There was a problem hiding this comment.
Let's just check hasDeadBlobsQueue/hasMissingBlobsQueue in threads startup and applyNewSettings where the underlying task is being activated.
…n-plain-disks # Conflicts: # src/Disks/DiskObjectStorage/MetadataStorages/PlainRewritable/MetadataStorageFromPlainRewritableObjectStorage.h
`BlobKillerThread` and `BlobCopierThread` were not created at all for a metadata storage that never defers blob removal or replication, so `DiskObjectStorage::blob_killer` and `blob_copier` could be `nullptr` and every use of them needed a check. As requested in the review, the pointers are never null again; instead each thread asks its metadata storage whether the corresponding queue exists and never activates its background schedule pool task when it does not. This is the only thing that costs anything: an idle task woken up once a second. `triggerAndWait` returns immediately in that case. It has to: the task is deactivated, so `task->schedule()` would do nothing and waiting for the round counter to advance would never return. `BlobKillerThread::shutdown` also skips the final explicit cleanup round, which had nothing to drain.
…tadata directory The previous revision of the test defined the `local` metadata disk with `path = 'disks/05136_local_metadata/'`, which is exactly where the `local` metadata storage puts its own files, and `CREATE TABLE` failed in the Fast test with `filesystem error: in create_directory: No such file or directory`. `LocalObjectStorage::removeObject` removes the now empty parent directories of a deleted blob, and its guard against removing the root of the object storage itself compares a relative path against the canonicalized absolute root, so with a relative `path` the root is removed too - taking the metadata directory of the disk with it. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118662&sha=d8d6ea69f9f711c6f44b66545c93334eae85a5cb&name_0=PR&name_1=Fast%20test #118662
`MetadataStorageFromCacheObjectStorage::hasDeadBlobsQueue` delegated the answer to the storage it wraps, which is wrong: the wrapper does not forward this queue, it has one of its own. Every `commit` and `tryCommit` moves `underlying->getSubmittedForRemovalBlobs()` into `objects_to_remove`, and `getBlobsToRemove` drains that local queue, so that `BlobKillerThread` drops the cache entries of the removed blobs. A cached `plain` or `plain_rewritable` disk therefore does need a running blob killer, and it is not only a matter of wasted space: `areBlobPathsRandom` is `false` for those storages, so a new file reuses the path of a deleted one and a stale cache entry would be read as its contents. With the delegated answer the queue never drained, and `SYSTEM WAIT BLOBS CLEANUP` became a no-op on such a disk. The wrapper now reports its own queue. A read-only storage never removes anything, so nothing is ever queued for it and a cached `web` disk still gets no blob killer.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units60 translation units recompiled, 544 s compile time in total, 60 of them have a recent master baseline. |
|
🕵 Both tests of this pull request passed in the same run: Related: #119136 |
|
🕵 @groeneai, please investigate this failure and provide a fix in a separate pull request; if a fix is already in progress, link it here.
It is not caused by this pull request, which only stops a background blob removal task from running on
The shape of it: I have found no open issue for it. |
|
Your The remover, in that run. The stress harness disrupts itself: It needs neither S3 nor the stress harness, so it does reproduce locally. Use a which is the same statement and the same object as CI's 499; only the backend's error code differs. Where I put the fix, since you named the test. In The fix is in review and not open yet. I will link it here when it opens. For prioritizing: my CI scan counts six occurrences of this shape in the 5.2 h after the first one, on |
…n-plain-disks # Conflicts: # src/Disks/DiskObjectStorage/MetadataStorages/PlainRewritable/MetadataStorageFromPlainRewritableObjectStorage.h
|
Fix PR: #119154. It tolerates a It is parked rather than in review: #119276 reverted #110939, so One gap in it, measured on that PR's own CI with the fix present in the build: a mutation that was killed before it had applied to every part leaves a readonly reader permanently unable to attach, and I did not find a reader-side predicate that is safe for that case. Traces and options are in #119154 (comment); my preference is to order the entry unlink after the mutate task's commit barrier, which makes the reader-side reconciliation sound. Apologies for the late link. |
alexey-milovidov
left a comment
There was a problem hiding this comment.
LGTM now. I didn't like the usage of LOG_INFO (instead of LOG_TRACE), but it was pre-existing.
…he layer after a reload to `readonly` `MetadataStorageFromCacheObjectStorage::hasDeadBlobsQueue` only told whether new dead blobs can be queued from now on. If the wrapped disk was reloaded as read-only while `objects_to_remove` still had entries, `BlobKillerThread` deactivated its task, skipped the final flush on shutdown, and the queue, which is not persisted, was lost together with the cache invalidations for those blobs. Now a non-empty queue is always reported, so it is drained first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hen the cache layer has no dead blobs queue A cache layer over a disk reloaded to `readonly` reports no dead blobs queue of its own once its in-memory queue is drained, but the wrapped disk may still have pending removals. `SYSTEM WAIT BLOBS CLEANUP` on the cache disk must still wait for the wrapped disk in that case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/PRs/118662/81962ec6f9c0b0551a0308cba8a9a2f7778cbb2e/pr/ast_fuzzer_amd_release_oracle/fatal.log ( The other failure, |
|
This is the same negative-zero hash-key defect as on #110626, and #115970 fixes it. The shard query is
With |
|
🕵 Thanks, @groeneai. The The only red check at ab20de5, |
|
🕵 All 12 red |
… wake up on queued blobs `BlobKillerThread` no longer deactivates its task when `hasDeadBlobsQueue` answers `false`. The task stays active, is scheduled only when there may be dead blobs, and `run` stops rescheduling itself once the queue is drained and nothing new can be queued (a cache layer over a `plain` disk reloaded as read-only). `MetadataStorageFromCacheObjectStorage` calls a callback registered by the blob killer after it queued the blobs of a committed transaction, so a commit that is still in flight during the reload wakes the task up, and `SYSTEM WAIT BLOBS CLEANUP` can always schedule a round instead of waiting on a deactivated task. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s are queued The callback that `MetadataStorageFromCacheObjectStorage` invokes after queueing dead blobs called `schedule`, which cancels an already delayed round, so every commit on a writable cached disk started an immediate cleanup pass and bypassed the batching by `data_background_cleanup.interval_sec`. Use `scheduleAfter(0, /*overwrite=*/ false)` instead: it wakes up an idle task (e.g. after a reload to `readonly` stopped the polling) but keeps a pending delayed round as is. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The callback of a cache layer used `scheduleAfter(0, false)`. When it fired while a round was running, the task got `scheduled = true`, so the `scheduleAfter(interval)` at the end of the round was a no-op and the next round ran immediately, bypassing `data_background_cleanup.interval_sec`. Now `BlobKillerThread` tracks whether it stopped rescheduling itself (`polling_stopped`) under a mutex. The decision to stop at the end of a round is taken under that mutex, and the metadata storage queues blobs before it calls the callback, so a commit either makes `hasDeadBlobsQueue` answer `true` for the round or wakes up the task after it stopped. While polling, the callback does nothing and ordinary asynchronous removals stay batched. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged |
…` by time Each query scanned the whole `text_log`, which exceeds the test's `max_rows_to_read` on a server with a large `text_log`. Related: ClickHouse#118662 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
BlobKillerThreadandBlobCopierThreaddrain two queues that live in the metadata storage: the dead blobs, submitted for removal by a committed transaction, and the blobs that are still missing in some of the cluster locations. Only thelocalmetadata storage ever fills them.The
plainandplain_rewritablemetadata storages remove objects synchronously, right inside the metadata transaction, and thewebandweb_indexones are read-only, so for all of them both queues stay empty forever. The blob killer is enabled by default with a one second interval, so every such disk woke up a background schedule pool task once a second only to find nothing to do. That is pure overhead for a read-onlyMergeTreetable on aplain_rewritabledisk, and there is usually one such disk per table.The metadata storage is now asked with the new
hasDeadBlobsQueueandhasMissingBlobsQueue, and the thread never activates its background task when it answersfalse. Both default totrue, so a metadata storage has to opt out explicitly; a cached disk delegates the copier answer to the storage it wraps, but keeps its own queue of dead blobs (to drop stale cache entries) unless the wrapped storage is read-only, or removes blobs synchronously over a read-only object storage. The threads themselves are still always created, soDiskObjectStorage::blob_killerandblob_copierare never null and every caller stays as it was.triggerAndWaitreturns immediately for such a storage. It has to: the task is deactivated, sotask->schedule()would do nothing and waiting for the round counter to advance would never return.SYSTEM WAIT BLOBS CLEANUPtherefore keeps working on such a disk - nothing is deferred there, so it returns immediately.Related: #119119
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Disks that keep their metadata in the object storage itself (
plain,plain_rewritable) or serve it from a web server (web,web_index) no longer run the background blob cleanup and blob replication tasks, which had nothing to do there. Previously every such disk woke up a background task once a second, which was noticeable with many read-onlyMergeTreetables, each on its ownplain_rewritabledisk.Workflow [PR]
Sync PR [sync-upstream/pr/118662]
Version info
26.11.1.341-master(included in26.11and later)