-
Notifications
You must be signed in to change notification settings - Fork 6
feat(worker-datasets-raw): add redump command to re-extract block ranges #1815
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
Open
Theodus
wants to merge
2
commits into
main
Choose a base branch
from
theodus/redump
base: main
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.
+1,333
−3
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| //! Dataset redump command. | ||
| //! | ||
| //! Submits a request to re-extract blocks in a given range for a dataset. | ||
| //! | ||
| //! This is useful when `ampctl verify` identifies corrupted data and the operator | ||
| //! needs to re-extract specific block ranges. | ||
| //! | ||
| //! # Dataset Reference Format | ||
| //! | ||
| //! `namespace/name@version` (e.g., `graph/eth_mainnet@1.0.0`) | ||
| //! | ||
| //! # Configuration | ||
| //! | ||
| //! - Admin URL: `--admin-url` flag or `AMP_ADMIN_URL` env var (default: `http://localhost:1610`) | ||
| //! - Logging: `AMP_LOG` env var (`error`, `warn`, `info`, `debug`, `trace`) | ||
|
|
||
| use datasets_common::reference::Reference; | ||
|
|
||
| use crate::{args::GlobalArgs, client::datasets::RedumpResponse}; | ||
|
|
||
| /// Command-line arguments for the `dataset redump` command. | ||
| #[derive(Debug, clap::Args)] | ||
| pub struct Args { | ||
| #[command(flatten)] | ||
| pub global: GlobalArgs, | ||
|
|
||
| /// The dataset reference in format: namespace/name@version | ||
| /// | ||
| /// Examples: my_namespace/my_dataset@1.0.0, my_namespace/my_dataset@latest | ||
| #[arg(value_name = "REFERENCE", required = true, value_parser = clap::value_parser!(Reference))] | ||
| pub dataset_ref: Reference, | ||
|
|
||
| /// First block of the range to re-extract (inclusive) | ||
| #[arg(long, value_name = "BLOCK_NUMBER")] | ||
| pub start_block: u64, | ||
|
|
||
| /// Last block of the range to re-extract (inclusive) | ||
| #[arg(long, value_name = "BLOCK_NUMBER")] | ||
| pub end_block: u64, | ||
| } | ||
|
|
||
| /// Result of a dataset redump operation. | ||
| #[derive(serde::Serialize)] | ||
| struct RedumpResult { | ||
| request_id: i64, | ||
| job_id: Option<i64>, | ||
| } | ||
|
|
||
| impl std::fmt::Display for RedumpResult { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
| writeln!( | ||
| f, | ||
| "{} Redump request submitted (request_id: {})", | ||
| console::style("✓").green().bold(), | ||
| self.request_id, | ||
| )?; | ||
| match self.job_id { | ||
| Some(job_id) => writeln!( | ||
| f, | ||
| "{} New dump job scheduled (job_id: {})", | ||
| console::style("→").cyan(), | ||
| job_id, | ||
| )?, | ||
| None => writeln!( | ||
| f, | ||
| "{} Active dump job already running; it will pick up this request", | ||
| console::style("→").cyan(), | ||
| )?, | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| /// Submit a redump request for a dataset block range. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`Error`] for invalid paths/URLs, API errors (400/404/409/500), or network failures. | ||
| #[tracing::instrument(skip_all, fields(admin_url = %global.admin_url, %dataset_ref, start_block, end_block))] | ||
| pub async fn run( | ||
| Args { | ||
| global, | ||
| dataset_ref, | ||
| start_block, | ||
| end_block, | ||
| }: Args, | ||
| ) -> Result<(), Error> { | ||
| tracing::debug!(%dataset_ref, start_block, end_block, "Submitting redump request"); | ||
|
|
||
| let response = submit_redump(&global, &dataset_ref, start_block, end_block).await?; | ||
| let result = RedumpResult { | ||
| request_id: response.request_id, | ||
| job_id: response.job_id, | ||
| }; | ||
| global.print(&result).map_err(Error::JsonSerialization)?; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Submit a redump request via the admin API. | ||
| #[tracing::instrument(skip_all, fields(%dataset_ref, start_block, end_block))] | ||
| async fn submit_redump( | ||
| global: &GlobalArgs, | ||
| dataset_ref: &Reference, | ||
| start_block: u64, | ||
| end_block: u64, | ||
| ) -> Result<RedumpResponse, Error> { | ||
| let client = global.build_client().map_err(Error::ClientBuild)?; | ||
| let response = client | ||
| .datasets() | ||
| .redump(dataset_ref, start_block, end_block) | ||
| .await | ||
| .map_err(Error::Redump)?; | ||
|
|
||
| Ok(response) | ||
| } | ||
|
|
||
| /// Errors for dataset redump operations. | ||
| #[derive(Debug, thiserror::Error)] | ||
| pub enum Error { | ||
| /// Failed to build client | ||
| #[error("failed to build admin API client")] | ||
| ClientBuild(#[source] crate::args::BuildClientError), | ||
|
|
||
| /// Redump error from the client | ||
| #[error("redump failed")] | ||
| Redump(#[source] crate::client::datasets::RedumpError), | ||
|
|
||
| /// Failed to serialize result to JSON | ||
| #[error("failed to serialize result to JSON")] | ||
| JsonSerialization(#[source] serde_json::Error), | ||
| } | ||
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.
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.
Can we place the
runfn to top? (After Args)