Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

657 fast ping on startup #675

Merged
merged 12 commits into from
Feb 7, 2023
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Bob versions changelog
- Include bobc into release builds (#569)
- Added blob-info and index-info features to brt (#356)
- Support for files, file name patterns, key ranges and a 'exists' subcommand to 'bobc' (#539)
- Fast ping at the start (#657)

#### Changed
- Change locks to sync where possible (#472)
Expand Down
1 change: 1 addition & 0 deletions bob/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ tonic = { version = "0.6", features = ["prost"] }
tower = "0.4"
tower-service = "0.3"
uuid = "1.1.2"
ikopylov marked this conversation as resolved.
Show resolved Hide resolved
coarsetime = "0.1.22"

[dependencies.pearl]
version = "0.15.0"
Expand Down
62 changes: 50 additions & 12 deletions bob/src/link_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use crate::prelude::*;

use termion::color;

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

#[derive(Debug)]
pub(crate) struct LinkManager {
nodes: Arc<[Node]>,
Expand All @@ -21,28 +24,63 @@ impl LinkManager {
}

async fn checker_task(factory: Factory, nodes: Arc<[Node]>, period: Duration) {
let now = coarsetime::Clock::now_since_epoch().as_secs();
ikopylov marked this conversation as resolved.
Show resolved Hide resolved
ikopylov marked this conversation as resolved.
Show resolved Hide resolved
Self::checker(
&factory,
&nodes,
Duration::from_millis(FAST_PING_PERIOD_MS),
ikopylov marked this conversation as resolved.
Show resolved Hide resolved
|| {
let ts = coarsetime::Clock::now_since_epoch().as_secs();
ts > now && ts - now > FAST_PING_DURATION_SEC
},
period.as_millis() as usize / FAST_PING_PERIOD_MS as usize,
ikopylov marked this conversation as resolved.
Show resolved Hide resolved
)
.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 = 1;
while !should_stop() {
let log = i % log_iteration_div == 0;
if log {
i = 1;
} else {
i += 1;
}
ikopylov marked this conversation as resolved.
Show resolved Hide resolved
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} ", color::Fg(color::Red), node.name());
if log {
ikopylov marked this conversation as resolved.
Show resolved Hide resolved
error!(
"No connection to {}:[{}] - {}",
node.name(),
node.address(),
e
);
status += &format!("{}{:<10} ", color::Fg(color::Red), node.name());
ikopylov marked this conversation as resolved.
Show resolved Hide resolved
}
err_cnt += 1;
} else {
status += &format!("{}{:<10} ", color::Fg(color::Green), node.name());
if log {
status += &format!("{}{:<10} ", color::Fg(color::Green), node.name());
ikopylov marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
info!("{}{}", status, color::Fg(color::Reset));
let cnt = nodes.len() - err_cnt;
gauge!(AVAILABLE_NODES_COUNT, cnt as f64);
if log {
info!("{}{}", status, color::Fg(color::Reset));
ikopylov marked this conversation as resolved.
Show resolved Hide resolved
let cnt = nodes.len() - err_cnt;
gauge!(AVAILABLE_NODES_COUNT, cnt as f64);
ikopylov marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Expand Down