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

refactor: use humantime for user-facing options #2724

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions config/metasrv.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ retry_delay = "500ms"
# Failure detectors options.
[failure_detector]
threshold = 8.0
min_std_deviation_millis = 100.0
acceptable_heartbeat_pause_millis = 3000
first_heartbeat_estimate_millis = 1000
min_std_deviation = "100ms"
acceptable_heartbeat_pause = "3000ms"
first_heartbeat_estimate = "1000ms"

# # Datanode options.
# [datanode]
Expand Down
21 changes: 15 additions & 6 deletions src/cmd/src/metasrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ mod tests {

[failure_detector]
threshold = 8.0
min_std_deviation_millis = 100.0
acceptable_heartbeat_pause_millis = 3000
first_heartbeat_estimate_millis = 1000
min_std_deviation = "100ms"
acceptable_heartbeat_pause = "3000ms"
first_heartbeat_estimate = "1000ms"
"#;
write!(file, "{}", toml_str).unwrap();

Expand All @@ -241,14 +241,23 @@ mod tests {
assert_eq!("debug", options.logging.level.as_ref().unwrap());
assert_eq!("/tmp/greptimedb/test/logs".to_string(), options.logging.dir);
assert_eq!(8.0, options.failure_detector.threshold);
assert_eq!(100.0, options.failure_detector.min_std_deviation_millis);
assert_eq!(
100.0,
options.failure_detector.min_std_deviation.as_millis() as f32
);
assert_eq!(
3000,
options.failure_detector.acceptable_heartbeat_pause_millis
options
.failure_detector
.acceptable_heartbeat_pause
.as_millis()
);
assert_eq!(
1000,
options.failure_detector.first_heartbeat_estimate_millis
options
.failure_detector
.first_heartbeat_estimate
.as_millis()
);
}

Expand Down
1 change: 1 addition & 0 deletions src/meta-srv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ derive_builder.workspace = true
etcd-client.workspace = true
futures.workspace = true
h2 = "0.3"
humantime-serde.workspace = true
http-body = "0.4"
tisonkun marked this conversation as resolved.
Show resolved Hide resolved
lazy_static.workspace = true
once_cell.workspace = true
Expand Down
23 changes: 14 additions & 9 deletions src/meta-srv/src/failure_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use std::collections::VecDeque;
use std::time::Duration;

use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -66,9 +67,12 @@ pub(crate) struct PhiAccrualFailureDetector {
#[serde(default)]
pub struct PhiAccrualFailureDetectorOptions {
pub threshold: f32,
pub min_std_deviation_millis: f32,
pub acceptable_heartbeat_pause_millis: u32,
pub first_heartbeat_estimate_millis: u32,
#[serde(with = "humantime_serde")]
pub min_std_deviation: Duration,
#[serde(with = "humantime_serde")]
pub acceptable_heartbeat_pause: Duration,
#[serde(with = "humantime_serde")]
pub first_heartbeat_estimate: Duration,
}

impl Default for PhiAccrualFailureDetectorOptions {
Expand All @@ -77,9 +81,9 @@ impl Default for PhiAccrualFailureDetectorOptions {
// https://github.com/akka/akka/blob/v2.6.21/akka-cluster/src/main/resources/reference.conf#L181
Self {
threshold: 8_f32,
min_std_deviation_millis: 100_f32,
acceptable_heartbeat_pause_millis: 3000,
first_heartbeat_estimate_millis: 1000,
min_std_deviation: Duration::from_millis(100),
acceptable_heartbeat_pause: Duration::from_millis(3000),
first_heartbeat_estimate: Duration::from_millis(1000),
}
}
}
Expand All @@ -94,9 +98,10 @@ impl PhiAccrualFailureDetector {
pub(crate) fn from_options(options: PhiAccrualFailureDetectorOptions) -> Self {
Self {
threshold: options.threshold,
min_std_deviation_millis: options.min_std_deviation_millis,
acceptable_heartbeat_pause_millis: options.acceptable_heartbeat_pause_millis,
first_heartbeat_estimate_millis: options.first_heartbeat_estimate_millis,
min_std_deviation_millis: options.min_std_deviation.as_millis() as f32,
acceptable_heartbeat_pause_millis: options.acceptable_heartbeat_pause.as_millis()
as u32,
first_heartbeat_estimate_millis: options.first_heartbeat_estimate.as_millis() as u32,
heartbeat_history: HeartbeatHistory::new(1000),
last_heartbeat_millis: None,
}
Expand Down
Loading