-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- **Wrote committed log id to storage** Save the committed log id to storage before Raft apply log entries. This can recover state machine to the state corresponding to the committed log id upon system startup. - **Re-applied log entries after startup** If the last applied log id is smaller than the committed log id saved in storage, re-apply log entries from the next index of last applied log id to the committed log id. Version 1 storage API `RaftStorage` and Version 2 storage API `RaftLogStorage` both add API `save_committed()` and `read_committed()` to support saving/reading committed log id. These two new API are optional and provides default dummy implementation, an application does not need any modifications if it does not need this feature.
- Loading branch information
1 parent
8626ecf
commit 942ec78
Showing
10 changed files
with
221 additions
and
1 deletion.
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
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,11 @@ | ||
#![cfg_attr(feature = "bt", feature(error_generic_member_access))] | ||
#![cfg_attr(feature = "bt", feature(provide_any))] | ||
|
||
#[macro_use] | ||
#[path = "../fixtures/mod.rs"] | ||
mod fixtures; | ||
|
||
// The number indicate the preferred running order for these case. | ||
// The later tests may depend on the earlier ones. | ||
|
||
mod t10_save_committed; |
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,46 @@ | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
|
||
use anyhow::Result; | ||
use maplit::btreeset; | ||
use openraft::storage::RaftLogStorage; | ||
use openraft::testing::log_id; | ||
use openraft::Config; | ||
|
||
use crate::fixtures::init_default_ut_tracing; | ||
use crate::fixtures::RaftRouter; | ||
|
||
/// Before applying log, write `committed` log id to log store. | ||
#[async_entry::test(worker_threads = 4, init = "init_default_ut_tracing()", tracing_span = "debug")] | ||
async fn write_committed_log_id_to_log_store() -> Result<()> { | ||
let config = Arc::new( | ||
Config { | ||
enable_tick: 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,2}, btreeset! {}).await?; | ||
|
||
log_index += router.client_request_many(0, "0", 10).await?; | ||
|
||
for i in [0, 1, 2] { | ||
router.wait(&i, timeout()).log(Some(log_index), "write logs").await?; | ||
} | ||
|
||
for id in [0, 1, 2] { | ||
let (_, mut ls, _) = router.remove_node(id).unwrap(); | ||
let committed = ls.read_committed().await?; | ||
assert_eq!(Some(log_id(1, 0, log_index)), committed, "node-{} committed", id); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn timeout() -> Option<Duration> { | ||
Some(Duration::from_millis(1000)) | ||
} |