-
Notifications
You must be signed in to change notification settings - Fork 208
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
local cas: achieve chunk deduplication for nydus. #1399
Open
xwb1136021767
wants to merge
4
commits into
dragonflyoss:master
Choose a base branch
from
xwb1136021767:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,254
−102
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3d04aa7
nydus-image: support chunk level deduplication between local images
xwb1136021767 cd45665
nydusd: achieve dynamic dedup for nydusd.
5e6a45d
nydusd: solving the mismatch between nydus chunk amplification and dy…
xwb1136021767 6c5147f
Smoke: add smoke test and doc for local-cas
xwb1136021767 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ pub struct ConfigV2 { | |
pub cache: Option<CacheConfigV2>, | ||
/// Configuration information for RAFS filesystem. | ||
pub rafs: Option<RafsConfigV2>, | ||
/// Configuration information for image deduplication. | ||
pub dedup: Option<DeduplicationConfigV2>, | ||
/// Internal runtime configuration. | ||
#[serde(skip)] | ||
pub internal: ConfigV2Internal, | ||
|
@@ -42,6 +44,7 @@ impl Default for ConfigV2 { | |
backend: None, | ||
cache: None, | ||
rafs: None, | ||
dedup: None, | ||
internal: ConfigV2Internal::default(), | ||
} | ||
} | ||
|
@@ -56,6 +59,7 @@ impl ConfigV2 { | |
backend: None, | ||
cache: None, | ||
rafs: None, | ||
dedup: None, | ||
internal: ConfigV2Internal::default(), | ||
} | ||
} | ||
|
@@ -126,6 +130,16 @@ impl ConfigV2 { | |
}) | ||
} | ||
|
||
/// Get configuration information for image deduplication. | ||
pub fn get_dedup_config(&self) -> Result<&DeduplicationConfigV2> { | ||
self.dedup.as_ref().ok_or_else(|| { | ||
Error::new( | ||
ErrorKind::InvalidInput, | ||
"no configuration information for deduplication", | ||
) | ||
}) | ||
} | ||
|
||
/// Get configuration information for cache subsystem. | ||
pub fn get_cache_config(&self) -> Result<&CacheConfigV2> { | ||
self.cache.as_ref().ok_or_else(|| { | ||
|
@@ -962,6 +976,9 @@ pub struct BlobCacheEntryConfigV2 { | |
/// Configuration information for local cache system. | ||
#[serde(default)] | ||
pub cache: CacheConfigV2, | ||
/// Configuration information for chunk deduplication. | ||
#[serde(default)] | ||
pub dedup: Option<DeduplicationConfigV2>, | ||
/// Optional file path for metadata blob. | ||
#[serde(default)] | ||
pub metadata_path: Option<String>, | ||
|
@@ -1024,11 +1041,59 @@ impl From<&BlobCacheEntryConfigV2> for ConfigV2 { | |
backend: Some(c.backend.clone()), | ||
cache: Some(c.cache.clone()), | ||
rafs: None, | ||
dedup: c.dedup.clone(), | ||
internal: ConfigV2Internal::default(), | ||
} | ||
} | ||
} | ||
|
||
/// Configuration information for image deduplication. | ||
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] | ||
pub struct DeduplicationConfigV2 { | ||
#[serde(default)] | ||
pub enable: bool, | ||
#[serde(default)] | ||
pub work_dir: String, | ||
} | ||
|
||
impl DeduplicationConfigV2 { | ||
/// Validate image deduplication configuration. | ||
pub fn validate(&self) -> bool { | ||
true | ||
} | ||
|
||
pub fn get_enable(&self) -> bool { | ||
self.enable | ||
} | ||
pub fn get_work_dir(&self) -> Result<&str> { | ||
let path = fs::metadata(&self.work_dir) | ||
.or_else(|_| { | ||
fs::create_dir_all(&self.work_dir)?; | ||
fs::metadata(&self.work_dir) | ||
}) | ||
.map_err(|e| { | ||
log::error!( | ||
"fail to stat deduplication work_dir {}: {}", | ||
self.work_dir, | ||
e | ||
); | ||
e | ||
})?; | ||
|
||
if path.is_dir() { | ||
Ok(&self.work_dir) | ||
} else { | ||
Err(Error::new( | ||
ErrorKind::NotFound, | ||
format!( | ||
"deduplication work_dir {} is not a directory", | ||
self.work_dir | ||
), | ||
)) | ||
} | ||
} | ||
} | ||
|
||
/// Internal runtime configuration. | ||
#[derive(Clone, Debug)] | ||
pub struct ConfigV2Internal { | ||
|
@@ -1070,7 +1135,7 @@ pub const BLOB_CACHE_TYPE_META_BLOB: &str = "bootstrap"; | |
pub const BLOB_CACHE_TYPE_DATA_BLOB: &str = "datablob"; | ||
|
||
/// Configuration information for a cached blob. | ||
#[derive(Debug, Deserialize, Serialize)] | ||
#[derive(Debug, Deserialize, Serialize, Clone)] | ||
pub struct BlobCacheEntry { | ||
/// Type of blob object, bootstrap or data blob. | ||
#[serde(rename = "type")] | ||
|
@@ -1325,6 +1390,28 @@ impl TryFrom<&CacheConfig> for CacheConfigV2 { | |
} | ||
} | ||
|
||
/// Configuration information for image deduplication. | ||
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] | ||
struct DeduplicationConfig { | ||
/// Whether to enable image dedup | ||
#[serde(default)] | ||
pub enable: bool, | ||
/// Work fir for image dedup | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
#[serde(default)] | ||
pub work_dir: String, | ||
} | ||
|
||
impl TryFrom<&DeduplicationConfig> for DeduplicationConfigV2 { | ||
type Error = std::io::Error; | ||
|
||
fn try_from(v: &DeduplicationConfig) -> std::result::Result<Self, Self::Error> { | ||
Ok(DeduplicationConfigV2 { | ||
enable: v.enable, | ||
work_dir: v.work_dir.clone(), | ||
}) | ||
} | ||
} | ||
|
||
/// Configuration information to create blob cache manager. | ||
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] | ||
struct FactoryConfig { | ||
|
@@ -1336,6 +1423,9 @@ struct FactoryConfig { | |
/// Configuration for blob cache manager. | ||
#[serde(default)] | ||
pub cache: CacheConfig, | ||
/// Configuration information for image deduplication. | ||
#[serde(default)] | ||
pub dedup: Option<DeduplicationConfig>, | ||
} | ||
|
||
/// Rafs storage backend configuration information. | ||
|
@@ -1375,6 +1465,14 @@ impl TryFrom<RafsConfig> for ConfigV2 { | |
fn try_from(v: RafsConfig) -> std::result::Result<Self, Self::Error> { | ||
let backend: BackendConfigV2 = (&v.device.backend).try_into()?; | ||
let mut cache: CacheConfigV2 = (&v.device.cache).try_into()?; | ||
let dedup: Option<DeduplicationConfigV2> = match &v.device.dedup { | ||
Some(dedup) => { | ||
let dedup_v2: DeduplicationConfigV2 = dedup.try_into()?; | ||
Some(dedup_v2) | ||
} | ||
None => None, | ||
}; | ||
// (&v.device.dedup).try_into()?; | ||
let rafs = RafsConfigV2 { | ||
mode: v.mode, | ||
user_io_batch_size: v.user_io_batch_size, | ||
|
@@ -1395,6 +1493,7 @@ impl TryFrom<RafsConfig> for ConfigV2 { | |
backend: Some(backend), | ||
cache: Some(cache), | ||
rafs: Some(rafs), | ||
dedup, | ||
internal: ConfigV2Internal::default(), | ||
}) | ||
} | ||
|
@@ -1490,6 +1589,8 @@ pub(crate) struct BlobCacheEntryConfig { | |
/// | ||
/// Possible value: `FileCacheConfig`, `FsCacheConfig`. | ||
cache_config: Value, | ||
/// Configuration for chunk deduplication | ||
dedup_config: Option<DeduplicationConfig>, | ||
/// Configuration for data prefetch. | ||
#[serde(default)] | ||
prefetch_config: BlobPrefetchConfig, | ||
|
@@ -1513,11 +1614,19 @@ impl TryFrom<&BlobCacheEntryConfig> for BlobCacheEntryConfigV2 { | |
cache_validate: false, | ||
prefetch_config: v.prefetch_config.clone(), | ||
}; | ||
let dedup_config = match &v.dedup_config { | ||
Some(cfg) => { | ||
let cfg_v2: DeduplicationConfigV2 = cfg.try_into()?; | ||
Some(cfg_v2) | ||
} | ||
None => None, | ||
}; | ||
Ok(BlobCacheEntryConfigV2 { | ||
version: 2, | ||
id: v.id.clone(), | ||
backend: (&backend_config).try_into()?, | ||
cache: (&cache_config).try_into()?, | ||
dedup: dedup_config, | ||
metadata_path: v.metadata_path.clone(), | ||
}) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a pub field, still need this? Also better be
is_enable
.