-
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.
Improve: loosen validity check with RaftState.snapshot_last_log_id()
A application may not persist snapshot. And when it restarted, the last-purged-log-id is not `None` but `snapshot_last_log_id()` is None. This is a valid state and should not emit error.
- Loading branch information
1 parent
0f80be9
commit 664635e
Showing
3 changed files
with
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use crate::engine::LogIdList; | ||
use crate::validate::Validate; | ||
use crate::CommittedLeaderId; | ||
use crate::LogId; | ||
use crate::RaftState; | ||
use crate::SnapshotMeta; | ||
|
||
fn log_id(term: u64, index: u64) -> LogId<u64> { | ||
LogId::<u64> { | ||
leader_id: CommittedLeaderId::new(term, 0), | ||
index, | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_raft_state_validate_snapshot_is_none() -> anyhow::Result<()> { | ||
// Some app does not persist snapshot, when restarted, purged is not None but snapshot_last_log_id | ||
// is None. This is a valid state and should not emit error. | ||
|
||
let rs = RaftState::<u64, ()> { | ||
log_ids: LogIdList::new(vec![log_id(1, 1), log_id(3, 4)]), | ||
purged_next: 2, | ||
purge_upto: Some(log_id(1, 1)), | ||
committed: Some(log_id(1, 1)), | ||
snapshot_meta: SnapshotMeta::default(), | ||
..Default::default() | ||
}; | ||
|
||
assert!(rs.validate().is_ok()); | ||
|
||
Ok(()) | ||
} |