Skip to content

Commit

Permalink
[state-sync] version counters
Browse files Browse the repository at this point in the history
Prefer this model of type safety and simplicity... so introducing it
here where I have more work to do...
  • Loading branch information
davidiw authored and bors-libra committed Dec 1, 2020
1 parent a8a152c commit b0e30bf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
8 changes: 2 additions & 6 deletions state-synchronizer/src/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,8 @@ impl<T: ExecutorProxyTrait> SyncCoordinator<T> {
let synced_version = self.local_state.highest_version_in_local_storage();
let committed_version = self.local_state.highest_local_li.ledger_info().version();
let local_epoch = self.local_state.epoch();
counters::VERSION
.with_label_values(&[counters::SYNCED_VERSION_LABEL])
.set(synced_version as i64);
counters::VERSION
.with_label_values(&[counters::COMMITTED_VERSION_LABEL])
.set(committed_version as i64);
counters::set_version(counters::VersionType::Synced, synced_version);
counters::set_version(counters::VersionType::Committed, committed_version);
counters::EPOCH.set(local_epoch as i64);
debug!(LogSchema::new(LogEntry::LocalState)
.local_li_version(committed_version)
Expand Down
27 changes: 24 additions & 3 deletions state-synchronizer/src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,30 @@ pub const CHUNK_REQUEST_MSG_LABEL: &str = "chunk_request";
pub const CHUNK_RESPONSE_MSG_LABEL: &str = "chunk_response";

// version type labels
pub const COMMITTED_VERSION_LABEL: &str = "committed"; // Version of latest ledger info committed.
pub const SYNCED_VERSION_LABEL: &str = "synced"; // Version of most recent txn that was synced (even if it is not backed by an LI)
pub const TARGET_VERSION_LABEL: &str = "target"; // Version a node is trying to catch up to
pub fn set_version(version_type: VersionType, version: u64) {
VERSION
.with_label_values(&[version_type.as_str()])
.set(version as i64)
}

pub enum VersionType {
/// Version of latest ledger info committed.
Committed,
/// Version of most recent txn that was synced (even if it is not backed by an LI)
Synced,
/// Current version a node is trying to catch up to usually within the current epoch
Target,
}

impl VersionType {
pub fn as_str(&self) -> &'static str {
match self {
VersionType::Committed => "committed",
VersionType::Synced => "synced",
VersionType::Target => "target",
}
}
}

// failed channel send type labels
pub const CONSENSUS_SYNC_REQ_CALLBACK: &str = "consensus_sync_req_callback";
Expand Down
4 changes: 1 addition & 3 deletions state-synchronizer/src/request_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,7 @@ impl RequestManager {
// TODO set target version of chunk request in counter
if failed_peer_sends.is_empty() {
if let Some(version) = target_version {
counters::VERSION
.with_label_values(&[counters::TARGET_VERSION_LABEL])
.set(version as i64);
counters::set_version(counters::VersionType::Target, version);
}
Ok(())
} else {
Expand Down

0 comments on commit b0e30bf

Please sign in to comment.