diff --git a/openraft/src/config/config.rs b/openraft/src/config/config.rs index a42c61ab6..1076e8f2c 100644 --- a/openraft/src/config/config.rs +++ b/openraft/src/config/config.rs @@ -103,6 +103,10 @@ pub struct Config { #[clap(long, default_value = "200")] pub install_snapshot_timeout: u64, + /// The timeout for sending the last snapshot segment, in seconds + #[clap(long, default_value = "300")] + pub finalize_snapshot_timeout: u64, + /// The maximum number of entries per payload allowed to be transmitted during replication /// /// If this is too low, it will take longer for the nodes to be brought up to diff --git a/openraft/src/core/install_snapshot.rs b/openraft/src/core/install_snapshot.rs index c8479858c..372bdf1dd 100644 --- a/openraft/src/core/install_snapshot.rs +++ b/openraft/src/core/install_snapshot.rs @@ -66,6 +66,7 @@ impl, S: RaftStorage> RaftCore, S /// The timeout for sending snapshot segment. install_snapshot_timeout: Duration, + /// The timeout for sending the last snapshot segment. This is when finalize is called, which can often be longer. + finalize_snapshot_timeout: Duration, + /// if or not need to replicate log entries or states, e.g., `commit_index` etc. need_to_replicate: bool, } @@ -149,6 +152,7 @@ impl, S: RaftStorage> Replication // other component to ReplicationStream let (repl_tx, repl_rx) = mpsc::unbounded_channel(); let install_snapshot_timeout = Duration::from_millis(config.install_snapshot_timeout); + let finalize_snapshot_timeout = Duration::from_millis(config.finalize_snapshot_timeout); let this = Self { target, @@ -164,6 +168,7 @@ impl, S: RaftStorage> Replication raft_core_tx, repl_rx, install_snapshot_timeout, + finalize_snapshot_timeout, need_to_replicate: true, }; @@ -751,7 +756,13 @@ impl, S: RaftStorage> Replication "sending snapshot chunk" ); - let res = timeout(self.install_snapshot_timeout, self.network.send_install_snapshot(req)).await; + let snap_timeout = if done { + self.install_snapshot_timeout + } else { + self.finalize_snapshot_timeout + }; + + let res = timeout(snap_timeout, self.network.send_install_snapshot(req)).await; let res = match res { Ok(outer_res) => match outer_res {