Skip to content

Commit c030ca2

Browse files
committed
builder: support external blob build
Signed-off-by: Yan Song <[email protected]>
1 parent 855de68 commit c030ca2

File tree

19 files changed

+435
-92
lines changed

19 files changed

+435
-92
lines changed

builder/src/compact.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl BlobCompactor {
285285
version,
286286
states: vec![Default::default(); ori_blobs_number],
287287
ori_blob_mgr,
288-
new_blob_mgr: BlobManager::new(digester),
288+
new_blob_mgr: BlobManager::new(digester, false),
289289
c2nodes: HashMap::new(),
290290
b2nodes: HashMap::new(),
291291
backend,
@@ -547,7 +547,8 @@ impl BlobCompactor {
547547
info!("compactor: delete compacted blob {}", ori_blob_ids[idx]);
548548
}
549549
State::Rebuild(cs) => {
550-
let blob_storage = ArtifactStorage::FileDir(PathBuf::from(dir));
550+
let blob_storage =
551+
ArtifactStorage::FileDir((PathBuf::from(dir), String::new()));
551552
let mut blob_ctx = BlobContext::new(
552553
String::from(""),
553554
0,
@@ -557,6 +558,7 @@ impl BlobCompactor {
557558
build_ctx.cipher,
558559
Default::default(),
559560
None,
561+
false,
560562
);
561563
blob_ctx.set_meta_info_enabled(self.is_v6());
562564
let blob_idx = self.new_blob_mgr.alloc_index()?;
@@ -609,6 +611,7 @@ impl BlobCompactor {
609611
PathBuf::from(""),
610612
Default::default(),
611613
None,
614+
None,
612615
false,
613616
Features::new(),
614617
false,
@@ -617,7 +620,7 @@ impl BlobCompactor {
617620
let mut bootstrap_mgr =
618621
BootstrapManager::new(Some(ArtifactStorage::SingleFile(d_bootstrap)), None);
619622
let mut bootstrap_ctx = bootstrap_mgr.create_ctx()?;
620-
let mut ori_blob_mgr = BlobManager::new(rs.meta.get_digester());
623+
let mut ori_blob_mgr = BlobManager::new(rs.meta.get_digester(), false);
621624
ori_blob_mgr.extend_from_blob_table(&build_ctx, rs.superblock.get_blob_infos())?;
622625
if let Some(dict) = chunk_dict {
623626
ori_blob_mgr.set_chunk_dict(dict);
@@ -656,7 +659,9 @@ impl BlobCompactor {
656659

657660
Ok(Some(BuildOutput::new(
658661
&compactor.new_blob_mgr,
662+
None,
659663
&bootstrap_mgr.bootstrap_storage,
664+
&None,
660665
)?))
661666
}
662667
}
@@ -858,6 +863,7 @@ mod tests {
858863
crypt::Algorithm::Aes256Xts,
859864
Arc::new(cipher_object),
860865
None,
866+
false,
861867
);
862868
let ori_blob_ids = ["1".to_owned(), "2".to_owned()];
863869
let backend = Arc::new(MockBackend {
@@ -970,7 +976,7 @@ mod tests {
970976
HashChunkDict::from_commandline_arg(path, Arc::new(ConfigV2::default()), &rafs_config)
971977
.unwrap();
972978

973-
let mut ori_blob_mgr = BlobManager::new(digest::Algorithm::Sha256);
979+
let mut ori_blob_mgr = BlobManager::new(digest::Algorithm::Sha256, false);
974980
ori_blob_mgr.set_chunk_dict(dict);
975981

976982
let backend = Arc::new(MockBackend {
@@ -1132,6 +1138,7 @@ mod tests {
11321138
PathBuf::from(tmp_dir.as_path()),
11331139
Default::default(),
11341140
None,
1141+
None,
11351142
false,
11361143
Features::new(),
11371144
false,
@@ -1149,6 +1156,7 @@ mod tests {
11491156
build_ctx.cipher,
11501157
Default::default(),
11511158
None,
1159+
false,
11521160
);
11531161
let blob_ctx2 = BlobContext::new(
11541162
"blob_id2".to_owned(),
@@ -1159,6 +1167,7 @@ mod tests {
11591167
build_ctx.cipher,
11601168
Default::default(),
11611169
None,
1170+
false,
11621171
);
11631172
let blob_ctx3 = BlobContext::new(
11641173
"blob_id3".to_owned(),
@@ -1169,6 +1178,7 @@ mod tests {
11691178
build_ctx.cipher,
11701179
Default::default(),
11711180
None,
1181+
false,
11721182
);
11731183
let blob_ctx4 = BlobContext::new(
11741184
"blob_id4".to_owned(),
@@ -1179,6 +1189,7 @@ mod tests {
11791189
build_ctx.cipher,
11801190
Default::default(),
11811191
None,
1192+
false,
11821193
);
11831194
let blob_ctx5 = BlobContext::new(
11841195
"blob_id5".to_owned(),
@@ -1189,6 +1200,7 @@ mod tests {
11891200
build_ctx.cipher,
11901201
Default::default(),
11911202
None,
1203+
false,
11921204
);
11931205
compactor.ori_blob_mgr.add_blob(blob_ctx1);
11941206
compactor.ori_blob_mgr.add_blob(blob_ctx2);
@@ -1230,6 +1242,7 @@ mod tests {
12301242
PathBuf::from(tmp_dir.as_path()),
12311243
Default::default(),
12321244
None,
1245+
None,
12331246
false,
12341247
Features::new(),
12351248
false,
@@ -1244,6 +1257,7 @@ mod tests {
12441257
build_ctx.cipher,
12451258
Default::default(),
12461259
None,
1260+
false,
12471261
);
12481262
blob_ctx1.compressed_blob_size = 2;
12491263
let mut blob_ctx2 = BlobContext::new(
@@ -1255,6 +1269,7 @@ mod tests {
12551269
build_ctx.cipher,
12561270
Default::default(),
12571271
None,
1272+
false,
12581273
);
12591274
blob_ctx2.compressed_blob_size = 0;
12601275
let blob_ctx3 = BlobContext::new(
@@ -1266,6 +1281,7 @@ mod tests {
12661281
build_ctx.cipher,
12671282
Default::default(),
12681283
None,
1284+
false,
12691285
);
12701286
let blob_ctx4 = BlobContext::new(
12711287
"blob_id4".to_owned(),
@@ -1276,6 +1292,7 @@ mod tests {
12761292
build_ctx.cipher,
12771293
Default::default(),
12781294
None,
1295+
false,
12791296
);
12801297
let blob_ctx5 = BlobContext::new(
12811298
"blob_id5".to_owned(),
@@ -1286,6 +1303,7 @@ mod tests {
12861303
build_ctx.cipher,
12871304
Default::default(),
12881305
None,
1306+
false,
12891307
);
12901308
compactor.ori_blob_mgr.add_blob(blob_ctx1);
12911309
compactor.ori_blob_mgr.add_blob(blob_ctx2);

builder/src/core/bootstrap.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ impl Bootstrap {
7575
let digest = RafsDigest::from_buf(&bootstrap_data, digest::Algorithm::Sha256);
7676
let name = digest.to_string();
7777
bootstrap_ctx.writer.finalize(Some(name.clone()))?;
78-
*bootstrap_storage = Some(ArtifactStorage::SingleFile(p.join(name)));
78+
let mut path = p.0.join(name);
79+
path.set_extension(&p.1);
80+
*bootstrap_storage = Some(ArtifactStorage::SingleFile(path));
7981
Ok(())
8082
} else {
8183
bootstrap_ctx.writer.finalize(Some(String::default()))

builder/src/core/chunk_dict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use nydus_utils::digest::{self, RafsDigest};
1919
use crate::Tree;
2020

2121
#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
22-
pub struct DigestWithBlobIndex(pub RafsDigest, pub u32);
22+
pub struct DigestWithBlobIndex(pub RafsDigest, pub u32, pub Option<u32>);
2323

2424
/// Trait to manage chunk cache for chunk deduplication.
2525
pub trait ChunkDict: Sync + Send + 'static {

0 commit comments

Comments
 (0)