diff --git a/src/mito2/src/region/version.rs b/src/mito2/src/region/version.rs index fa95255c1a5c..15928e1e22c2 100644 --- a/src/mito2/src/region/version.rs +++ b/src/mito2/src/region/version.rs @@ -80,14 +80,11 @@ impl VersionControl { /// Freezes the mutable memtable if it is not empty. pub(crate) fn freeze_mutable(&self) -> Result<()> { let version = self.current().version; - if version.memtables.mutable.is_empty() { + + let Some(new_memtables) = version.memtables.freeze_mutable(&version.metadata)? else { return Ok(()); - } - // Safety: Immutable memtable is None. - let new_memtables = version - .memtables - .freeze_mutable(&version.metadata)? - .unwrap(); + }; + // Create a new version with memtable switched. let new_version = Arc::new( VersionBuilder::from_version(version)