Skip to content

Commit

Permalink
refactor: use humantime for user-facing options (#2724)
Browse files Browse the repository at this point in the history
* refactor: use humantime for user-facing options

Signed-off-by: tison <[email protected]>

* unify quote style

Signed-off-by: tison <[email protected]>

* taplo fmt

Signed-off-by: tison <[email protected]>

---------

Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun authored Nov 9, 2023
1 parent f02dc0e commit af71075
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
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 @@ -33,6 +33,7 @@ etcd-client.workspace = true
futures.workspace = true
h2 = "0.3"
http-body = "0.4"
humantime-serde.workspace = true
lazy_static.workspace = true
once_cell.workspace = true
parking_lot = "0.12"
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

0 comments on commit af71075

Please sign in to comment.