Add default value for safekeeper --recall option. DEFAULT_RECALL_PERIOD is 1 second.

This commit is contained in:
anastasia
2021-12-07 17:02:42 +03:00
committed by lubennikovaav
parent 41dce68bdd
commit 93ff5f7ff0
3 changed files with 7 additions and 8 deletions

View File

@@ -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)

View File

@@ -200,9 +200,6 @@ impl Drop for SubscriptionStateInner {
}
pub async fn main_loop(conf: SafeKeeperConf, mut rx: Receiver<CallmeEvent>) -> Result<()> {
let default_timeout = Duration::from_secs(5);
let recall_period = conf.recall_period.unwrap_or(default_timeout);
let subscriptions: Mutex<HashMap<(ZTenantId, ZTimelineId), SubscriptionState>> =
Mutex::new(HashMap::new());
@@ -259,7 +256,7 @@ pub async fn main_loop(conf: SafeKeeperConf, mut rx: Receiver<CallmeEvent>) -> 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<CallmeEvent>) -> 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);
}
}
}

View File

@@ -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<Duration>,
pub recall_period: Option<Duration>,
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,
}
}
}