From 6ff2683f2276ebc9b74a7210f32ded4f65c30db6 Mon Sep 17 00:00:00 2001 From: "Lei, HUANG" Date: Sat, 10 Oct 2026 00:51:57 +0800 Subject: [PATCH] fix(mito): unregister drop runtime state before WAL cleanup The region leaves the region map before its WAL entries are obsoleted. A failure in `wal.obsolete(...).await?` returned early and skipped `cleanup_dropped_region_runtime_state`, so the resident compaction, flush, and index scheduler entries were never unregistered. Since the region is no longer in the map, a later close cannot clean them up either, leaking the entries for the rest of the worker's lifetime. Move the runtime-state cleanup to immediately after the region leaves the map, before the fallible WAL cleanup. The schedulers only touch their own state and do not depend on the region map or WAL, so the reordering is safe and leaves the success path unchanged. Signed-off-by: Lei, HUANG --- src/mito2/src/worker/handle_drop.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mito2/src/worker/handle_drop.rs b/src/mito2/src/worker/handle_drop.rs index 8112d6a1592..a62e8f0068e 100644 --- a/src/mito2/src/worker/handle_drop.rs +++ b/src/mito2/src/worker/handle_drop.rs @@ -115,6 +115,11 @@ where // Removes this region from region map to prevent other requests from accessing this region self.regions.remove_region(region_id); self.dropping_regions.insert_region(region.clone()); + // The region is no longer served once it leaves the map, so unregister its + // runtime state before the fallible WAL cleanup below. Otherwise a WAL + // failure would leak the resident compaction/flush/index entries that only + // this cleanup and close/drop remove. + self.cleanup_dropped_region_runtime_state(region_id).await; // Delete region data in WAL. self.wal @@ -124,7 +129,6 @@ where ®ion.provider, ) .await?; - self.cleanup_dropped_region_runtime_state(region_id).await; if let Some(store) = &self.series_index_store { crate::series_index::delete_catalogs(store, region_id).await;