diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-20 23:04:48 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-20 23:04:48 +0300 |
| commit | dedec9b18bafa2bcfdb05429f717f95f2236d811 (patch) | |
| tree | 379a6d18ebf95aa552a6bd8722f1b7ebee9f8ca6 /src/main/java/prefs/VSDefaultPrefs.java | |
| parent | 32882ca8582a102b9357e8d7f2c313d52c568977 (diff) | |
Implement Raft consensus algorithm for distributed systems simulator
This commit adds a complete implementation of the Raft consensus algorithm,
providing a robust solution for achieving consensus in distributed systems.
Key features implemented:
- Three-state system: Follower, Candidate, and Leader states
- Leader election with randomized election timeouts (150-300ms)
- Log replication for state machine commands
- Heartbeat mechanism to maintain leader authority
- Safety guarantees through term numbers and log consistency checks
- Proper handling of split votes and network partitions
Implementation details:
- Added VSRaftProtocol.java with full Raft algorithm logic
- Integrated with existing event-driven simulation framework
- Supports dynamic cluster sizes with proper quorum calculations
- Implements RequestVote and AppendEntries RPCs
- Maintains persistent state (currentTerm, votedFor, log entries)
- Includes comprehensive logging for debugging and visualization
Testing:
- Added VSRaftProtocolTest.java with unit tests covering:
- Leader election scenarios
- Log replication mechanics
- State transitions
- Message handling for all RPC types
Integration:
- Registered protocol in VSRegisteredEvents for simulator discovery
- Added human-readable names in VSDefaultPrefs for UI display
- Compatible with existing visualization and timing systems
This implementation follows the Raft paper closely while adapting to
the simulator's event-driven architecture and message-passing model.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'src/main/java/prefs/VSDefaultPrefs.java')
| -rw-r--r-- | src/main/java/prefs/VSDefaultPrefs.java | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/main/java/prefs/VSDefaultPrefs.java b/src/main/java/prefs/VSDefaultPrefs.java index 217144e..aa0b741 100644 --- a/src/main/java/prefs/VSDefaultPrefs.java +++ b/src/main/java/prefs/VSDefaultPrefs.java @@ -180,6 +180,8 @@ public class VSDefaultPrefs extends VSSerializablePrefs { initString("lang.protocols.implementations.VSReliableMulticastProtocol.short", "Reliable Multicast"); initString("lang.protocols.implementations.VSTwoPhaseCommitProtocol", "Two-Phase Commit"); initString("lang.protocols.implementations.VSTwoPhaseCommitProtocol.short", "2-Phase Commit"); + initString("lang.protocols.implementations.VSRaftProtocol", "Raft Consensus Algorithm"); + initString("lang.protocols.implementations.VSRaftProtocol.short", "Raft Consensus"); /* Timestamp event names */ initString("lang.events.implementations.VSLamportTimestampEvent", "Lamport Timestamp Event"); |
