From c66a4aeb375aebe653b7f1a2401f01c095ce2ff4 Mon Sep 17 00:00:00 2001 From: dennis zhuang Date: Sun, 20 Sep 2026 03:12:51 +0000 Subject: [PATCH] fix(mito2): hold the bulk compact permit for the whole blocking task (#9252) Keep the semaphore permit alive throughout queued and running bulk compaction in `src/mito2/src/memtable/bulk.rs`. (cherry picked from commit e99f75f9b3a0911074da6f3ac66a78b51a63a31d) Signed-off-by: Dennis Zhuang Signed-off-by: Lei, HUANG --- src/mito2/src/memtable/bulk.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mito2/src/memtable/bulk.rs b/src/mito2/src/memtable/bulk.rs index 8e1346b9921..55d8f71e9b0 100644 --- a/src/mito2/src/memtable/bulk.rs +++ b/src/mito2/src/memtable/bulk.rs @@ -1484,11 +1484,15 @@ impl CompactDispatcher { fn dispatch_compact(&self, task: MemCompactTask) { let semaphore = self.semaphore.clone(); common_runtime::spawn_global(async move { - let Ok(_permit) = semaphore.acquire().await else { + let Ok(permit) = semaphore.acquire_owned().await else { return; }; common_runtime::spawn_blocking_global(move || { + // The async task above returns as soon as the blocking task is + // submitted, so the permit has to travel with it to bound the + // compaction that actually runs. + let _permit = permit; if let Err(e) = task.compact() { common_telemetry::error!(e; "Failed to compact memtable, region: {}", task.metadata.region_id); }