From 93ff5f7ff0f932a5b704be1da7c4a20cc916677c Mon Sep 17 00:00:00 2001 From: anastasia Date: Tue, 7 Dec 2021 17:02:42 +0300 Subject: [PATCH] Add default value for safekeeper --recall option. DEFAULT_RECALL_PERIOD is 1 second. --- walkeeper/src/bin/safekeeper.rs | 2 +- walkeeper/src/callmemaybe.rs | 7 ++----- walkeeper/src/lib.rs | 6 ++++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/walkeeper/src/bin/safekeeper.rs b/walkeeper/src/bin/safekeeper.rs index 67ee0d34cd..aceb759cd2 100644 --- a/walkeeper/src/bin/safekeeper.rs +++ b/walkeeper/src/bin/safekeeper.rs @@ -112,7 +112,7 @@ fn main() -> Result<()> { } if let Some(recall) = arg_matches.value_of("recall") { - conf.recall_period = Some(humantime::parse_duration(recall)?); + conf.recall_period = humantime::parse_duration(recall)?; } start_safekeeper(conf) diff --git a/walkeeper/src/callmemaybe.rs b/walkeeper/src/callmemaybe.rs index 4e249e9cfe..66eb9968ba 100644 --- a/walkeeper/src/callmemaybe.rs +++ b/walkeeper/src/callmemaybe.rs @@ -200,9 +200,6 @@ impl Drop for SubscriptionStateInner { } pub async fn main_loop(conf: SafeKeeperConf, mut rx: Receiver) -> Result<()> { - let default_timeout = Duration::from_secs(5); - let recall_period = conf.recall_period.unwrap_or(default_timeout); - let subscriptions: Mutex> = Mutex::new(HashMap::new()); @@ -259,7 +256,7 @@ pub async fn main_loop(conf: SafeKeeperConf, mut rx: Receiver) -> R }, } }, - _ = tokio::time::sleep(recall_period) => { true }, + _ = tokio::time::sleep(conf.recall_period) => { true }, }; if call_iteration { @@ -268,7 +265,7 @@ pub async fn main_loop(conf: SafeKeeperConf, mut rx: Receiver) -> R for (&(_tenantid, _timelineid), state) in subscriptions.iter() { let listen_pg_addr = conf.listen_pg_addr.clone(); - state.call(recall_period, listen_pg_addr); + state.call(conf.recall_period, listen_pg_addr); } } } diff --git a/walkeeper/src/lib.rs b/walkeeper/src/lib.rs index 2c26ea5dd6..0ad4e7d644 100644 --- a/walkeeper/src/lib.rs +++ b/walkeeper/src/lib.rs @@ -18,12 +18,14 @@ pub mod wal_service; pub mod defaults { use const_format::formatcp; + use std::time::Duration; pub const DEFAULT_PG_LISTEN_PORT: u16 = 5454; pub const DEFAULT_PG_LISTEN_ADDR: &str = formatcp!("127.0.0.1:{DEFAULT_PG_LISTEN_PORT}"); pub const DEFAULT_HTTP_LISTEN_PORT: u16 = 7676; pub const DEFAULT_HTTP_LISTEN_ADDR: &str = formatcp!("127.0.0.1:{DEFAULT_HTTP_LISTEN_PORT}"); + pub const DEFAULT_RECALL_PERIOD: Duration = Duration::from_secs(1); } #[derive(Debug, Clone)] @@ -41,7 +43,7 @@ pub struct SafeKeeperConf { pub listen_pg_addr: String, pub listen_http_addr: String, pub ttl: Option, - pub recall_period: Option, + pub recall_period: Duration, } impl SafeKeeperConf { @@ -62,7 +64,7 @@ impl Default for SafeKeeperConf { listen_pg_addr: defaults::DEFAULT_PG_LISTEN_ADDR.to_string(), listen_http_addr: defaults::DEFAULT_PG_LISTEN_ADDR.to_string(), ttl: None, - recall_period: None, + recall_period: defaults::DEFAULT_RECALL_PERIOD, } } }