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 <discord9@discord9.com>
This commit is contained in:
discord9
2026-11-26 10:23:01 +00:00
committed by GitHub
parent c887958b03
commit e8eb093b72
2 changed files with 22 additions and 1 deletions
+19 -1
View File
@@ -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
+3
View File
@@ -861,6 +861,9 @@ impl RegionManifestManager {
pub fn clear_deleted_files(&mut self, deleted_files: Vec<RemovedFile>) {
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));
}