Skip to content

Commit

Permalink
write modified state key into internal indexer db
Browse files Browse the repository at this point in the history
  • Loading branch information
areshand committed Oct 2, 2024
1 parent 7f784af commit 6879371
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions storage/indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand Down
6 changes: 4 additions & 2 deletions storage/indexer/src/db_indexer.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -361,6 +361,7 @@ impl DBIndexer {
}

pub fn process_a_batch(&self, start_version: Version) -> Result<Version> {
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
Expand Down Expand Up @@ -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::<StateKeysSchema>(state_key, &())
.expect("Failed to put state keys to a batch");
Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions storage/indexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions storage/indexer/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -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<HistogramVec> = 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()
});

0 comments on commit 6879371

Please sign in to comment.