mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-10-27 22:26:15 +00:00
refactor: use humantime for user-facing options (#2724)
* refactor: use humantime for user-facing options Signed-off-by: tison <wander4096@gmail.com> * unify quote style Signed-off-by: tison <wander4096@gmail.com> * taplo fmt Signed-off-by: tison <wander4096@gmail.com> --------- Signed-off-by: tison <wander4096@gmail.com>
This commit is contained in:
Generated
+1
@@ -4727,6 +4727,7 @@ dependencies = [
|
||||
"futures",
|
||||
"h2",
|
||||
"http-body",
|
||||
"humantime-serde",
|
||||
"lazy_static",
|
||||
"once_cell",
|
||||
"parking_lot 0.12.1",
|
||||
|
||||
@@ -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]
|
||||
|
||||
+15
-6
@@ -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();
|
||||
|
||||
@@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::time::Duration;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -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 {
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user