Skip to content

Commit 23259b7

Browse files
committed
change ttl data type
1 parent aa6f54d commit 23259b7

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

router/src/cluster_based.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
//! A router based on the [`cluster::Cluster`].
44
5-
use std::time::Duration;
6-
75
use async_trait::async_trait;
86
use ceresdbproto::storage::{Route, RouteRequest};
97
use cluster::ClusterRef;
@@ -24,8 +22,8 @@ impl ClusterBasedRouter {
2422
let cache = if cache_config.enable {
2523
Some(
2624
Cache::builder()
27-
.time_to_live(Duration::from_secs(cache_config.ttl))
28-
.time_to_idle(Duration::from_secs(cache_config.tti))
25+
.time_to_live(cache_config.ttl.0)
26+
.time_to_idle(cache_config.tti.0)
2927
.max_capacity(cache_config.capacity)
3028
.build(),
3129
)
@@ -114,6 +112,7 @@ impl Router for ClusterBasedRouter {
114112
#[cfg(test)]
115113
mod tests {
116114
use std::{collections::HashMap, sync::Arc, thread::sleep};
115+
use std::time::Duration;
117116

118117
use ceresdbproto::{
119118
meta_event::{
@@ -123,6 +122,7 @@ mod tests {
123122
storage::RequestContext,
124123
};
125124
use cluster::{Cluster, ClusterNodesResp};
125+
use common_util::config::ReadableDuration;
126126
use meta_client::types::{
127127
NodeShard, RouteEntry, RouteTablesResponse, ShardInfo, ShardRole::Leader, TableInfo,
128128
TablesOfShard,
@@ -216,8 +216,8 @@ mod tests {
216216

217217
let config = RouteCacheConfig {
218218
enable: true,
219-
ttl: 4,
220-
tti: 2,
219+
ttl: ReadableDuration::from(Duration::from_secs(4)),
220+
tti: ReadableDuration::from(Duration::from_secs(2)),
221221
capacity: 2,
222222
};
223223
let router = ClusterBasedRouter::new(Arc::new(mock_cluster), config);

router/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::sync::Arc;
99
use async_trait::async_trait;
1010
use ceresdbproto::storage::{Route, RouteRequest};
1111
pub use cluster_based::ClusterBasedRouter;
12-
use common_util::define_result;
12+
use common_util::{config::ReadableDuration, define_result};
1313
pub use rule_based::{RuleBasedRouter, RuleList};
1414
use serde::{Deserialize, Serialize};
1515
use snafu::{Backtrace, Snafu};
@@ -69,9 +69,9 @@ pub struct RouteCacheConfig {
6969
// enable route cache, default false
7070
enable: bool,
7171
/// Time to live (TTL) in second.
72-
ttl: u64,
72+
ttl: ReadableDuration,
7373
/// Time to idle (TTI) in second.
74-
tti: u64,
74+
tti: ReadableDuration,
7575
/// how many route records can store in cache.
7676
capacity: u64,
7777
}

0 commit comments

Comments
 (0)