From 8df5d7f4e584424433239197138aa54598def845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B3=B0=E5=8F=8B?= Date: Tue, 23 Jan 2024 07:49:46 +0000 Subject: [PATCH] feat: reuse blob cache of old version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nydus2.2 has same format for blob cache and bitmap on disk. However, 2.2 nydusd not use blob cache of 1.6 nydusd. This pr counts ready chunk number for both 1.6 and 2.2, instead of thinking it as not filled at all. Signed-off-by: 泰友 --- smoke/tests/blobcache_test.go | 2 +- storage/src/cache/filecache/mod.rs | 2 +- storage/src/cache/state/persist_map.rs | 51 ++++++++++++-------------- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/smoke/tests/blobcache_test.go b/smoke/tests/blobcache_test.go index 5dd10a25f88..ca5a44eabd3 100644 --- a/smoke/tests/blobcache_test.go +++ b/smoke/tests/blobcache_test.go @@ -212,7 +212,7 @@ func (a *BlobCacheTestSuite) TestGenerateBlobcache(t *testing.T) { ctx.Binary.Builder, ctx.Env.BootstrapPath, blobcacheDir, filepath.Join(ctx.Env.BlobDir, ociBlobDigest.Hex()))) - a.compareTwoFiles(t, filepath.Join(blobcacheDir, fmt.Sprintf("%s.blob.data", ociBlobDigest.Hex())), filepath.Join(ctx.Env.CacheDir, fmt.Sprintf("%s.blob.data", ociBlobDigest.Hex()))) + a.compareTwoFiles(t, filepath.Join(blobcacheDir, fmt.Sprintf("%s.blob.data", ociBlobDigest.Hex())), filepath.Join(ctx.Env.CacheDir, ociBlobDigest.Hex())) a.compareTwoFiles(t, filepath.Join(blobcacheDir, fmt.Sprintf("%s.blob.meta", ociBlobDigest.Hex())), filepath.Join(ctx.Env.CacheDir, fmt.Sprintf("%s.blob.meta", ociBlobDigest.Hex()))) } diff --git a/storage/src/cache/filecache/mod.rs b/storage/src/cache/filecache/mod.rs index fd561c8a60c..88485c32036 100644 --- a/storage/src/cache/filecache/mod.rs +++ b/storage/src/cache/filecache/mod.rs @@ -25,7 +25,7 @@ use crate::cache::{BlobCache, BlobCacheMgr}; use crate::device::{BlobFeatures, BlobInfo}; pub const BLOB_RAW_FILE_SUFFIX: &str = ".blob.raw"; -pub const BLOB_DATA_FILE_SUFFIX: &str = ".blob.data"; +pub const BLOB_DATA_FILE_SUFFIX: &str = ""; /// An implementation of [BlobCacheMgr](../trait.BlobCacheMgr.html) to improve performance by /// caching uncompressed blob with local storage. diff --git a/storage/src/cache/state/persist_map.rs b/storage/src/cache/state/persist_map.rs index bf434174607..bfe39734d0f 100644 --- a/storage/src/cache/state/persist_map.rs +++ b/storage/src/cache/state/persist_map.rs @@ -111,36 +111,33 @@ impl PersistMap { } let header = filemap.get_mut::
(0)?; - let mut not_ready_count = chunk_count; - if header.version >= 1 { - if header.magic2 != MAGIC2 { - return Err(einval!(format!( - "invalid blob chunk_map file header: {:?}", - filename - ))); + if header.version >= 1 && header.magic2 != MAGIC2 { + return Err(einval!(format!( + "invalid blob chunk_map file header: {:?}", + filename + ))); + } + let not_ready_count = if new_content { + chunk_count + } else if header.version >= 1 && header.all_ready == MAGIC_ALL_READY { + 0 + } else { + let mut ready_count = 0; + for idx in HEADER_SIZE..expected_size as usize { + let current = filemap.get_ref::(idx)?; + let val = current.load(Ordering::Acquire); + ready_count += val.count_ones() as u32; } - if header.all_ready == MAGIC_ALL_READY { - not_ready_count = 0; - } else if new_content { - not_ready_count = chunk_count; - } else { - let mut ready_count = 0; - for idx in HEADER_SIZE..expected_size as usize { - let current = filemap.get_ref::(idx)?; - let val = current.load(Ordering::Acquire); - ready_count += val.count_ones() as u32; - } - if ready_count >= chunk_count { - let header = filemap.get_mut::
(0)?; - header.all_ready = MAGIC_ALL_READY; - let _ = file.sync_all(); - not_ready_count = 0; - } else { - not_ready_count = chunk_count - ready_count; - } + if ready_count >= chunk_count { + let header = filemap.get_mut::
(0)?; + header.all_ready = MAGIC_ALL_READY; + let _ = file.sync_all(); + 0 + } else { + chunk_count - ready_count } - } + }; readahead(file.as_raw_fd(), 0, expected_size); if !persist {