Skip to content

Commit

Permalink
feat: reuse blob cache of old version
Browse files Browse the repository at this point in the history
    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: 泰友 <cuichengxu.ccx@antgroup.com>
  • Loading branch information
泰友 committed Mar 27, 2024
1 parent f4fde1c commit 8df5d7f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion smoke/tests/blobcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())))
}

Expand Down
2 changes: 1 addition & 1 deletion storage/src/cache/filecache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
51 changes: 24 additions & 27 deletions storage/src/cache/state/persist_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,36 +111,33 @@ impl PersistMap {
}

let header = filemap.get_mut::<Header>(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::<AtomicU8>(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::<AtomicU8>(idx)?;
let val = current.load(Ordering::Acquire);
ready_count += val.count_ones() as u32;
}

if ready_count >= chunk_count {
let header = filemap.get_mut::<Header>(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::<Header>(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 {
Expand Down

0 comments on commit 8df5d7f

Please sign in to comment.