From a8f1ed7fc9b00d3070b930fd7274de9fa97ec3da Mon Sep 17 00:00:00 2001 From: Yingwen Date: Mon, 2 Feb 2026 20:33:41 +0800 Subject: [PATCH] feat: add recover_sync to ManifestCache::new (#7652) feat: add recover_sync to ManifestCache::new This ensures tests can recover in sync Signed-off-by: evenyag --- src/mito2/src/cache/manifest_cache.rs | 16 +++++++--------- src/mito2/src/cache/write_cache.rs | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/mito2/src/cache/manifest_cache.rs b/src/mito2/src/cache/manifest_cache.rs index 6d2c563499..182526fe94 100644 --- a/src/mito2/src/cache/manifest_cache.rs +++ b/src/mito2/src/cache/manifest_cache.rs @@ -55,6 +55,7 @@ impl ManifestCache { local_store: ObjectStore, capacity: ReadableSize, ttl: Option, + recover_sync: bool, ) -> ManifestCache { let total_capacity = capacity.as_bytes(); @@ -67,8 +68,8 @@ impl ManifestCache { let cache = ManifestCache { local_store, index }; - // Recovers the cache index from local store asynchronously - cache.recover(false).await; + // Recovers the cache index from local store. + cache.recover(recover_sync).await; cache } @@ -483,7 +484,7 @@ mod tests { let dir = create_temp_dir(""); let local_store = new_fs_store(dir.path().to_str().unwrap()); - let cache = ManifestCache::new(local_store.clone(), ReadableSize::mb(10), None).await; + let cache = ManifestCache::new(local_store.clone(), ReadableSize::mb(10), None, true).await; let key = "region_1/manifest/00000000000000000007.json"; let file_path = cache.cache_file_path(key); @@ -527,7 +528,7 @@ mod tests { let dir = create_temp_dir(""); let local_store = new_fs_store(dir.path().to_str().unwrap()); - let cache = ManifestCache::new(local_store.clone(), ReadableSize::mb(10), None).await; + let cache = ManifestCache::new(local_store.clone(), ReadableSize::mb(10), None, true).await; // Write some manifest files with different paths let keys = [ @@ -559,10 +560,7 @@ mod tests { } // Create a new cache instance which will automatically recover from local store - let cache = ManifestCache::new(local_store.clone(), ReadableSize::mb(10), None).await; - - // Wait for recovery to complete synchronously - cache.recover(true).await; + let cache = ManifestCache::new(local_store.clone(), ReadableSize::mb(10), None, true).await; // Check size. cache.index.run_pending_tasks().await; @@ -580,7 +578,7 @@ mod tests { async fn test_cache_file_path() { let dir = create_temp_dir(""); let local_store = new_fs_store(dir.path().to_str().unwrap()); - let cache = ManifestCache::new(local_store, ReadableSize::mb(10), None).await; + let cache = ManifestCache::new(local_store, ReadableSize::mb(10), None, true).await; assert_eq!( "cache/object/manifest/region_1/manifest/00000000000000000007.json", diff --git a/src/mito2/src/cache/write_cache.rs b/src/mito2/src/cache/write_cache.rs index accb7dfcff..ddd9a6c8ca 100644 --- a/src/mito2/src/cache/write_cache.rs +++ b/src/mito2/src/cache/write_cache.rs @@ -112,7 +112,7 @@ impl WriteCache { // Create manifest cache if capacity is non-zero let manifest_cache = if manifest_cache_capacity.as_bytes() > 0 { - Some(ManifestCache::new(local_store.clone(), manifest_cache_capacity, ttl).await) + Some(ManifestCache::new(local_store.clone(), manifest_cache_capacity, ttl, false).await) } else { None };