Skip to content

Commit

Permalink
[Aptos Data Client] Update the poller to better handle in-flight
Browse files Browse the repository at this point in the history
requests.

Closes: aptos-labs#1059
  • Loading branch information
JoshLind authored and aptos-bot committed May 18, 2022
1 parent 093298c commit 8efeec7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions state-sync/aptos-data-client/src/aptosnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use storage_service_types::{
StorageServiceRequest, StorageServiceResponse, TransactionOutputsWithProofRequest,
TransactionsWithProofRequest,
};
use tokio::runtime::Handle;
use tokio::{runtime::Handle, task::JoinHandle};

mod logging;
mod metrics;
Expand Down Expand Up @@ -621,7 +621,11 @@ fn update_in_flight_metrics(label: &str, num_in_flight_polls: u64) {
}

/// Spawns a dedicated poller for the given peer.
fn poll_peer(data_client: AptosNetDataClient, peer: PeerNetworkId, runtime: Option<Handle>) {
pub(crate) fn poll_peer(
data_client: AptosNetDataClient,
peer: PeerNetworkId,
runtime: Option<Handle>,
) -> JoinHandle<()> {
// Create the poller for the peer
let poller = async move {
// Mark the in-flight poll as started
Expand All @@ -642,6 +646,9 @@ fn poll_peer(data_client: AptosNetDataClient, peer: PeerNetworkId, runtime: Opti
.map(Response::into_payload);
drop(timer);

// Mark the in-flight poll as now complete
data_client.in_flight_request_complete(&peer);

// Check the storage summary response
let storage_summary = match result {
Ok(storage_summary) => storage_summary,
Expand All @@ -661,9 +668,6 @@ fn poll_peer(data_client: AptosNetDataClient, peer: PeerNetworkId, runtime: Opti
data_client.update_summary(peer, storage_summary);
data_client.update_global_summary_cache();

// Mark the in-flight poll as now complete
data_client.in_flight_request_complete(&peer);

// Log the new global data summary and update the metrics
sample!(
SampleRate::Duration(Duration::from_secs(GLOBAL_DATA_LOG_FREQ_SECS)),
Expand All @@ -688,7 +692,7 @@ fn poll_peer(data_client: AptosNetDataClient, peer: PeerNetworkId, runtime: Opti
runtime.spawn(poller)
} else {
tokio::spawn(poller)
};
}
}

/// Updates the advertised data metrics using the given global
Expand Down

0 comments on commit 8efeec7

Please sign in to comment.