-
Notifications
You must be signed in to change notification settings - Fork 49
chore: Add build-indexes command #823
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| use std::{sync::Arc}; | ||
|
|
||
| use dolos_core::config::RootConfig; | ||
| use itertools::Itertools; | ||
| use miette::{Context, IntoDiagnostic}; | ||
|
|
||
| use dolos::prelude::*; | ||
|
|
||
| use crate::feedback::Feedback; | ||
|
|
||
| #[derive(Debug, clap::Args)] | ||
| pub struct Args { | ||
| #[arg(short, long, default_value_t = 500)] | ||
| pub chunk: usize, | ||
| } | ||
|
|
||
| #[tokio::main] | ||
| pub async fn run(config: &RootConfig, args: &Args, feedback: &Feedback) -> miette::Result<()> { | ||
| //crate::common::setup_tracing(&config.logging)?; | ||
|
|
||
| let progress = feedback.slot_progress_bar(); | ||
| progress.set_message("building indexes"); | ||
|
|
||
| let domain = crate::common::setup_domain(config).await?; | ||
|
|
||
| progress.set_length(domain.state.amount_of_utxos().into_diagnostic().context("getting amount of utxos")?); | ||
|
|
||
| let remaining = domain | ||
| .state.iter_utxos() | ||
| .into_diagnostic() | ||
| .context("iterating over utxos")?; | ||
|
|
||
| for chunk in remaining.chunks(args.chunk).into_iter() { | ||
| let produced_utxo = chunk.into_iter().map(|x| { | ||
| let ( k, v ) = x.into_diagnostic().context("decoding utxoset")?; | ||
| Ok((k, Arc::new(v))) | ||
| }).collect::<miette::Result<_>>()?; | ||
| let utxoset = UtxoSetDelta {produced_utxo, ..Default::default()}; | ||
|
|
||
| let writer = domain.state.start_writer().into_diagnostic().context("starting writer")?; | ||
| writer.index_utxoset(&utxoset).into_diagnostic().context("indexing")?; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| progress.inc(args.chunk as u64); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Progress increment may overcount on the last chunk. The progress increments by 🔎 Proposed fixTrack the actual chunk size: for chunk in remaining.chunks(args.chunk).into_iter() {
- let produced_utxo = chunk.into_iter().map(|x| {
+ let chunk_items: Vec<_> = chunk.collect();
+ let chunk_len = chunk_items.len();
+ let produced_utxo = chunk_items.into_iter().map(|x| {
let ( k, v ) = x.into_diagnostic().context("decoding utxoset")?;
Ok((k, Arc::new(v)))
}).collect::<miette::Result<_>>()?;
let utxoset = UtxoSetDelta {produced_utxo, ..Default::default()};
let writer = domain.state.start_writer().into_diagnostic().context("starting writer")?;
writer.index_utxoset(&utxoset).into_diagnostic().context("indexing")?;
+ writer.commit().into_diagnostic().context("committing indexes")?;
- progress.inc(args.chunk as u64);
+ progress.inc(chunk_len as u64);
}
🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ use dolos_core::config::RootConfig; | |||||||||
|
|
||||||||||
| use crate::feedback::Feedback; | ||||||||||
|
|
||||||||||
| mod build_indexes; | ||||||||||
| mod catchup_stores; | ||||||||||
| mod reset_wal; | ||||||||||
| mod rollback; | ||||||||||
|
|
@@ -32,6 +33,9 @@ pub enum Command { | |||||||||
|
|
||||||||||
| /// manually updates an entity in the state | ||||||||||
| UpdateEntity(update_entity::Args), | ||||||||||
|
|
||||||||||
| /// catch up store data from WAL records | ||||||||||
| BuildIndexes(build_indexes::Args), | ||||||||||
|
Comment on lines
+37
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the doc comment. The doc comment "catch up store data from WAL records" is incorrect and appears to be copy-pasted from the 🔎 Suggested fix- /// catch up store data from WAL records
+ /// builds UTXO indexes in batches
BuildIndexes(build_indexes::Args),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| } | ||||||||||
|
|
||||||||||
| #[derive(Debug, Parser)] | ||||||||||
|
|
@@ -42,6 +46,7 @@ pub struct Args { | |||||||||
|
|
||||||||||
| pub fn run(config: &RootConfig, args: &Args, feedback: &Feedback) -> miette::Result<()> { | ||||||||||
| match &args.command { | ||||||||||
| Command::BuildIndexes(x) => build_indexes::run(config, x, feedback)?, | ||||||||||
| Command::CatchupStores(x) => catchup_stores::run(config, x, feedback)?, | ||||||||||
| Command::ResetWal(x) => reset_wal::run(config, x, feedback)?, | ||||||||||
| Command::WalIntegrity(x) => wal_integrity::run(config, x)?, | ||||||||||
|
|
||||||||||
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.
Remove
#[tokio::main]attribute from non-main function.The
#[tokio::main]attribute is designed to transform themain()entry point to set up a Tokio runtime. Using it on a regular async function that is called by the actual main function is incorrect and may cause compilation errors or unexpected behavior. Since this function is called from the CLI dispatcher (which already has a runtime), this attribute should be removed.🔎 Proposed fix
-#[tokio::main] pub async fn run(config: &RootConfig, args: &Args, feedback: &Feedback) -> miette::Result<()> {📝 Committable suggestion
🤖 Prompt for AI Agents