Skip to content

Commit

Permalink
657 fast ping on startup (#675)
Browse files Browse the repository at this point in the history
* add low period ping at start

* update changelog

* add constants

* reduce logs from ping

* changes

* changes

* rename variable

* revert uuid version

* [657] Revert function rename
  • Loading branch information
idruzhitskiy authored Feb 7, 2023
1 parent e32ef48 commit 64879a2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Bob versions changelog
## [Unreleased]
#### Added
- Quorum argument for manual workflow dispatch for integration tests (#749)
- Fast ping at the start (#657)
- Client metrics are initialized at the start (#761)
- Exist test on doubled range of keys for integration tests (#764)

Expand Down
54 changes: 44 additions & 10 deletions bob/src/link_manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::prelude::*;
use std::time::Instant;

const FAST_PING_PERIOD_MS: u64 = 100;
const FAST_PING_DURATION_SEC: u64 = 60;

#[derive(Debug)]
pub(crate) struct LinkManager {
Expand All @@ -19,26 +23,56 @@ impl LinkManager {
}

async fn checker_task(factory: Factory, nodes: Arc<[Node]>, period: Duration) {
let start = Instant::now();
let fast_log_iteration_div =
(period.as_millis() as usize / FAST_PING_PERIOD_MS as usize).max(1);
Self::checker(
&factory,
&nodes,
Duration::from_millis(FAST_PING_PERIOD_MS).min(period),
|| start.elapsed().as_secs() > FAST_PING_DURATION_SEC,
fast_log_iteration_div,
)
.await;
Self::checker(&factory, &nodes, period, || false, 1).await;
}

async fn checker(
factory: &Factory,
nodes: &[Node],
period: Duration,
should_stop: impl Fn() -> bool,
log_iteration_div: usize,
) {
let mut interval = interval(period);
loop {
let mut i: usize = 1;
while !should_stop() {
i = i.wrapping_add(1) % log_iteration_div;
let log_in_this_iter = i == 0;
interval.tick().await;
let mut err_cnt = 0;
let mut status = String::from("Node status: ");
for node in nodes.iter() {
if let Err(e) = node.check(&factory).await {
error!(
"No connection to {}:[{}] - {}",
node.name(),
node.address(),
e
);
status += &format!("[-]{:<10} ", node.name());
if log_in_this_iter {
error!(
"No connection to {}:[{}] - {}",
node.name(),
node.address(),
e
);
status += &format!("[-]{:<10} ", node.name());
}
err_cnt += 1;
} else {
status += &format!("[+]{:<10} ", node.name());
if log_in_this_iter {
status += &format!("[+]{:<10} ", node.name());
}
}
}
info!("{}", status);
if log_in_this_iter {
info!("{}", status);
}
let cnt = nodes.len() - err_cnt;
gauge!(AVAILABLE_NODES_COUNT, cnt as f64);
}
Expand Down

0 comments on commit 64879a2

Please sign in to comment.