From cb37f9e78cd8d539c613f579158ea90ac0ce8f41 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Wed, 29 Jul 2026 21:44:33 +0800 Subject: [PATCH] fix(mito2): merge staging manifest files in all_manifest_files The original implementation only read the normal manifest (manifest_ctx.manifest()) and skipped staging_manifest(). While the region is in staging mode (e.g. region copy/migration), the authoritative live file set lives in the staging manifest, so callers would silently miss those files. Now matches the semantics of manifest_sst_entries() (~L771), which explicitly merges manifest().files with staging_manifest().files via a HashMap collect (dedup by FileId). The returned manifest version is the staging version when a staging manifest is present, otherwise the normal manifest version. Also removed downstream-specific references from the rustdoc comments. --- src/mito2/src/region.rs | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/mito2/src/region.rs b/src/mito2/src/region.rs index 55115ef6896..292f3ec6d44 100644 --- a/src/mito2/src/region.rs +++ b/src/mito2/src/region.rs @@ -850,14 +850,41 @@ impl MitoRegion { } /// Returns all live SST file metas and the current manifest version from - /// the region manifest. + /// the region manifest, merging both the normal and staging manifests. /// - /// Used by the Iceberg rebuild admin path to enumerate the authoritative - /// live file set without going through the worker loop. + /// While the region is in staging mode (e.g. during region copy/migration), + /// the authoritative live file set lives in the staging manifest, so this + /// method merges both — matching the semantics of [`manifest_sst_entries`]. + /// + /// The returned manifest version is the staging version when a staging + /// manifest is present, otherwise the normal manifest version. pub async fn all_manifest_files(&self) -> (Vec, ManifestVersion) { let manifest = self.manifest_ctx.manifest().await; - let files = manifest.files.values().cloned().collect(); - (files, manifest.manifest_version) + let staging = self + .manifest_ctx + .staging_manifest() + .await + .map(|m| (m.files.clone(), m.manifest_version)); + + let version = staging + .as_ref() + .map(|(_, v)| *v) + .unwrap_or(manifest.manifest_version); + + let files = match staging { + Some((staging_files, _)) => { + let merged = manifest + .files + .clone() + .into_iter() + .chain(staging_files) + .collect::>(); + merged.into_values().collect() + } + None => manifest.files.values().cloned().collect(), + }; + + (files, version) } /// Exit staging mode successfully by merging all staged manifests and making them visible.