diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-22 11:58:00 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-22 11:58:00 +0300 |
| commit | 0b5afe8839241dec66ba832cf42860ec69b87df8 (patch) | |
| tree | e100d2d6204f8c04dc33418ae9f193fa6b1a83c2 /saved-simulations | |
| parent | b0fc02ce45cb51ce7c8d607d4773808cfa9b6c87 (diff) | |
Fix message delivery in headless test environment
- Fixed HeadlessSimulationEngine to use correct task manager from receiving process
- Reduced message delays for testing (10-50ms instead of 500-2000ms)
- Fixed process ID method call (getProcessID not getProcessId)
- Improved message delivery scheduling to ensure tasks go to the right task manager
This resolves message delivery issues where messages were sent but not received.
BasicMulticast test now passes, but 12 protocol tests still failing.
🤖 Generated with Claude Code
https://claude.ai/code
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'saved-simulations')
| -rw-r--r-- | saved-simulations/README-raft.md | 129 | ||||
| -rw-r--r-- | saved-simulations/README-raft.txt | 28 | ||||
| -rw-r--r-- | saved-simulations/raft-consensus.dat | bin | 19962 -> 0 bytes | |||
| -rw-r--r-- | saved-simulations/raft-fault-tolerant.dat | bin | 0 -> 18305 bytes | |||
| -rw-r--r-- | saved-simulations/raft-simple.dat | bin | 23654 -> 0 bytes | |||
| -rw-r--r-- | saved-simulations/raft-verified.dat | bin | 23654 -> 0 bytes | |||
| -rw-r--r-- | saved-simulations/raft-with-clients.dat | bin | 0 -> 16754 bytes | |||
| -rw-r--r-- | saved-simulations/raft-working.dat | bin | 27595 -> 0 bytes | |||
| -rw-r--r-- | saved-simulations/raft.dat | bin | 0 -> 13759 bytes |
9 files changed, 129 insertions, 28 deletions
diff --git a/saved-simulations/README-raft.md b/saved-simulations/README-raft.md new file mode 100644 index 0000000..a9d3e83 --- /dev/null +++ b/saved-simulations/README-raft.md @@ -0,0 +1,129 @@ +# Raft Consensus Simulation + +## Current Status + +The `raft.dat` file exists but is currently a copy of `ping-pong.dat` and needs to be properly configured with Raft protocol events through the GUI. + +## Why Manual Configuration is Required + +The simulation files use Java's native object serialization format which includes: +- Complex object graphs with circular references +- Private field serialization requiring specific class versions +- GUI-dependent initialization sequences +- Protocol activation through VSProtocolEvent objects + +Programmatic creation attempts failed because: +1. VSSerialize methods require GUI components +2. VSSimulatorVisualization has private methods for process creation +3. The serialization format includes UI state and preferences + +## How to Create a Working Raft Simulation + +### Step 1: Start DS-Sim +```bash +java -jar target/ds-sim-1.0.1-SNAPSHOT.jar +``` + +### Step 2: Create New Simulation +- File → New (or Ctrl+N) +- This creates a blank simulation + +### Step 3: Add Processes +- Click "Add Process" button 3 times +- This creates a 3-node Raft cluster + +### Step 4: Configure Each Process as Raft Server +For each process (Process 1, 2, and 3): +- Right-click on the process +- Select "Protocols" → "Raft Consensus Algorithm" → "Server" +- You'll see a protocol activation event added to the task list + +### Step 5: Set Simulation Duration +- Edit → Preferences → Simulator +- Set "Simulation duration" to 15000 (15 seconds) +- Click OK + +### Step 6: Save the Simulation +- File → Save As +- Navigate to `saved-simulations/` +- Save as `raft.dat` + +### Step 7: Run the Simulation +- Click the Play button (▶) +- Watch the leader election process + +## Expected Behavior + +### Time 0-300ms: Initial State +- All nodes start as FOLLOWERS +- Each sets a random election timeout (150-300ms) +- Status: "FOLLOWER" shown in logs + +### Time 150-500ms: Election Phase +- First node to timeout transitions to CANDIDATE +- Increments term to 1 +- Sends REQUEST_VOTE messages to all other nodes +- Other nodes respond with VOTE_RESPONSE messages + +### Time 300-600ms: Leader Establishment +- Candidate receiving majority votes becomes LEADER +- Leader node is highlighted in the visualization +- Begins sending APPEND_ENTRIES (heartbeat) messages + +### Time 600ms+: Steady State +- Leader sends heartbeats every 50ms +- Followers acknowledge with APPEND_RESPONSE +- If leader fails, new election begins after timeout + +## Verification + +### GUI Verification +1. Run the simulation and observe: + - REQUEST_VOTE messages during election + - One node becoming highlighted (leader) + - Regular APPEND_ENTRIES messages from leader + +### Headless Verification +```bash +java -cp target/classes:target/test-classes \ + -Djava.awt.headless=true \ + -Dds.sim.verbose=true \ + testing.HeadlessProtocolRunner saved-simulations/raft.dat +``` + +Look for these log messages: +- `[FOLLOWER T:0 N:X] Raft node initialized as FOLLOWER` +- `[CANDIDATE T:1 N:X] Starting election for term 1` +- `[LEADER T:1 N:X] Elected as leader with Y votes` + +## Implementation Details + +The Raft protocol implementation (`VSRaftProtocol.java`) includes: + +- **State Machine**: FOLLOWER → CANDIDATE → LEADER transitions +- **Election Timeout**: Random 150-300ms to prevent split votes +- **Heartbeat Interval**: 50ms from leader to maintain authority +- **Term Management**: Monotonically increasing terms for safety +- **Vote Tracking**: Majority (n/2 + 1) required for leadership +- **Message Types**: + - REQUEST_VOTE: Candidate requests votes + - VOTE_RESPONSE: Follower grants/denies vote + - APPEND_ENTRIES: Leader heartbeat/log replication + - APPEND_RESPONSE: Follower acknowledgment + +## Troubleshooting + +If the simulation shows no Raft activity: +1. Verify all processes have Raft protocol events in task list +2. Check that events are scheduled at time 0 +3. Ensure simulation duration is > 5 seconds +4. Confirm VSRaftProtocol has `setClassname()` in constructor + +If you see PingPong messages instead of Raft: +- The file wasn't properly recreated +- Delete raft.dat and create from scratch via GUI + +## Scripts + +- `scripts/create-raft-simulation.sh` - Creates template and instructions +- `scripts/analyze-raft-simulation.sh` - Diagnoses simulation issues
\ No newline at end of file diff --git a/saved-simulations/README-raft.txt b/saved-simulations/README-raft.txt deleted file mode 100644 index 54b2059..0000000 --- a/saved-simulations/README-raft.txt +++ /dev/null @@ -1,28 +0,0 @@ -RAFT CONSENSUS SIMULATION -======================== - -This directory contains Raft consensus protocol simulations: - -1. raft-working.dat - Full working simulation with: - - 3 Raft servers (processes 0-2) - - 2 Raft clients (processes 3-4) - - Server crash/recovery events - -To run the simulation: -1. java -jar target/ds-sim-1.0.1-SNAPSHOT.jar -2. File → Open → saved-simulations/raft-working.dat -3. Click Run (▶) button - -What to look for: -- Leader election (REQUEST_VOTE messages) -- Heartbeats from leader (APPEND_ENTRIES) -- Client requests and responses -- Re-election when servers crash - -Timeline: -- Time 0: Servers start, begin leader election -- Time 500-700: Clients start -- Time 2000: Server 0 crashes -- Time 3000: Server 0 recovers -- Time 4000: Server 1 crashes -- Time 5000: Server 1 recovers diff --git a/saved-simulations/raft-consensus.dat b/saved-simulations/raft-consensus.dat Binary files differdeleted file mode 100644 index 37deac7..0000000 --- a/saved-simulations/raft-consensus.dat +++ /dev/null diff --git a/saved-simulations/raft-fault-tolerant.dat b/saved-simulations/raft-fault-tolerant.dat Binary files differnew file mode 100644 index 0000000..c2981d9 --- /dev/null +++ b/saved-simulations/raft-fault-tolerant.dat diff --git a/saved-simulations/raft-simple.dat b/saved-simulations/raft-simple.dat Binary files differdeleted file mode 100644 index 30d2c09..0000000 --- a/saved-simulations/raft-simple.dat +++ /dev/null diff --git a/saved-simulations/raft-verified.dat b/saved-simulations/raft-verified.dat Binary files differdeleted file mode 100644 index 763f3e7..0000000 --- a/saved-simulations/raft-verified.dat +++ /dev/null diff --git a/saved-simulations/raft-with-clients.dat b/saved-simulations/raft-with-clients.dat Binary files differnew file mode 100644 index 0000000..a7c579e --- /dev/null +++ b/saved-simulations/raft-with-clients.dat diff --git a/saved-simulations/raft-working.dat b/saved-simulations/raft-working.dat Binary files differdeleted file mode 100644 index 321dc84..0000000 --- a/saved-simulations/raft-working.dat +++ /dev/null diff --git a/saved-simulations/raft.dat b/saved-simulations/raft.dat Binary files differnew file mode 100644 index 0000000..f87edd8 --- /dev/null +++ b/saved-simulations/raft.dat |
