common_meta/
distributed_time_constants.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 etcd_client::ConnectOptions;
18
19/// Heartbeat interval time (is the basic unit of various time).
20pub const HEARTBEAT_INTERVAL_MILLIS: u64 = 3000;
21
22/// The frontend will also send heartbeats to Metasrv, sending an empty
23/// heartbeat every HEARTBEAT_INTERVAL_MILLIS * 6 seconds.
24pub const FRONTEND_HEARTBEAT_INTERVAL_MILLIS: u64 = HEARTBEAT_INTERVAL_MILLIS * 6;
25
26/// The lease seconds of a region. It's set by 3 heartbeat intervals
27/// (HEARTBEAT_INTERVAL_MILLIS × 3), plus some extra buffer (1 second).
28pub const REGION_LEASE_SECS: u64 =
29    Duration::from_millis(HEARTBEAT_INTERVAL_MILLIS * 3).as_secs() + 1;
30
31/// When creating table or region failover, a target node needs to be selected.
32/// If the node's lease has expired, the `Selector` will not select it.
33pub const DATANODE_LEASE_SECS: u64 = REGION_LEASE_SECS;
34
35pub const FLOWNODE_LEASE_SECS: u64 = DATANODE_LEASE_SECS;
36
37/// The lease seconds of metasrv leader.
38pub const META_LEASE_SECS: u64 = 5;
39
40/// The keep-alive interval of the Postgres connection.
41pub const POSTGRES_KEEP_ALIVE_SECS: u64 = 30;
42
43/// In a lease, there are two opportunities for renewal.
44pub const META_KEEP_ALIVE_INTERVAL_SECS: u64 = META_LEASE_SECS / 2;
45
46/// The timeout of the heartbeat request.
47pub const HEARTBEAT_TIMEOUT: Duration = Duration::from_secs(META_KEEP_ALIVE_INTERVAL_SECS + 1);
48
49/// The keep-alive interval of the heartbeat channel.
50pub const HEARTBEAT_CHANNEL_KEEP_ALIVE_INTERVAL_SECS: Duration = Duration::from_secs(15);
51
52/// The keep-alive timeout of the heartbeat channel.
53pub const HEARTBEAT_CHANNEL_KEEP_ALIVE_TIMEOUT_SECS: Duration = Duration::from_secs(5);
54
55/// The default options for the etcd client.
56pub fn default_etcd_client_options() -> ConnectOptions {
57    ConnectOptions::new()
58        .with_keep_alive_while_idle(true)
59        .with_keep_alive(Duration::from_secs(15), Duration::from_secs(5))
60        .with_connect_timeout(Duration::from_secs(10))
61}
62
63/// The default mailbox round-trip timeout.
64pub const MAILBOX_RTT_SECS: u64 = 1;
65
66/// The interval of reporting topic stats.
67pub const TOPIC_STATS_REPORT_INTERVAL_SECS: u64 = 15;
68
69/// The retention seconds of topic stats.
70pub const TOPIC_STATS_RETENTION_SECS: u64 = TOPIC_STATS_REPORT_INTERVAL_SECS * 100;