From dedec9b18bafa2bcfdb05429f717f95f2236d811 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 20 Jun 2025 23:04:48 +0300 Subject: Implement Raft consensus algorithm for distributed systems simulator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/main/java/events/VSRegisteredEvents.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main/java/events') diff --git a/src/main/java/events/VSRegisteredEvents.java b/src/main/java/events/VSRegisteredEvents.java index 92deeb0..91000bc 100644 --- a/src/main/java/events/VSRegisteredEvents.java +++ b/src/main/java/events/VSRegisteredEvents.java @@ -99,6 +99,7 @@ public final class VSRegisteredEvents { registerEvent("protocols.implementations.VSReliableMulticastProtocol"); registerEvent("protocols.implementations.VSTwoPhaseCommitProtocol"); registerEvent("protocols.implementations.VSTimestampDemoProtocol"); + registerEvent("protocols.implementations.VSRaftProtocol"); /* Make dummy objects of each protocol, to see if they contain VSPrefs values to edit */ -- cgit v1.2.3