Skip to content

Commit 02f1ad9

Browse files
authored
feat: add meta join cluster timeout config (#10877)
* feat: add meta join cluster timeout config * feat: add meta join cluster timeout config * feat: add meta wait cluster leader timeout config
1 parent afc3f29 commit 02f1ad9

File tree

6 files changed

+20
-1
lines changed

6 files changed

+20
-1
lines changed

docs/doc/10-deploy/06-metasrv/15-metasrv-config.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ heartbeat_interval = 1000 # milli second
4747
install_snapshot_timeout = 4000 # milli second
4848
max_applied_log_to_keep = 1000 # N.O. raft logs
4949
snapshot_logs_since_last = 1024 # N.O. raft logs
50+
wait_leader_timeout = 70000
5051
#
5152
# Startup config
5253
#
@@ -101,6 +102,8 @@ Defines raft behaviors on raft-storage and the state machine.
101102

102103
- `snapshot_logs_since_last` specifies the number of raft-logs since the last snapshot beyond which a snapshot will be generated.
103104

105+
- `wait_leader_timeout` specifies the max time for waiting a cluster leader in milliseconds.
106+
104107
## 6. Startup config
105108

106109
- `single` tells the node to initialize a single node cluster if it is not

src/binaries/meta/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ async fn register_node(meta_node: &Arc<MetaNode>, conf: &Config) -> Result<(), a
177177
"Register node to update raft_api_advertise_host_endpoint and grpc_api_advertise_address"
178178
);
179179

180-
let wait_leader_timeout = Duration::from_millis(conf.raft_config.election_timeout().1 * 10);
180+
let wait_leader_timeout = Duration::from_millis(conf.raft_config.wait_leader_timeout);
181181
info!(
182182
"Wait {:?} for active leader to register node, raft election timeouts: {:?}",
183183
wait_leader_timeout,

src/meta/raft-store/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ pub struct RaftConfig {
110110
/// The node name. If the user specifies a name,
111111
/// the user-supplied name is used, if not, the default name is used.
112112
pub cluster_name: String,
113+
114+
/// Max timeout(in milli seconds) when waiting a cluster leader.
115+
pub wait_leader_timeout: u64,
113116
}
114117

115118
pub fn get_default_raft_advertise_host() -> String {
@@ -142,6 +145,7 @@ impl Default for RaftConfig {
142145
id: 0,
143146
sled_tree_prefix: "".to_string(),
144147
cluster_name: "foo_cluster".to_string(),
148+
wait_leader_timeout: 70000,
145149
}
146150
}
147151
}

src/meta/service/src/configs/outer_v0.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ pub struct ConfigViaEnv {
277277
pub kvsrv_snapshot_logs_since_last: u64,
278278
pub kvsrv_heartbeat_interval: u64,
279279
pub kvsrv_install_snapshot_timeout: u64,
280+
pub kvsrv_wait_leader_timeout: u64,
280281
pub raft_max_applied_log_to_keep: u64,
281282
pub kvsrv_single: bool,
282283
pub metasrv_join: Vec<String>,
@@ -320,6 +321,7 @@ impl From<Config> for ConfigViaEnv {
320321
kvsrv_snapshot_logs_since_last: cfg.raft_config.snapshot_logs_since_last,
321322
kvsrv_heartbeat_interval: cfg.raft_config.heartbeat_interval,
322323
kvsrv_install_snapshot_timeout: cfg.raft_config.install_snapshot_timeout,
324+
kvsrv_wait_leader_timeout: cfg.raft_config.wait_leader_timeout,
323325
raft_max_applied_log_to_keep: cfg.raft_config.max_applied_log_to_keep,
324326
kvsrv_single: cfg.raft_config.single,
325327
metasrv_join: cfg.raft_config.join,
@@ -344,6 +346,7 @@ impl Into<Config> for ConfigViaEnv {
344346
snapshot_logs_since_last: self.kvsrv_snapshot_logs_since_last,
345347
heartbeat_interval: self.kvsrv_heartbeat_interval,
346348
install_snapshot_timeout: self.kvsrv_install_snapshot_timeout,
349+
wait_leader_timeout: self.kvsrv_wait_leader_timeout,
347350
max_applied_log_to_keep: self.raft_max_applied_log_to_keep,
348351
single: self.kvsrv_single,
349352
join: self.metasrv_join,
@@ -483,6 +486,10 @@ pub struct RaftConfig {
483486
/// if not, the default name is used
484487
#[clap(long, default_value = "foo_cluster")]
485488
pub cluster_name: String,
489+
490+
/// Max timeout(in milli seconds) when waiting a cluster leader.
491+
#[clap(long, default_value = "70000")]
492+
pub wait_leader_timeout: u64,
486493
}
487494

488495
impl Default for RaftConfig {
@@ -511,6 +518,7 @@ impl From<RaftConfig> for InnerRaftConfig {
511518
id: x.id,
512519
sled_tree_prefix: x.sled_tree_prefix,
513520
cluster_name: x.cluster_name,
521+
wait_leader_timeout: x.wait_leader_timeout,
514522
}
515523
}
516524
}
@@ -535,6 +543,7 @@ impl From<InnerRaftConfig> for RaftConfig {
535543
id: inner.id,
536544
sled_tree_prefix: inner.sled_tree_prefix,
537545
cluster_name: inner.cluster_name,
546+
wait_leader_timeout: inner.wait_leader_timeout,
538547
}
539548
}
540549
}

src/meta/service/src/meta_service/raftmeta.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ impl MetaNode {
663663
}
664664
}
665665
}
666+
666667
Err(MetaManagementError::Join(AnyError::error(format!(
667668
"fail to join {} cluster via {:?}, caused by errors: {}",
668669
self.sto.id,

src/meta/service/tests/it/configs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ no_sync = true
5959
snapshot_logs_since_last = 1000
6060
heartbeat_interval = 2000
6161
install_snapshot_timeout = 3000
62+
wait_leader_timeout = 3000
6263
single = false
6364
join = ["j1", "j2"]
6465
id = 20
@@ -85,6 +86,7 @@ cluster_name = "foo_cluster"
8586
assert_eq!(cfg.raft_config.snapshot_logs_since_last, 1000);
8687
assert_eq!(cfg.raft_config.heartbeat_interval, 2000);
8788
assert_eq!(cfg.raft_config.install_snapshot_timeout, 3000);
89+
assert_eq!(cfg.raft_config.wait_leader_timeout, 3000);
8890
assert!(!cfg.raft_config.single);
8991
assert_eq!(cfg.raft_config.join, vec!["j1", "j2"]);
9092
assert_eq!(cfg.raft_config.id, 20);

0 commit comments

Comments
 (0)