Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: fix chunk map compatibility #1417

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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