-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: replication should be able to shutdown when replicating snapshot…
… to unreachable node If a replication is sending a snapshot, it should periodically verify the input channel's status. When the input channel is closed during replication rebuilding, it should immediately exit the loop instead of attempting retries indefinitely. - Fix: #808
- Loading branch information
1 parent
60d49fd
commit d012705
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
tests/tests/snapshot/t90_issue_808_snapshot_to_unreachable_node_should_not_block.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
|
||
use anyhow::Result; | ||
use maplit::btreeset; | ||
use openraft::testing::log_id; | ||
use openraft::Config; | ||
|
||
use crate::fixtures::init_default_ut_tracing; | ||
use crate::fixtures::RaftRouter; | ||
|
||
/// When transferring snapshot to unreachable node, it should not block for ever. | ||
#[async_entry::test(worker_threads = 8, init = "init_default_ut_tracing()", tracing_span = "debug")] | ||
async fn snapshot_to_unreachable_node_should_not_block() -> Result<()> { | ||
let config = Arc::new( | ||
Config { | ||
purge_batch_size: 1, | ||
max_in_snapshot_log_to_keep: 0, | ||
enable_heartbeat: false, | ||
..Default::default() | ||
} | ||
.validate()?, | ||
); | ||
let mut router = RaftRouter::new(config.clone()); | ||
|
||
tracing::info!("--- initializing cluster"); | ||
let mut log_index = router.new_cluster(btreeset! {0,1}, btreeset! {2}).await?; | ||
|
||
tracing::info!(log_index, "--- isolate replication 0 -> 2"); | ||
router.isolate_node(2); | ||
|
||
let n = 10; | ||
tracing::info!(log_index, "--- write {} logs", n); | ||
{ | ||
log_index += router.client_request_many(0, "0", n).await?; | ||
router.wait(&0, timeout()).log(Some(log_index), format!("{} writes", n)).await?; | ||
} | ||
|
||
let n0 = router.get_raft_handle(&0)?; | ||
|
||
tracing::info!(log_index, "--- build a snapshot"); | ||
{ | ||
n0.trigger_snapshot().await?; | ||
|
||
n0.wait(timeout()).snapshot(log_id(1, 0, log_index), "snapshot").await?; | ||
n0.wait(timeout()).purged(Some(log_id(1, 0, log_index)), "logs in snapshot are purged").await?; | ||
} | ||
|
||
tracing::info!( | ||
log_index, | ||
"--- change membership to {{0}}, replication should be closed and re-spawned, snapshot streaming should stop at once" | ||
); | ||
{ | ||
n0.change_membership(btreeset! {0}, true).await?; | ||
n0.wait(timeout()).members(btreeset! {0}, "change membership to {{0}}").await?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn timeout() -> Option<Duration> { | ||
Some(Duration::from_millis(1_000)) | ||
} |