Skip to content

Commit ef2db14

Browse files
committed
chore: adjusments following PR reviews
- make the dependencies builder construct the full FileArchiver verification dir path instead of completing it in the archiver itself - removed `snapshot_subset` from the Snapshotter trait: as it's supersede by the new methods that don't need node db knowledge - removed `FileArchiver::set_verification_temp_dir` as it's never needed since this directory is always passed in constructors. - adjusted some naming (`snapshot` -> `archive` in `file_archiver` module)
1 parent e65c85c commit ef2db14

File tree

8 files changed

+43
-128
lines changed

8 files changed

+43
-128
lines changed

mithril-aggregator/src/artifact_builder/cardano_database_artifacts/digest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ impl DigestArtifactBuilder {
174174

175175
let locations = self.upload_digest_file(&digest_archive).await;
176176

177-
self.cleanup_uploaded_artefacts(&digest_path, &digest_archive)?;
177+
self.cleanup_uploaded_artifacts(&digest_path, &digest_archive)?;
178178

179179
Ok(DigestUpload {
180180
locations: locations?,
181181
size: digest_archive.get_uncompressed_size(),
182182
})
183183
}
184184

185-
fn cleanup_uploaded_artefacts(
185+
fn cleanup_uploaded_artifacts(
186186
&self,
187187
digest_path: &PathBuf,
188188
digest_archive: &FileArchive,

mithril-aggregator/src/artifact_builder/cardano_database_artifacts/immutable.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,6 @@ mod tests {
677677
snapshotter
678678
.expect_compression_algorithm()
679679
.returning(|| CompressionAlgorithm::Gzip);
680-
snapshotter.expect_snapshot_subset().never();
681680

682681
create_fake_file(&work_dir.join("00001.tar.gz"), "00001 content");
683682
create_fake_file(&work_dir.join("00002.tar.gz"), "00002 content");

mithril-aggregator/src/dependency_injection/builder/protocol/artifacts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ impl DependenciesBuilder {
9595
}
9696

9797
async fn build_file_archiver(&mut self) -> Result<Arc<FileArchiver>> {
98-
let archive_verification_directory = std::env::temp_dir();
98+
let archive_verification_directory =
99+
std::env::temp_dir().join("mithril_archiver_verify_archive");
99100
let file_archiver = Arc::new(FileArchiver::new(
100101
self.configuration.zstandard_parameters.unwrap_or_default(),
101102
archive_verification_directory,

mithril-aggregator/src/services/snapshotter/compressed_archive_snapshotter.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,6 @@ impl Snapshotter for CompressedArchiveSnapshotter {
3838
self.snapshot(archive_name_without_extension, appender)
3939
}
4040

41-
fn snapshot_subset(
42-
&self,
43-
archive_name_without_extension: &str,
44-
entries: Vec<PathBuf>,
45-
) -> StdResult<FileArchive> {
46-
if entries.is_empty() {
47-
return Err(anyhow!("Can not create snapshot with empty entries"));
48-
}
49-
50-
let appender = AppenderEntries::new(entries, self.db_directory.clone())?;
51-
self.snapshot(archive_name_without_extension, appender)
52-
}
53-
5441
fn snapshot_ancillary(
5542
&self,
5643
immutable_file_number: ImmutableFileNumber,
@@ -151,16 +138,11 @@ impl CompressedArchiveSnapshotter {
151138
&self,
152139
immutable_file_number: u64,
153140
) -> StdResult<Vec<PathBuf>> {
154-
let mut files_to_snapshot = Vec::with_capacity(4);
155-
156141
let next_immutable_file_number = immutable_file_number + 1;
157-
files_to_snapshot.extend_from_slice(
158-
immutable_trio_names(next_immutable_file_number)
159-
.iter()
160-
.map(|filename| PathBuf::from(IMMUTABLE_DIR).join(filename))
161-
.collect::<Vec<_>>()
162-
.as_slice(),
163-
);
142+
let mut files_to_snapshot: Vec<PathBuf> = immutable_trio_names(next_immutable_file_number)
143+
.into_iter()
144+
.map(|filename| PathBuf::from(IMMUTABLE_DIR).join(filename))
145+
.collect();
164146

165147
let db_ledger_dir = self.db_directory.join(LEDGER_DIR);
166148
let ledger_files = LedgerFile::list_all_in_dir(&db_ledger_dir)?;
@@ -276,7 +258,7 @@ mod tests {
276258
let db_directory = test_dir.join("db");
277259

278260
fs::create_dir(&db_directory).unwrap();
279-
File::create(&db_directory.join("file_to_archive.txt")).unwrap();
261+
File::create(db_directory.join("file_to_archive.txt")).unwrap();
280262

281263
let snapshotter = CompressedArchiveSnapshotter::new(
282264
db_directory,

mithril-aggregator/src/services/snapshotter/interface.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::path::PathBuf;
2-
31
use mithril_common::entities::{CompressionAlgorithm, ImmutableFileNumber};
42
use mithril_common::StdResult;
53

@@ -11,13 +9,6 @@ pub trait Snapshotter: Sync + Send {
119
/// Create a new snapshot with the given filepath.
1210
fn snapshot_all(&self, archive_name_without_extension: &str) -> StdResult<FileArchive>;
1311

14-
/// Create a new snapshot with the given filepath from a subset of directories and files.
15-
fn snapshot_subset(
16-
&self,
17-
archive_name_without_extension: &str,
18-
files: Vec<PathBuf>,
19-
) -> StdResult<FileArchive>;
20-
2112
/// Create a new snapshot of ancillary files.
2213
///
2314
/// Ancillary files include the last, uncompleted, immutable trio and the last ledger file.

mithril-aggregator/src/services/snapshotter/test_doubles.rs

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ impl Snapshotter for DumbSnapshotter {
6060
Ok(snapshot)
6161
}
6262

63-
fn snapshot_subset(
64-
&self,
65-
archive_name_without_extension: &str,
66-
_files: Vec<PathBuf>,
67-
) -> StdResult<FileArchive> {
68-
self.snapshot_all(archive_name_without_extension)
69-
}
70-
7163
fn snapshot_ancillary(
7264
&self,
7365
_immutable_file_number: ImmutableFileNumber,
@@ -133,14 +125,6 @@ impl Snapshotter for FakeSnapshotter {
133125
))
134126
}
135127

136-
fn snapshot_subset(
137-
&self,
138-
archive_name_without_extension: &str,
139-
_files: Vec<PathBuf>,
140-
) -> StdResult<FileArchive> {
141-
self.snapshot_all(archive_name_without_extension)
142-
}
143-
144128
fn snapshot_ancillary(
145129
&self,
146130
_immutable_file_number: ImmutableFileNumber,
@@ -189,9 +173,11 @@ mod tests {
189173
assert_eq!(PathBuf::from("archive.tar.gz"), *snapshot.get_file_path());
190174
assert_eq!(0, snapshot.get_archive_size());
191175

192-
let snapshot = snapshotter
193-
.snapshot_subset("archive", vec![PathBuf::from("whatever")])
194-
.unwrap();
176+
let snapshot = snapshotter.snapshot_ancillary(3, "archive").unwrap();
177+
assert_eq!(PathBuf::from("archive.tar.gz"), *snapshot.get_file_path());
178+
assert_eq!(0, snapshot.get_archive_size());
179+
180+
let snapshot = snapshotter.snapshot_immutable_trio(4, "archive").unwrap();
195181
assert_eq!(PathBuf::from("archive.tar.gz"), *snapshot.get_file_path());
196182
assert_eq!(0, snapshot.get_archive_size());
197183
}
@@ -239,17 +225,6 @@ mod tests {
239225
)
240226
);
241227
}
242-
{
243-
let subset_snapshot = snapshotter
244-
.snapshot_subset("another_whatever", vec![PathBuf::from("subdir")])
245-
.expect("Dumb snapshotter::snapshot_subset should not fail.");
246-
assert_eq!(
247-
Some(subset_snapshot),
248-
snapshotter.get_last_snapshot().expect(
249-
"Dumb snapshotter::get_last_snapshot should not fail when some last snapshot."
250-
)
251-
);
252-
}
253228
}
254229
}
255230

@@ -307,16 +282,6 @@ mod tests {
307282
);
308283
assert!(immutable_snapshot.get_file_path().is_file());
309284
}
310-
{
311-
let subset_snapshot =
312-
fake_snapshotter.snapshot_subset(filename, vec![]).unwrap();
313-
314-
assert_eq!(
315-
subset_snapshot.get_file_path(),
316-
&test_dir.join(filename).with_extension("tar.gz")
317-
);
318-
assert!(subset_snapshot.get_file_path().is_file());
319-
}
320285
}
321286
}
322287
}

mithril-aggregator/src/tools/file_archiver/api.rs

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl FileArchiver {
7474
if temporary_archive_path.exists() {
7575
if let Err(remove_error) = fs::remove_file(&temporary_archive_path) {
7676
warn!(
77-
self.logger, " > Post snapshotter.snapshot failure, could not remove temporary archive";
77+
self.logger, " > Post FileArchiver.archive failure, could not remove temporary archive";
7878
"archive_path" => temporary_archive_path.display(),
7979
"error" => remove_error
8080
);
@@ -206,30 +206,28 @@ impl FileArchiver {
206206
archive.filepath.display()
207207
);
208208

209-
let mut snapshot_file_tar = File::open(&archive.filepath).with_context(|| {
209+
let mut archive_file_tar = File::open(&archive.filepath).with_context(|| {
210210
format!(
211211
"Verify archive error: can not open archive: '{}'",
212212
archive.filepath.display()
213213
)
214214
})?;
215-
snapshot_file_tar.seek(SeekFrom::Start(0))?;
215+
archive_file_tar.seek(SeekFrom::Start(0))?;
216216

217-
let mut snapshot_archive: Archive<Box<dyn Read>> = match archive.compression_algorithm {
217+
let mut tar_archive: Archive<Box<dyn Read>> = match archive.compression_algorithm {
218218
CompressionAlgorithm::Gzip => {
219-
let snapshot_file_tar = GzDecoder::new(snapshot_file_tar);
220-
Archive::new(Box::new(snapshot_file_tar))
219+
let archive_decoder = GzDecoder::new(archive_file_tar);
220+
Archive::new(Box::new(archive_decoder))
221221
}
222222
CompressionAlgorithm::Zstandard => {
223-
let snapshot_file_tar = Decoder::new(snapshot_file_tar)?;
224-
Archive::new(Box::new(snapshot_file_tar))
223+
let archive_decoder = Decoder::new(archive_file_tar)?;
224+
Archive::new(Box::new(archive_decoder))
225225
}
226226
};
227227

228228
let unpack_temp_dir = self
229229
.verification_temp_dir
230-
.join("mithril_archiver_verify_archive")
231230
// Add the archive name to the directory to allow two verifications at the same time
232-
// (useful for tests).
233231
.join(archive.filepath.file_name().ok_or(anyhow!(
234232
"Verify archive error: Could not append archive name to temp directory: archive `{}`",
235233
archive.filepath.display(),
@@ -246,7 +244,7 @@ impl FileArchiver {
246244

247245
let verify_result = {
248246
let mut result = Ok(());
249-
for e in snapshot_archive.entries()? {
247+
for e in tar_archive.entries()? {
250248
match e {
251249
Err(e) => {
252250
result = Err(anyhow!(e).context("Verify archive error: invalid entry"));
@@ -290,13 +288,6 @@ impl FileArchiver {
290288

291289
Ok(())
292290
}
293-
294-
#[cfg(test)]
295-
/// Allow to use a custom temporary directory to avoid conflicts during the snapshot verification.
296-
pub fn set_verification_temp_dir<T: Into<String>>(&mut self, sub_dir: T) {
297-
self.verification_temp_dir =
298-
mithril_common::test_utils::TempDir::create("snapshotter-temp", sub_dir);
299-
}
300291
}
301292

302293
#[cfg(test)]
@@ -305,10 +296,8 @@ mod tests {
305296

306297
use mithril_common::test_utils::assert_equivalent;
307298

308-
use crate::test_tools::TestLogger;
309299
use crate::tools::file_archiver::appender::{AppenderDirAll, AppenderFile};
310300
use crate::tools::file_archiver::test_tools::*;
311-
use crate::ZstandardCompressionParameters;
312301

313302
use super::*;
314303

@@ -344,7 +333,7 @@ mod tests {
344333
fn should_create_a_valid_archive_with_zstandard_compression() {
345334
let test_dir =
346335
get_test_directory("should_create_a_valid_archive_with_zstandard_compression");
347-
let target_archive = test_dir.join("archive.tar.gz");
336+
let target_archive = test_dir.join("archive.tar.zst");
348337
let archived_directory = test_dir.join(create_dir(&test_dir, "archived_directory"));
349338
create_file(&archived_directory, "file_to_archive.txt");
350339

@@ -437,39 +426,27 @@ mod tests {
437426
target_directory: test_dir.clone(),
438427
compression_algorithm: CompressionAlgorithm::Gzip,
439428
};
440-
let first_snapshot = file_archiver
429+
let first_archive = file_archiver
441430
.archive(
442431
archive_params.clone(),
443432
AppenderDirAll::new(archived_directory.clone()),
444433
)
445434
.unwrap();
446-
let first_snapshot_size = first_snapshot.get_archive_size();
435+
let first_archive_size = first_archive.get_archive_size();
447436

448437
create_file(&archived_directory, "another_file_to_archive.txt");
449438

450-
let second_snapshot = file_archiver
439+
let second_archive = file_archiver
451440
.archive(archive_params, AppenderDirAll::new(archived_directory))
452441
.unwrap();
453-
let second_snapshot_size = second_snapshot.get_archive_size();
442+
let second_archive_size = second_archive.get_archive_size();
454443

455-
assert_ne!(first_snapshot_size, second_snapshot_size);
444+
assert_ne!(first_archive_size, second_archive_size);
456445

457-
let unpack_path = second_snapshot.unpack_gzip(&test_dir);
446+
let unpack_path = second_archive.unpack_gzip(&test_dir);
458447
assert!(unpack_path.join("another_file_to_archive.txt").exists());
459448
}
460449

461-
#[test]
462-
fn can_set_verification_temp_dir_with_str_or_string() {
463-
let mut file_archiver = FileArchiver::new(
464-
ZstandardCompressionParameters::default(),
465-
PathBuf::new(),
466-
TestLogger::stdout(),
467-
);
468-
469-
file_archiver.set_verification_temp_dir("sub_dir");
470-
file_archiver.set_verification_temp_dir("sub_dir".to_string());
471-
}
472-
473450
#[test]
474451
fn compute_size_of_uncompressed_data_and_archive() {
475452
let test_dir = get_test_directory("compute_size_of_uncompressed_data_and_archive");
@@ -485,15 +462,15 @@ mod tests {
485462
target_directory: test_dir.clone(),
486463
compression_algorithm: CompressionAlgorithm::Gzip,
487464
};
488-
let snapshot = file_archiver
465+
let archive = file_archiver
489466
.archive(
490467
archive_params.clone(),
491468
AppenderFile::append_at_archive_root(file_path.clone()).unwrap(),
492469
)
493470
.unwrap();
494471

495-
let expected_archive_size = file_size::compute_size_of_path(&snapshot.filepath).unwrap();
496-
assert_eq!(expected_archive_size, snapshot.get_archive_size(),);
497-
assert_eq!(777, snapshot.get_uncompressed_size());
472+
let expected_archive_size = file_size::compute_size_of_path(&archive.filepath).unwrap();
473+
assert_eq!(expected_archive_size, archive.get_archive_size(),);
474+
assert_eq!(777, archive.get_uncompressed_size());
498475
}
499476
}

0 commit comments

Comments
 (0)