Skip to content

Commit

Permalink
Merge branch 'master' into generate-blobcache
Browse files Browse the repository at this point in the history
  • Loading branch information
zyfjeff authored Sep 5, 2023
2 parents 830d7ce + 1d93f12 commit f57777a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
11 changes: 7 additions & 4 deletions storage/src/cache/filecache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ use crate::cache::{BlobCache, BlobCacheMgr};
use crate::device::{BlobFeatures, BlobInfo};
use crate::RAFS_DEFAULT_CHUNK_SIZE;

pub const BLOB_RAW_FILE_SUFFIX: &str = ".blob.raw";
pub const BLOB_DATA_FILE_SUFFIX: &str = ".blob.data";

/// An implementation of [BlobCacheMgr](../trait.BlobCacheMgr.html) to improve performance by
/// caching uncompressed blob with local storage.
#[derive(Clone)]
Expand Down Expand Up @@ -107,7 +110,7 @@ impl FileCacheMgr {
.underlying_files
.lock()
.unwrap()
.insert(blob_id);
.insert(blob_id + BLOB_DATA_FILE_SUFFIX);
Ok(entry)
}
}
Expand Down Expand Up @@ -236,9 +239,9 @@ impl FileCacheEntry {
&& !is_legacy_stargz;
// Set cache file to its expected size.
let suffix = if mgr.cache_raw_data {
".blob.raw"
BLOB_RAW_FILE_SUFFIX
} else {
".blob.data"
BLOB_DATA_FILE_SUFFIX
};
let blob_data_file_path = blob_file_path.clone() + suffix;
let file = OpenOptions::new()
Expand Down Expand Up @@ -358,7 +361,7 @@ impl FileCacheEntry {
Arc::new(BlobStateMap::from(DigestedChunkMap::new()))
} else {
Arc::new(BlobStateMap::from(IndexedChunkMap::new(
blob_file,
&format!("{}{}", blob_file, BLOB_DATA_FILE_SUFFIX),
blob_info.chunk_count(),
true,
)?))
Expand Down
6 changes: 4 additions & 2 deletions storage/src/cache/fscache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use crate::device::{BlobFeatures, BlobInfo, BlobObject};
use crate::factory::BLOB_FACTORY;
use crate::RAFS_DEFAULT_CHUNK_SIZE;

use crate::cache::filecache::BLOB_DATA_FILE_SUFFIX;

const FSCACHE_BLOBS_CHECK_NUM: u8 = 1;

/// An implementation of [BlobCacheMgr](../trait.BlobCacheMgr.html) to improve performance by
Expand Down Expand Up @@ -104,7 +106,7 @@ impl FsCacheMgr {
.underlying_files
.lock()
.unwrap()
.insert(blob_id);
.insert(blob_id + BLOB_DATA_FILE_SUFFIX);
Ok(entry)
}
}
Expand Down Expand Up @@ -256,7 +258,7 @@ impl FileCacheEntry {
};

let chunk_map = Arc::new(BlobStateMap::from(IndexedChunkMap::new(
&blob_file_path,
&format!("{}{}", blob_file_path, BLOB_DATA_FILE_SUFFIX),
blob_info.chunk_count(),
false,
)?));
Expand Down
10 changes: 1 addition & 9 deletions storage/src/cache/state/indexed_chunk_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::io::Result;

use crate::cache::state::persist_map::PersistMap;
use crate::cache::state::{ChunkIndexGetter, ChunkMap, RangeMap};
use crate::device::{BlobChunkInfo, BlobInfo};
use crate::device::BlobChunkInfo;

/// The name suffix of blob chunk_map file, named $blob_id.chunk_map.
const FILE_SUFFIX: &str = "chunk_map";
Expand All @@ -39,14 +39,6 @@ impl IndexedChunkMap {

PersistMap::open(&filename, chunk_count, true, persist).map(|map| IndexedChunkMap { map })
}

/// Create a new instance of `IndexedChunkMap` from an existing chunk map file.
pub fn open(blob_info: &BlobInfo, workdir: &str) -> Result<Self> {
let filename = format!("{}/{}.{}", workdir, blob_info.blob_id(), FILE_SUFFIX);

PersistMap::open(&filename, blob_info.chunk_count(), false, true)
.map(|map| IndexedChunkMap { map })
}
}

impl ChunkMap for IndexedChunkMap {
Expand Down
2 changes: 2 additions & 0 deletions utils/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,8 @@ pub struct BlobcacheMetrics {
id: String,
// Prefer to let external tool get file's state like file size and disk usage.
// Because stat(2) file may get blocked.
// It should include the real blob cache file names, so that the external GC
// process can handle it directly.
pub underlying_files: Mutex<HashSet<String>>,
pub store_path: String,
// Cache hit percentage = (partial_hits + whole_hits) / total
Expand Down

0 comments on commit f57777a

Please sign in to comment.