From e8eb093b7251746cfbb9dc513eecceb90eb6fd22 Mon Sep 17 00:00:00 2001 From: discord9 Date: Thu, 26 Nov 2026 10:23:01 +0000 Subject: [PATCH] fix(mito): refresh the removed-file count when GC clears its records (#10636) Clearing deleted files from the manifest does not commit a manifest version, and the count reported to metasrv was only recomputed on open, create, commit and checkpoint. A region that goes write-idle after a GC pass therefore kept reporting the files GC had already deleted, indefinitely. That stale count feeds the GC score, so such a region kept winning a candidate slot on a table while it had nothing left to reclaim, and a region with real garbage behind it could stay outside the top-N. Recompute the count at the clearing site, exactly like the other five places that change removed_files. The read path is untouched: region_statistic still loads one atomic. Signed-off-by: discord9 --- src/mito2/src/gc/worker_test.rs | 20 +++++++++++++++++++- src/mito2/src/manifest/manager.rs | 3 +++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/mito2/src/gc/worker_test.rs b/src/mito2/src/gc/worker_test.rs index 1f31b98d7be..13aaa198d47 100644 --- a/src/mito2/src/gc/worker_test.rs +++ b/src/mito2/src/gc/worker_test.rs @@ -29,7 +29,7 @@ use object_store::layers::mock::{ }; use object_store::{Entry, ObjectStore, services}; use store_api::metadata::RegionMetadataRef; -use store_api::region_engine::{RegionEngine as _, RegionRole}; +use store_api::region_engine::{RegionEngine as _, RegionManifestInfo, RegionRole}; use store_api::region_request::{RegionCompactRequest, RegionRequest}; use store_api::storage::{FileId, FileRef, FileRefsManifest, IndexVersion, RegionId}; @@ -526,6 +526,14 @@ async fn test_gc_worker_basic_truncate() { "Manifest after truncate: {:?}", manifest ); + // Truncate committed the files it removed, so the reported count is not zero yet. + let RegionManifestInfo::Mito { + file_removed_cnt, .. + } = region.region_statistic().manifest + else { + unreachable!("mito region reports a mito manifest"); + }; + assert!(file_removed_cnt > 0, "manifest: {manifest:?}"); let version = manifest.manifest_version; let regions = BTreeMap::from([(region_id, Some(region.clone()))]); @@ -544,6 +552,16 @@ async fn test_gc_worker_basic_truncate() { let manifest = region.manifest_ctx.manifest().await; assert!(manifest.removed_files.removed_files.is_empty() && manifest.files.is_empty()); + + // GC cleared the records without any new write, flush or manifest commit for this region, so + // the reported count must follow the manifest. + let RegionManifestInfo::Mito { + file_removed_cnt, .. + } = region.region_statistic().manifest + else { + unreachable!("mito region reports a mito manifest"); + }; + assert_eq!(0, file_removed_cnt, "manifest: {manifest:?}"); } /// Truncate with file refs should not delete files diff --git a/src/mito2/src/manifest/manager.rs b/src/mito2/src/manifest/manager.rs index 27917a4729c..57c97920522 100644 --- a/src/mito2/src/manifest/manager.rs +++ b/src/mito2/src/manifest/manager.rs @@ -861,6 +861,9 @@ impl RegionManifestManager { pub fn clear_deleted_files(&mut self, deleted_files: Vec) { let mut manifest = (*self.manifest()).clone(); manifest.removed_files.clear_deleted_files(deleted_files); + manifest + .removed_files + .update_file_removed_cnt_to_stats(&self.stats); self.set_manifest(Arc::new(manifest)); }