Skip to content

Commit

Permalink
feat: make the ancillary archive name more precise
Browse files Browse the repository at this point in the history
  • Loading branch information
dlachaume committed Dec 24, 2024
1 parent 8133fd3 commit 66638f7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
7 changes: 3 additions & 4 deletions mithril-aggregator/src/artifact_builder/cardano_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ impl ArtifactBuilder<CardanoDbBeacon, CardanoDatabaseSnapshot> for CardanoDataba
})?;
let total_db_size_uncompressed = compute_uncompressed_database_size(&self.db_directory)?;

let ancillary_locations = self
.ancillary_builder
.upload(beacon.immutable_file_number)
.await?;
let ancillary_locations = self.ancillary_builder.upload(&beacon).await?;

let locations = ArtifactsLocations {
ancillary: ancillary_locations,
Expand Down Expand Up @@ -118,6 +115,7 @@ mod tests {
digesters::DummyCardanoDbBuilder,
entities::{AncillaryLocation, ProtocolMessage, ProtocolMessagePartKey},
test_utils::{fake_data, TempDir},
CardanoNetwork,
};

use crate::{
Expand Down Expand Up @@ -183,6 +181,7 @@ mod tests {
Arc::new(AncillaryArtifactBuilder::new(
vec![Arc::new(ancillary_uploader)],
Arc::new(DumbSnapshotter::new()),
CardanoNetwork::DevNet(123),
CompressionAlgorithm::Gzip,
TestLogger::stdout(),
)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use slog::{debug, Logger};

use mithril_common::{
digesters::{IMMUTABLE_DIR, LEDGER_DIR, VOLATILE_DIR},
entities::{AncillaryLocation, CompressionAlgorithm, ImmutableFileNumber},
entities::{AncillaryLocation, CardanoDbBeacon, CompressionAlgorithm},
logging::LoggerExtensions,
StdResult,
CardanoNetwork, StdResult,
};

use crate::{snapshotter::OngoingSnapshot, FileUploader, LocalUploader, Snapshotter};
Expand All @@ -38,6 +38,7 @@ impl AncillaryFileUploader for LocalUploader {
pub struct AncillaryArtifactBuilder {
uploaders: Vec<Arc<dyn AncillaryFileUploader>>,
snapshotter: Arc<dyn Snapshotter>,
cardano_network: CardanoNetwork,
compression_algorithm: CompressionAlgorithm,
logger: Logger,
}
Expand All @@ -47,19 +48,21 @@ impl AncillaryArtifactBuilder {
pub fn new(
uploaders: Vec<Arc<dyn AncillaryFileUploader>>,
snapshotter: Arc<dyn Snapshotter>,
cardano_network: CardanoNetwork,
compression_algorithm: CompressionAlgorithm,
logger: Logger,
) -> Self {
Self {
uploaders,
logger: logger.new_with_component_name::<Self>(),
cardano_network,
compression_algorithm,
snapshotter,
}
}

pub async fn upload(&self, immutable_file_number: u64) -> StdResult<Vec<AncillaryLocation>> {
let snapshot = self.create_ancillary_archive(immutable_file_number)?;
pub async fn upload(&self, beacon: &CardanoDbBeacon) -> StdResult<Vec<AncillaryLocation>> {
let snapshot = self.create_ancillary_archive(beacon)?;

let locations = self
.upload_ancillary_archive(snapshot.get_file_path())
Expand All @@ -86,19 +89,21 @@ impl AncillaryArtifactBuilder {
}

/// Creates an archive for the Cardano database ancillary files for the given immutable file number.
fn create_ancillary_archive(
&self,
immutable_file_number: ImmutableFileNumber,
) -> StdResult<OngoingSnapshot> {
fn create_ancillary_archive(&self, beacon: &CardanoDbBeacon) -> StdResult<OngoingSnapshot> {
debug!(
self.logger,
"Creating ancillary archive for immutable file number: {}", immutable_file_number
"Creating ancillary archive for immutable file number: {}",
beacon.immutable_file_number
);

let paths_to_include = Self::get_files_and_directories_to_snapshot(immutable_file_number);
let paths_to_include =
Self::get_files_and_directories_to_snapshot(beacon.immutable_file_number);

let archive_name = format!(
"ancillary.{}",
"{}-e{}-i{}.ancillary.{}",
self.cardano_network,
*beacon.epoch,
beacon.immutable_file_number,
self.compression_algorithm.tar_file_extension()
);

Expand All @@ -108,7 +113,7 @@ impl AncillaryArtifactBuilder {
.with_context(|| {
format!(
"Failed to create snapshot for immutable file number: {}",
immutable_file_number
beacon.immutable_file_number
)
})?;

Expand Down Expand Up @@ -160,6 +165,7 @@ mod tests {
let builder = AncillaryArtifactBuilder::new(
vec![],
Arc::new(DumbSnapshotter::new()),
CardanoNetwork::DevNet(123),
CompressionAlgorithm::Gzip,
TestLogger::stdout(),
);
Expand Down Expand Up @@ -202,6 +208,7 @@ mod tests {
let builder = AncillaryArtifactBuilder::new(
uploaders,
Arc::new(DumbSnapshotter::new()),
CardanoNetwork::DevNet(123),
CompressionAlgorithm::Gzip,
TestLogger::stdout(),
);
Expand Down Expand Up @@ -248,11 +255,14 @@ mod tests {
let builder = AncillaryArtifactBuilder::new(
vec![],
Arc::new(snapshotter),
CardanoNetwork::DevNet(123),
CompressionAlgorithm::Gzip,
TestLogger::stdout(),
);

let snapshot = builder.create_ancillary_archive(1).unwrap();
let snapshot = builder
.create_ancillary_archive(&CardanoDbBeacon::new(99, 1))
.unwrap();

let mut archive = {
let file_tar_gz = File::open(snapshot.get_file_path()).unwrap();
Expand Down Expand Up @@ -306,12 +316,13 @@ mod tests {
let builder = AncillaryArtifactBuilder::new(
vec![Arc::new(uploader)],
Arc::new(snapshotter),
CardanoNetwork::DevNet(123),
CompressionAlgorithm::Gzip,
TestLogger::stdout(),
);

builder
.upload(1)
.upload(&CardanoDbBeacon::new(99, 1))
.await
.expect_err("Should return an error when archive creation fails");
}
Expand Down
1 change: 1 addition & 0 deletions mithril-aggregator/src/dependency_injection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,7 @@ impl DependenciesBuilder {
let ancillary_builder = Arc::new(AncillaryArtifactBuilder::new(
vec![Arc::new(local_uploader)],
snapshotter,
self.configuration.get_network()?,
self.configuration.snapshot_compression_algorithm,
logger.clone(),
));
Expand Down

0 comments on commit 66638f7

Please sign in to comment.