Skip to content

Commit

Permalink
[Storage] Use gauged api to measure latency.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLind authored and aptos-bot committed Apr 29, 2022
1 parent 7ffedbe commit 12eae22
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ mock! {
chunk_size: usize,
) -> Result<StateValueChunkWithProof>;

fn get_state_prune_window(&self) -> Option<usize>;
fn get_state_prune_window(&self) -> Result<Option<usize>>;
}
}

Expand Down
1 change: 1 addition & 0 deletions state-sync/storage-service/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ impl StorageReader {
let pruning_window = self
.storage
.get_state_prune_window()
.map_err(|error| Error::StorageErrorEncountered(error.to_string()))?
.map(|window| window as u64);
if let Some(pruning_window) = pruning_window {
if latest_version > pruning_window {
Expand Down
4 changes: 2 additions & 2 deletions state-sync/storage-service/server/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,8 @@ impl DbReader for MockDbReader {
Ok(account_states_chunk_with_proof)
}

fn get_state_prune_window(&self) -> Option<usize> {
Some(STATE_PRUNE_WINDOW as usize)
fn get_state_prune_window(&self) -> Result<Option<usize>> {
Ok(Some(STATE_PRUNE_WINDOW as usize))
}
}

Expand Down
33 changes: 22 additions & 11 deletions storage/aptosdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,12 @@ impl DbReader for AptosDB {
ledger_version: Version,
fetch_events: bool,
) -> Result<Option<TransactionWithProof>> {
self.transaction_store
.get_transaction_version_by_hash(&hash, ledger_version)?
.map(|v| self.get_transaction_with_proof(v, ledger_version, fetch_events))
.transpose()
gauged_api("get_transaction_by_hash", || {
self.transaction_store
.get_transaction_version_by_hash(&hash, ledger_version)?
.map(|v| self.get_transaction_with_proof(v, ledger_version, fetch_events))
.transpose()
})
}

/// Get transaction by version, delegates to `AptosDB::get_transaction_by_hash`
Expand All @@ -749,7 +751,9 @@ impl DbReader for AptosDB {
ledger_version: Version,
fetch_events: bool,
) -> Result<TransactionWithProof> {
self.get_transaction_with_proof(version, ledger_version, fetch_events)
gauged_api("get_transaction_by_version", || {
self.get_transaction_with_proof(version, ledger_version, fetch_events)
})
}

// ======================= State Synchronizer Internal APIs ===================================
Expand Down Expand Up @@ -807,12 +811,16 @@ impl DbReader for AptosDB {

/// Get the first version that txn starts existent.
fn get_first_txn_version(&self) -> Result<Option<Version>> {
self.transaction_store.get_first_txn_version()
gauged_api("get_first_txn_version", || {
self.transaction_store.get_first_txn_version()
})
}

/// Get the first version that write set starts existent.
fn get_first_write_set_version(&self) -> Result<Option<Version>> {
self.transaction_store.get_first_write_set_version()
gauged_api("get_first_write_set_version", || {
self.transaction_store.get_first_write_set_version()
})
}

/// Gets a batch of transactions for the purpose of synchronizing state to another node.
Expand Down Expand Up @@ -1190,10 +1198,13 @@ impl DbReader for AptosDB {
})
}

fn get_state_prune_window(&self) -> Option<usize> {
self.pruner
.as_ref()
.map(|x| x.get_state_store_pruner_window() as usize)
fn get_state_prune_window(&self) -> Result<Option<usize>> {
gauged_api("get_state_prune_window", || {
Ok(self
.pruner
.as_ref()
.map(|x| x.get_state_store_pruner_window() as usize))
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion storage/storage-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ pub trait DbReader: Send + Sync {
}

/// Get the state prune window config value.
fn get_state_prune_window(&self) -> Option<usize> {
fn get_state_prune_window(&self) -> Result<Option<usize>> {
unimplemented!()
}
}
Expand Down

0 comments on commit 12eae22

Please sign in to comment.