diff --git a/Cargo.lock b/Cargo.lock index fa8fd6e2d13a8..b3f5b01055359 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1197,6 +1197,7 @@ dependencies = [ "aptos-config", "aptos-db-indexer-schemas", "aptos-logger", + "aptos-metrics-core", "aptos-proptest-helpers", "aptos-resource-viewer", "aptos-rocksdb-options", @@ -1207,6 +1208,7 @@ dependencies = [ "bytes", "dashmap", "move-core-types", + "once_cell", "rand 0.7.3", ] diff --git a/storage/indexer/Cargo.toml b/storage/indexer/Cargo.toml index 963c1a61864b0..5967a4c20c90e 100644 --- a/storage/indexer/Cargo.toml +++ b/storage/indexer/Cargo.toml @@ -17,6 +17,7 @@ anyhow = { workspace = true } aptos-config = { workspace = true } aptos-db-indexer-schemas = { workspace = true } aptos-logger = { workspace = true } +aptos-metrics-core = { workspace = true } aptos-resource-viewer = { workspace = true } aptos-rocksdb-options = { workspace = true } aptos-schemadb = { workspace = true } @@ -26,6 +27,7 @@ bcs = { workspace = true } bytes = { workspace = true } dashmap = { workspace = true } move-core-types = { workspace = true } +once_cell = { workspace = true } [dev-dependencies] aptos-proptest-helpers = { workspace = true } diff --git a/storage/indexer/src/db_indexer.rs b/storage/indexer/src/db_indexer.rs index ad0cbf56053fc..ac3d18709a068 100644 --- a/storage/indexer/src/db_indexer.rs +++ b/storage/indexer/src/db_indexer.rs @@ -1,7 +1,7 @@ // Copyright (c) Aptos Foundation // SPDX-License-Identifier: Apache-2.0 -use crate::utils::PrefixedStateValueIterator; +use crate::{metrics::TIMER, utils::PrefixedStateValueIterator}; use aptos_config::config::internal_indexer_db_config::InternalIndexerDBConfig; use aptos_db_indexer_schemas::{ metadata::{MetadataKey, MetadataValue, StateSnapshotProgress}, @@ -361,6 +361,7 @@ impl DBIndexer { } pub fn process_a_batch(&self, start_version: Version) -> Result { + let _timer = TIMER.with_label_values(&["process_a_batch"]).start_timer(); let mut version = start_version; let num_transactions = self.get_num_of_transactions(version)?; // This promises num_transactions should be readable from main db @@ -398,7 +399,7 @@ impl DBIndexer { if self.indexer_db.statekeys_enabled() { writeset.iter().for_each(|(state_key, write_op)| { - if write_op.is_creation() { + if write_op.is_creation() || write_op.is_modification() { batch .put::(state_key, &()) .expect("Failed to put state keys to a batch"); @@ -409,6 +410,7 @@ impl DBIndexer { Ok::<(), AptosDbError>(()) })?; assert!(version > 0, "batch number should be greater than 0"); + assert_eq!(num_transactions, version - start_version); if self.indexer_db.transaction_enabled() { diff --git a/storage/indexer/src/lib.rs b/storage/indexer/src/lib.rs index 6a96f37f16cf0..7a041c5dbbaca 100644 --- a/storage/indexer/src/lib.rs +++ b/storage/indexer/src/lib.rs @@ -7,6 +7,7 @@ pub mod db_indexer; pub mod db_ops; pub mod db_v2; pub mod indexer_reader; +mod metrics; mod utils; use crate::db::INDEX_DB_NAME; diff --git a/storage/indexer/src/metrics.rs b/storage/indexer/src/metrics.rs new file mode 100644 index 0000000000000..1ed7179580a22 --- /dev/null +++ b/storage/indexer/src/metrics.rs @@ -0,0 +1,15 @@ +// Copyright © Aptos Foundation +// SPDX-License-Identifier: Apache-2.0 + +use aptos_metrics_core::{exponential_buckets, register_histogram_vec, HistogramVec}; +use once_cell::sync::Lazy; + +pub static TIMER: Lazy = Lazy::new(|| { + register_histogram_vec!( + "aptos_internal_indexer_timer_seconds", + "Various timers for performance analysis.", + &["name"], + exponential_buckets(/*start=*/ 1e-9, /*factor=*/ 2.0, /*count=*/ 32).unwrap(), + ) + .unwrap() +});