-
Notifications
You must be signed in to change notification settings - Fork 51
Feat: implement the Ancillary sub builder for Incremental Cardano DB #2180
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1ef5dce
feat: implement `AncillaryArtifactBuilder` sub-builder
dlachaume 4fec95b
feat: add the `AncillaryArtifactBuilder` dependency to the cardano da…
dlachaume 156cee0
refactor: extract `CardanoDatabaseArtifactBuilder` creation in the ag…
dlachaume 9501035
refactor: enhance namings in the ancillary module
dlachaume 7db78d6
refactor: add documentation, renaming and test enhancement
dlachaume fe1f710
fix: remove the use of the ancillary builder in `CardanoDatabaseArtif…
dlachaume 9d8d639
test: ensure upload with `LocalUploader` error if the provided path i…
dlachaume 5f20bd7
fix: ensure that the snapshot directory and the cardano database arti…
dlachaume 32d1ef4
chore: upgrade crate versions
dlachaume 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 hidden or 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
This file contains hidden or 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
110 changes: 110 additions & 0 deletions
110
mithril-aggregator/src/artifact_builder/cardano_database_artifacts/ancillary.rs
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| #![allow(dead_code)] | ||
| use async_trait::async_trait; | ||
| use std::{path::Path, sync::Arc}; | ||
|
|
||
| use mithril_common::{entities::AncillaryLocation, StdResult}; | ||
|
|
||
| use crate::{FileUploader, LocalUploader}; | ||
|
|
||
| /// The [AncillaryFileUploader] trait allows identifying uploaders that return locations for ancillary archive files. | ||
| #[cfg_attr(test, mockall::automock)] | ||
| #[async_trait] | ||
| pub trait AncillaryFileUploader: Send + Sync { | ||
| /// Uploads the archive at the given filepath and returns the location of the uploaded file. | ||
| async fn upload(&self, filepath: &Path) -> StdResult<AncillaryLocation>; | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl AncillaryFileUploader for LocalUploader { | ||
| async fn upload(&self, filepath: &Path) -> StdResult<AncillaryLocation> { | ||
| let uri = FileUploader::upload(self, filepath).await?.into(); | ||
|
|
||
| Ok(AncillaryLocation::CloudStorage { uri }) | ||
| } | ||
| } | ||
|
|
||
| /// The [AncillaryArtifactBuilder] creates an ancillary archive from the cardano database directory (including ledger and volatile directories). | ||
| /// The archive is uploaded with the provided uploaders. | ||
| pub struct AncillaryArtifactBuilder { | ||
| uploaders: Vec<Arc<dyn AncillaryFileUploader>>, | ||
| } | ||
|
|
||
| impl AncillaryArtifactBuilder { | ||
| pub fn new(uploaders: Vec<Arc<dyn AncillaryFileUploader>>) -> Self { | ||
| Self { uploaders } | ||
| } | ||
|
|
||
| pub async fn upload_archive(&self, db_directory: &Path) -> StdResult<Vec<AncillaryLocation>> { | ||
| let mut locations = Vec::new(); | ||
| for uploader in &self.uploaders { | ||
| // TODO: Temporary preparation work, `db_directory` is used as the ancillary archive path for now. | ||
| let location = uploader.upload(db_directory).await?; | ||
| locations.push(location); | ||
| } | ||
|
|
||
| Ok(locations) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use mockall::predicate::eq; | ||
|
|
||
| use super::*; | ||
|
|
||
| #[tokio::test] | ||
| async fn upload_archive_should_return_empty_locations_with_no_uploader() { | ||
| let builder = AncillaryArtifactBuilder::new(vec![]); | ||
|
|
||
| let locations = builder.upload_archive(Path::new("whatever")).await.unwrap(); | ||
|
|
||
| assert!(locations.is_empty()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn upload_archive_should_return_all_uploaders_returned_locations() { | ||
| let mut first_uploader = MockAncillaryFileUploader::new(); | ||
| first_uploader | ||
| .expect_upload() | ||
| .with(eq(Path::new("archive_path"))) | ||
| .times(1) | ||
| .return_once(|_| { | ||
| Ok(AncillaryLocation::CloudStorage { | ||
| uri: "an_uri".to_string(), | ||
| }) | ||
| }); | ||
|
|
||
| let mut second_uploader = MockAncillaryFileUploader::new(); | ||
| second_uploader | ||
| .expect_upload() | ||
| .with(eq(Path::new("archive_path"))) | ||
| .times(1) | ||
| .return_once(|_| { | ||
| Ok(AncillaryLocation::CloudStorage { | ||
| uri: "another_uri".to_string(), | ||
| }) | ||
| }); | ||
|
|
||
| let uploaders: Vec<Arc<dyn AncillaryFileUploader>> = | ||
| vec![Arc::new(first_uploader), Arc::new(second_uploader)]; | ||
|
|
||
| let builder = AncillaryArtifactBuilder::new(uploaders); | ||
|
|
||
| let locations = builder | ||
| .upload_archive(Path::new("archive_path")) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| assert_eq!( | ||
| locations, | ||
| vec![ | ||
| AncillaryLocation::CloudStorage { | ||
| uri: "an_uri".to_string() | ||
| }, | ||
| AncillaryLocation::CloudStorage { | ||
| uri: "another_uri".to_string() | ||
| } | ||
| ] | ||
| ); | ||
| } | ||
| } |
4 changes: 4 additions & 0 deletions
4
mithril-aggregator/src/artifact_builder/cardano_database_artifacts/mod.rs
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| //! The module is responsible for creating and uploading the archives of the Cardano database artifacts. | ||
| mod ancillary; | ||
|
|
||
| pub use ancillary::*; |
This file contains hidden or 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
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.