-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub mod parquet_write_set_size_info; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
use crate::{ | ||
config::{ | ||
db_config::DbConfig, indexer_processor_config::IndexerProcessorConfig, | ||
processor_config::ProcessorConfig, | ||
}, | ||
parquet_processors::{ | ||
initialize_database_pool, initialize_gcs_client, initialize_parquet_buffer_step, | ||
set_backfill_table_flag, ParquetTypeEnum, | ||
}, | ||
steps::{ | ||
common::{ | ||
parquet_version_tracker_step::ParquetVersionTrackerStep, | ||
processor_status_saver::get_processor_status_saver, | ||
}, | ||
parquet_transaction_metadata_processor::parquet_transaction_metadata_extractor::ParquetTransactionMetadataExtractor, | ||
}, | ||
utils::{ | ||
chain_id::check_or_update_chain_id, | ||
database::{run_migrations, ArcDbPool}, | ||
starting_version::get_min_last_success_version_parquet, | ||
}, | ||
}; | ||
use anyhow::Context; | ||
use aptos_indexer_processor_sdk::{ | ||
aptos_indexer_transaction_stream::{TransactionStream, TransactionStreamConfig}, | ||
builder::ProcessorBuilder, | ||
common_steps::{TransactionStreamStep, DEFAULT_UPDATE_PROCESSOR_STATUS_SECS}, | ||
traits::{processor_trait::ProcessorTrait, IntoRunnableStep}, | ||
}; | ||
use parquet::schema::types::Type; | ||
use processor::{ | ||
bq_analytics::generic_parquet_processor::HasParquetSchema, | ||
db::parquet::models::transaction_metadata_model::parquet_write_set_size_info::WriteSetSize, | ||
}; | ||
use std::{collections::HashMap, sync::Arc}; | ||
use tracing::{debug, info}; | ||
|
||
pub struct ParquetTransactionMetadataProcessor { | ||
pub config: IndexerProcessorConfig, | ||
pub db_pool: ArcDbPool, | ||
} | ||
|
||
impl ParquetTransactionMetadataProcessor { | ||
pub async fn new(config: IndexerProcessorConfig) -> anyhow::Result<Self> { | ||
let db_pool = initialize_database_pool(&config.db_config).await?; | ||
Ok(Self { config, db_pool }) | ||
} | ||
Check warning on line 47 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L44-L47
|
||
} | ||
|
||
#[async_trait::async_trait] | ||
impl ProcessorTrait for ParquetTransactionMetadataProcessor { | ||
fn name(&self) -> &'static str { | ||
self.config.processor_config.name() | ||
} | ||
Check warning on line 54 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L52-L54
|
||
|
||
async fn run_processor(&self) -> anyhow::Result<()> { | ||
// Run Migrations | ||
let parquet_db_config = match self.config.db_config { | ||
DbConfig::ParquetConfig(ref parquet_config) => { | ||
run_migrations( | ||
parquet_config.connection_string.clone(), | ||
self.db_pool.clone(), | ||
) | ||
.await; | ||
parquet_config | ||
Check warning on line 65 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L58-L65
|
||
}, | ||
_ => { | ||
return Err(anyhow::anyhow!( | ||
"Invalid db config for ParquetTransactionMetadataProcessor {:?}", | ||
self.config.db_config | ||
)); | ||
Check warning on line 71 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L68-L71
|
||
}, | ||
}; | ||
|
||
// Check and update the ledger chain id to ensure we're indexing the correct chain | ||
let grpc_chain_id = TransactionStream::new(self.config.transaction_stream_config.clone()) | ||
.await? | ||
.get_chain_id() | ||
.await?; | ||
check_or_update_chain_id(grpc_chain_id as i64, self.db_pool.clone()).await?; | ||
Check warning on line 80 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L76-L80
|
||
|
||
let parquet_processor_config = match self.config.processor_config.clone() { | ||
ProcessorConfig::ParquetTransactionMetadataProcessor(parquet_processor_config) => { | ||
parquet_processor_config | ||
Check warning on line 84 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L82-L84
|
||
}, | ||
_ => { | ||
return Err(anyhow::anyhow!( | ||
"Invalid processor configuration for ParquetTransactionMetadataProcessor {:?}", | ||
self.config.processor_config | ||
)); | ||
Check warning on line 90 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L87-L90
|
||
}, | ||
}; | ||
|
||
let processor_status_table_names = self | ||
.config | ||
.processor_config | ||
.get_processor_status_table_names() | ||
.context("Failed to get table names for the processor status table")?; | ||
Check warning on line 98 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L94-L98
|
||
|
||
let starting_version = get_min_last_success_version_parquet( | ||
&self.config, | ||
self.db_pool.clone(), | ||
processor_status_table_names, | ||
) | ||
.await?; | ||
println!("Starting version: {:?}", starting_version); | ||
Check warning on line 106 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L100-L106
|
||
|
||
// Define processor transaction stream config | ||
let transaction_stream = TransactionStreamStep::new(TransactionStreamConfig { | ||
starting_version: Some(starting_version), | ||
..self.config.transaction_stream_config.clone() | ||
}) | ||
.await?; | ||
Check warning on line 113 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L109-L113
|
||
|
||
let backfill_table = set_backfill_table_flag(parquet_processor_config.backfill_table); | ||
let parquet_txn_metadata_extractor = ParquetTransactionMetadataExtractor { | ||
opt_in_tables: backfill_table, | ||
}; | ||
Check warning on line 118 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L115-L118
|
||
|
||
let gcs_client = | ||
initialize_gcs_client(parquet_db_config.google_application_credentials.clone()).await; | ||
Check warning on line 121 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L120-L121
|
||
|
||
let parquet_type_to_schemas: HashMap<ParquetTypeEnum, Arc<Type>> = | ||
[(ParquetTypeEnum::WriteSetSize, WriteSetSize::schema())] | ||
.into_iter() | ||
.collect(); | ||
Check warning on line 126 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L123-L126
|
||
|
||
let default_size_buffer_step = initialize_parquet_buffer_step( | ||
gcs_client.clone(), | ||
parquet_type_to_schemas, | ||
parquet_processor_config.upload_interval, | ||
parquet_processor_config.max_buffer_size, | ||
parquet_db_config.bucket_name.clone(), | ||
parquet_db_config.bucket_root.clone(), | ||
self.name().to_string(), | ||
) | ||
.await | ||
.unwrap_or_else(|e| { | ||
panic!("Failed to initialize parquet buffer step: {:?}", e); | ||
}); | ||
|
||
let parquet_version_tracker_step = ParquetVersionTrackerStep::new( | ||
get_processor_status_saver(self.db_pool.clone(), self.config.clone()), | ||
DEFAULT_UPDATE_PROCESSOR_STATUS_SECS, | ||
); | ||
|
||
let channel_size = parquet_processor_config.channel_size; | ||
|
||
// Connect processor steps together | ||
let (_, buffer_receiver) = ProcessorBuilder::new_with_inputless_first_step( | ||
transaction_stream.into_runnable_step(), | ||
) | ||
.connect_to( | ||
parquet_txn_metadata_extractor.into_runnable_step(), | ||
channel_size, | ||
) | ||
.connect_to(default_size_buffer_step.into_runnable_step(), channel_size) | ||
.connect_to( | ||
parquet_version_tracker_step.into_runnable_step(), | ||
channel_size, | ||
) | ||
.end_and_return_output_receiver(channel_size); | ||
Check warning on line 162 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L128-L162
|
||
|
||
loop { | ||
match buffer_receiver.recv().await { | ||
Ok(txn_context) => { | ||
debug!( | ||
"Finished processing versions [{:?}, {:?}]", | ||
Check warning on line 168 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L165-L168
|
||
txn_context.metadata.start_version, txn_context.metadata.end_version, | ||
); | ||
}, | ||
Err(e) => { | ||
info!("No more transactions in channel: {:?}", e); | ||
break Ok(()); | ||
Check warning on line 174 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L172-L174
|
||
}, | ||
} | ||
} | ||
} | ||
Check warning on line 178 in rust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs Codecov / codecov/patchrust/sdk-processor/src/parquet_processors/parquet_transaction_metadata_processor.rs#L178
|
||
} |