servers/
heartbeat_options.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::time::Duration;
16
17use common_meta::distributed_time_constants;
18use serde::{Deserialize, Serialize};
19
20#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
21#[serde(default)]
22pub struct HeartbeatOptions {
23    #[serde(with = "humantime_serde")]
24    pub interval: Duration,
25    #[serde(with = "humantime_serde")]
26    pub retry_interval: Duration,
27}
28
29impl HeartbeatOptions {
30    pub fn datanode_default() -> Self {
31        Default::default()
32    }
33
34    pub fn frontend_default() -> Self {
35        Self {
36            // Frontend can send heartbeat with a longer interval.
37            interval: Duration::from_millis(
38                distributed_time_constants::FRONTEND_HEARTBEAT_INTERVAL_MILLIS,
39            ),
40            retry_interval: Duration::from_millis(
41                distributed_time_constants::HEARTBEAT_INTERVAL_MILLIS,
42            ),
43        }
44    }
45}
46
47impl Default for HeartbeatOptions {
48    fn default() -> Self {
49        Self {
50            interval: Duration::from_millis(distributed_time_constants::HEARTBEAT_INTERVAL_MILLIS),
51            retry_interval: Duration::from_millis(
52                distributed_time_constants::HEARTBEAT_INTERVAL_MILLIS,
53            ),
54        }
55    }
56}