Skip to content

Commit 5f18e04

Browse files
committed
indexer-alt: pass ingestion client over CLI
## Description Move the source of checkpoint data (remote store or local path) into its own struct that is parsed using clap, instead of serde. This is to cater to the case where the same indexer configuration might be used to index different networks (mainnet, testnet, devnet, etc). ## Test plan Run the indexer against a variety of configs: ``` sui$ cargo run -p sui-indexer-alt --release -- \ indexer --last-checkpoint 10000 \ --remote-store-url https://checkpoints.mainnet.sui.io \ --config $CONFIG ``` Where config is a file that contains one of the following: ``` [pipeline.kv_objects] [pipeline.kv_transactions] ``` ``` [consistency] consistent-range = 1000 [pipeline.sum_obj_types] ``` ``` [committer] collect-interval-ms = 1000 [pipeline.tx_calls] [pipeline.tx_affected_objects] collect-interval-ms = 5000 ```
1 parent 3f724bf commit 5f18e04

File tree

5 files changed

+55
-16
lines changed

5 files changed

+55
-16
lines changed

crates/sui-indexer-alt/src/args.rs

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::path::PathBuf;
66
#[cfg(feature = "benchmark")]
77
use crate::benchmark::BenchmarkArgs;
88
use crate::db::DbArgs;
9+
use crate::ingestion::IngestionArgs;
910
use crate::IndexerArgs;
1011
use clap::Subcommand;
1112

@@ -23,6 +24,9 @@ pub struct Args {
2324
pub enum Command {
2425
/// Run the indexer.
2526
Indexer {
27+
#[command(flatten)]
28+
ingestion_args: IngestionArgs,
29+
2630
#[command(flatten)]
2731
indexer_args: IndexerArgs,
2832

crates/sui-indexer-alt/src/benchmark.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{path::PathBuf, time::Instant};
55

66
use crate::{
77
db::{reset_database, DbArgs},
8+
ingestion::IngestionArgs,
89
start_indexer, IndexerArgs, IndexerConfig,
910
};
1011
use sui_synthetic_ingestion::synthetic_ingestion::read_ingestion_data;
@@ -19,7 +20,7 @@ pub struct BenchmarkArgs {
1920
pub async fn run_benchmark(
2021
db_args: DbArgs,
2122
benchmark_args: BenchmarkArgs,
22-
mut indexer_config: IndexerConfig,
23+
indexer_config: IndexerConfig,
2324
) -> anyhow::Result<()> {
2425
let BenchmarkArgs { ingestion_path } = benchmark_args;
2526

@@ -36,14 +37,17 @@ pub async fn run_benchmark(
3637
..Default::default()
3738
};
3839

39-
indexer_config.ingestion.remote_store_url = None;
40-
indexer_config.ingestion.local_ingestion_path = Some(ingestion_path);
40+
let ingestion_args = IngestionArgs {
41+
remote_store_url: None,
42+
local_ingestion_path: Some(ingestion_path.clone()),
43+
};
4144

4245
let cur_time = Instant::now();
4346

4447
start_indexer(
4548
db_args,
4649
indexer_args,
50+
ingestion_args,
4751
indexer_config,
4852
false, /* with_genesis */
4953
)

crates/sui-indexer-alt/src/ingestion/mod.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,21 @@ mod remote_client;
2929
#[cfg(test)]
3030
mod test_utils;
3131

32-
#[DefaultConfig]
33-
#[derive(Clone)]
34-
pub struct IngestionConfig {
32+
#[derive(clap::Args, Clone, Debug)]
33+
pub struct IngestionArgs {
3534
/// Remote Store to fetch checkpoints from.
35+
#[clap(long, required = true, group = "source")]
3636
pub remote_store_url: Option<Url>,
3737

3838
/// Path to the local ingestion directory.
3939
/// If both remote_store_url and local_ingestion_path are provided, remote_store_url will be used.
40+
#[clap(long, required = true, group = "source")]
4041
pub local_ingestion_path: Option<PathBuf>,
42+
}
4143

44+
#[DefaultConfig]
45+
#[derive(Clone)]
46+
pub struct IngestionConfig {
4247
/// Maximum size of checkpoint backlog across all workers downstream of the ingestion service.
4348
pub checkpoint_buffer_size: usize,
4449

@@ -66,18 +71,20 @@ impl IngestionConfig {
6671

6772
impl IngestionService {
6873
pub fn new(
74+
args: IngestionArgs,
6975
config: IngestionConfig,
7076
metrics: Arc<IndexerMetrics>,
7177
cancel: CancellationToken,
7278
) -> Result<Self> {
7379
// TODO: Potentially support a hybrid mode where we can fetch from both local and remote.
74-
let client = if let Some(url) = config.remote_store_url.as_ref() {
80+
let client = if let Some(url) = args.remote_store_url.as_ref() {
7581
IngestionClient::new_remote(url.clone(), metrics.clone())?
76-
} else if let Some(path) = config.local_ingestion_path.as_ref() {
82+
} else if let Some(path) = args.local_ingestion_path.as_ref() {
7783
IngestionClient::new_local(path.clone(), metrics.clone())
7884
} else {
7985
panic!("Either remote_store_url or local_ingestion_path must be provided");
8086
};
87+
8188
let subscribers = Vec::new();
8289
let (ingest_hi_tx, ingest_hi_rx) = mpsc::unbounded_channel();
8390
Ok(Self {
@@ -166,8 +173,6 @@ impl IngestionService {
166173
impl Default for IngestionConfig {
167174
fn default() -> Self {
168175
Self {
169-
remote_store_url: None,
170-
local_ingestion_path: None,
171176
checkpoint_buffer_size: 5000,
172177
ingest_concurrency: 200,
173178
retry_interval_ms: 200,
@@ -196,8 +201,11 @@ mod tests {
196201
cancel: CancellationToken,
197202
) -> IngestionService {
198203
IngestionService::new(
199-
IngestionConfig {
204+
IngestionArgs {
200205
remote_store_url: Some(Url::parse(&uri).unwrap()),
206+
local_ingestion_path: None,
207+
},
208+
IngestionConfig {
201209
checkpoint_buffer_size,
202210
ingest_concurrency,
203211
..Default::default()

crates/sui-indexer-alt/src/lib.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use handlers::{
1717
tx_balance_changes::TxBalanceChanges, tx_calls::TxCalls, tx_digests::TxDigests,
1818
tx_kinds::TxKinds, wal_coin_balances::WalCoinBalances, wal_obj_types::WalObjTypes,
1919
};
20-
use ingestion::{client::IngestionClient, IngestionConfig, IngestionService};
20+
use ingestion::{client::IngestionClient, IngestionArgs, IngestionConfig, IngestionService};
2121
use metrics::{IndexerMetrics, MetricsService};
2222
use models::watermarks::CommitterWatermark;
2323
use pipeline::{
@@ -110,6 +110,7 @@ impl Indexer {
110110
pub async fn new(
111111
db_args: DbArgs,
112112
indexer_args: IndexerArgs,
113+
ingestion_args: IngestionArgs,
113114
ingestion_config: IngestionConfig,
114115
cancel: CancellationToken,
115116
) -> Result<Self> {
@@ -131,8 +132,13 @@ impl Indexer {
131132

132133
let (metrics, metrics_service) =
133134
MetricsService::new(metrics_address, db.clone(), cancel.clone())?;
134-
let ingestion_service =
135-
IngestionService::new(ingestion_config, metrics.clone(), cancel.clone())?;
135+
136+
let ingestion_service = IngestionService::new(
137+
ingestion_args,
138+
ingestion_config,
139+
metrics.clone(),
140+
cancel.clone(),
141+
)?;
136142

137143
Ok(Self {
138144
db,
@@ -352,6 +358,7 @@ impl Default for IndexerArgs {
352358
pub async fn start_indexer(
353359
db_args: DbArgs,
354360
indexer_args: IndexerArgs,
361+
ingestion_args: IngestionArgs,
355362
indexer_config: IndexerConfig,
356363
// If true, the indexer will bootstrap from genesis.
357364
// Otherwise it will skip the pipelines that rely on genesis data.
@@ -410,7 +417,15 @@ pub async fn start_indexer(
410417

411418
let cancel = CancellationToken::new();
412419
let retry_interval = ingestion.retry_interval();
413-
let mut indexer = Indexer::new(db_args, indexer_args, ingestion, cancel.clone()).await?;
420+
421+
let mut indexer = Indexer::new(
422+
db_args,
423+
indexer_args,
424+
ingestion_args,
425+
ingestion,
426+
cancel.clone(),
427+
)
428+
.await?;
414429

415430
macro_rules! add_concurrent {
416431
($handler:expr, $config:expr) => {

crates/sui-indexer-alt/src/main.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ async fn main() -> Result<()> {
2222

2323
match args.command {
2424
Command::Indexer {
25+
ingestion_args,
2526
indexer_args,
2627
config,
2728
} => {
@@ -32,7 +33,14 @@ async fn main() -> Result<()> {
3233
let indexer_config: IndexerConfig = toml::from_str(&config_contents)
3334
.context("Failed to parse configuration TOML file.")?;
3435

35-
start_indexer(args.db_args, indexer_args, indexer_config, true).await?;
36+
start_indexer(
37+
args.db_args,
38+
indexer_args,
39+
ingestion_args,
40+
indexer_config,
41+
true,
42+
)
43+
.await?;
3644
}
3745

3846
Command::GenerateConfig => {

0 commit comments

Comments
 (0)