-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #816 from drmingdrmer/24-parallel-build-snapshot
Improve: build snapshot in anohter task
- Loading branch information
Showing
9 changed files
with
217 additions
and
21 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
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
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,27 @@ | ||
### `build_change_log.py` | ||
|
||
Build change log since a previous git-tag | ||
|
||
- Usage: `./scripts/build_change_log.py`: build change log since last tag. | ||
- Usage: `./scripts/build_change_log.py <commit>`: build since specified commit. | ||
- Install: `pip install -r requirements.txt`. | ||
|
||
This script buils change log from git commit messages, outputs a versioned | ||
change log to `./change-log/<version>.md` and concatenates all versioned change log | ||
into `./change-log.md`. | ||
|
||
If `./change-log/<version>.md` exists, it skips re-building it from git-log. | ||
Thus you can generate semi-automatic change-logs by editing `./change-log/<version>.md` and running the script again, which will just only the `./change-log.md`. | ||
|
||
|
||
### `check.kdl` | ||
|
||
Run daily tests in parallel: | ||
|
||
- Usage: `zellij --layout ./scripts/check.kdl`. | ||
- Install: `cargo install zellij`. | ||
|
||
It opens 3 panes to run: | ||
- `cargo test --libs`: run only lib tests | ||
- `cargo test --test *`: run only integration tests. | ||
- `cargo clippy`: lint |
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,39 @@ | ||
// Use zellij to run test in parallel. | ||
// | ||
// Install: | ||
// cargo install zellij | ||
// | ||
// Usage: | ||
// zellij action new-tab --layout check.kdl | ||
// zellij --layout check.kdl | ||
|
||
simplified_ui true | ||
|
||
layout { | ||
|
||
tab name="3m1q" { | ||
// tab-bar | ||
pane size=1 borderless=true { | ||
plugin location="zellij:tab-bar" | ||
} | ||
|
||
pane split_direction="vertical" { | ||
pane { | ||
command "cargo" | ||
args "test" "--lib" | ||
} | ||
pane { | ||
command "cargo" | ||
args "test" "--test" "*" | ||
} | ||
pane { | ||
command "cargo" | ||
args "clippy" "--no-deps" "--all-targets" "--" "-D" "warnings" | ||
} | ||
} | ||
// status-bar | ||
pane size=2 borderless=true { | ||
plugin location="zellij:status-bar" | ||
} | ||
} | ||
} |
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
96 changes: 96 additions & 0 deletions
96
tests/tests/log_compaction/t35_building_snapshot_does_not_block_apply.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,96 @@ | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
|
||
use anyhow::Result; | ||
use maplit::btreeset; | ||
use openraft::raft::AppendEntriesRequest; | ||
use openraft::testing::blank_ent; | ||
use openraft::testing::log_id; | ||
use openraft::Config; | ||
use openraft::RaftNetwork; | ||
use openraft::RaftNetworkFactory; | ||
use openraft::Vote; | ||
use openraft_memstore::BlockOperation; | ||
|
||
use crate::fixtures::init_default_ut_tracing; | ||
use crate::fixtures::RaftRouter; | ||
|
||
/// When building a snapshot, applying-entries request should not be blocked. | ||
/// | ||
/// Issue: https://github.com/datafuselabs/openraft/issues/596 | ||
#[async_entry::test(worker_threads = 8, init = "init_default_ut_tracing()", tracing_span = "debug")] | ||
async fn building_snapshot_does_not_block_apply() -> Result<()> { | ||
let config = Arc::new( | ||
Config { | ||
enable_tick: false, | ||
..Default::default() | ||
} | ||
.validate()?, | ||
); | ||
|
||
let mut router = RaftRouter::new(config.clone()); | ||
let mut log_index = router.new_cluster(btreeset! {0,1}, btreeset! {}).await?; | ||
|
||
let follower = router.get_raft_handle(&1)?; | ||
|
||
tracing::info!(log_index, "--- set flag to delay snapshot building"); | ||
{ | ||
let (mut _sto1, sm1) = router.get_storage_handle(&1)?; | ||
sm1.storage_mut() | ||
.await | ||
.set_blocking(BlockOperation::DelayBuildingSnapshot, Duration::from_millis(5_000)); | ||
} | ||
|
||
tracing::info!(log_index, "--- build snapshot on follower, it should block"); | ||
{ | ||
log_index += router.client_request_many(0, "0", 10).await?; | ||
router.wait(&1, timeout()).log(Some(log_index), "written 10 logs").await?; | ||
|
||
follower.trigger_snapshot().await?; | ||
|
||
tracing::info!(log_index, "--- sleep 500 ms to make sure snapshot is started"); | ||
tokio::time::sleep(Duration::from_millis(500)).await; | ||
|
||
let res = router | ||
.wait(&1, Some(Duration::from_millis(500))) | ||
.snapshot(log_id(1, 0, log_index), "building snapshot is blocked") | ||
.await; | ||
assert!(res.is_err(), "snapshot should be blocked and can not finish"); | ||
} | ||
|
||
tracing::info!( | ||
log_index, | ||
"--- send append-entries request to the follower that is building snapshot" | ||
); | ||
{ | ||
let next = log_index + 1; | ||
|
||
let rpc = AppendEntriesRequest::<openraft_memstore::TypeConfig> { | ||
vote: Vote::new_committed(1, 0), | ||
prev_log_id: Some(log_id(1, 0, log_index)), | ||
entries: vec![blank_ent(1, 0, next)], | ||
// Append and commit this entry | ||
leader_commit: Some(log_id(1, 0, next)), | ||
}; | ||
|
||
let mut cli = router.new_client(1, &()).await; | ||
let fu = cli.send_append_entries(rpc); | ||
let fu = tokio::time::timeout(Duration::from_millis(500), fu); | ||
let resp = fu.await??; | ||
assert!(resp.is_success()); | ||
|
||
router | ||
.wait(&1, timeout()) | ||
.log( | ||
Some(next), | ||
format!("log at index {} can be applied, while snapshot is building", next), | ||
) | ||
.await?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn timeout() -> Option<Duration> { | ||
Some(Duration::from_millis(1_000)) | ||
} |
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