Class RaftInvariantChecker
Provides static methods to validate Raft invariants: - Election Safety: at most one leader per term - Log Matching: if two logs have the same entry at an index, all preceding entries are identical - Leader Completeness: committed entries persist in leaders of higher-numbered terms - Commit Index Monotonicity: commitIndex never decreases - Term Monotonicity: currentTerm never decreases
All methods return an InvariantResult record with the validation status and violation message.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult of an invariant check. -
Method Summary
Modifier and TypeMethodDescriptioncheckCommitIndexMonotonicity(long oldIndex, long newIndex) Check Commit Index Monotonicity: commitIndex never decreases.checkElectionSafety(List<RaftNode> nodes) Check Election Safety: at most one leader per term across a list of nodes.checkFencingTokenMonotonicity(long oldToken, long newToken) Check Fencing Token Monotonicity: a fencing token never decreases.checkLeaderCompleteness(RaftNode leader, long commitIndex) Check Leader Completeness: if a log entry is committed, it is present in logs of all current and future leaders.checkLogMatching(RaftLog log1, RaftLog log2) Check Log Matching Property: if two logs contain an entry with the same index and term, all entries preceding that index are identical.Check State Machine Safety (basic): verify that the same state machine entry is not applied at the same index with different commands.checkTermMonotonicity(long oldTerm, long newTerm) Check Term Monotonicity: currentTerm never decreases.
-
Method Details
-
checkElectionSafety
Check Election Safety: at most one leader per term across a list of nodes.Verifies that for any given term, at most one node claims to be the leader.
- Parameters:
nodes- non-null list of RaftNode instances- Returns:
- InvariantResult with validation status
- Throws:
NullPointerException- if nodes is null
-
checkLogMatching
Check Log Matching Property: if two logs contain an entry with the same index and term, all entries preceding that index are identical.Compares two logs entry-by-entry up to the minimum last index.
- Parameters:
log1- first RaftLoglog2- second RaftLog- Returns:
- InvariantResult with validation status
- Throws:
NullPointerException- if either log is null
-
checkCommitIndexMonotonicity
public static RaftInvariantChecker.InvariantResult checkCommitIndexMonotonicity(long oldIndex, long newIndex) Check Commit Index Monotonicity: commitIndex never decreases.Verifies that oldIndex invalid input: '<'= newIndex.
- Parameters:
oldIndex- previous commitIndex valuenewIndex- new commitIndex value- Returns:
- InvariantResult with validation status
-
checkTermMonotonicity
public static RaftInvariantChecker.InvariantResult checkTermMonotonicity(long oldTerm, long newTerm) Check Term Monotonicity: currentTerm never decreases.Verifies that oldTerm invalid input: '<'= newTerm.
- Parameters:
oldTerm- previous currentTerm valuenewTerm- new currentTerm value- Returns:
- InvariantResult with validation status
-
checkFencingTokenMonotonicity
public static RaftInvariantChecker.InvariantResult checkFencingTokenMonotonicity(long oldToken, long newToken) Check Fencing Token Monotonicity: a fencing token never decreases.- Parameters:
oldToken- previous fencing token valuenewToken- new fencing token value- Returns:
- InvariantResult with validation status
-
checkLeaderCompleteness
public static RaftInvariantChecker.InvariantResult checkLeaderCompleteness(RaftNode leader, long commitIndex) Check Leader Completeness: if a log entry is committed, it is present in logs of all current and future leaders.For a leader, verifies that all entries up to commitIndex are present in its log.
Note: This is a basic check. Full verification requires examining multiple leaders across term transitions, which is tested in integration scenarios.
- Parameters:
leader- the RaftNode claiming leadershipcommitIndex- the leader's commitIndex- Returns:
- InvariantResult with validation status
- Throws:
NullPointerException- if leader is null
-
checkStateMachineSafety
Check State Machine Safety (basic): verify that the same state machine entry is not applied at the same index with different commands.This is a simplified version that checks entry consistency in the log. Full state machine safety requires external tracking of applied commands.
- Parameters:
log- the RaftLog to check- Returns:
- InvariantResult with validation status
- Throws:
NullPointerException- if log is null
-