Before starting the cluster, the config file should contain the details of all the nodes (either online or offline).
Below is the explanation of each config:
id
: Id of the nodename
: Name of the nodeinitProposeDelay
: Delay in seconds before initiating election just after startupport
: Port to which this node will bind toresponseTiming
: Below are the categories of members: 6.IMMEDIATE
: No delay in processing events 7.MEDIUM
: Delay of 200 ms to 2 seconds 8.LATE
: Delay of 200 ms to 5 seconds 9.NEVER
: Max long valueprofile
: Below are the categories of profiles:FOLLOWER
: Participates in voting but never initiates electionCANDIDATE
: Participates in voting and can initiate election
Sample config files for each node can be found in
config
directory
If the cluster is going to have
N
nodes then themembers
key should contain the connection details of all theN
nodes
To run and simulate the election follow the below steps:
-
Run this command (Assuming Linux system)
./mvnw clean install
This will create the jar in the
target
directory -
All the nodes run separately and bind to different socket.
-
Open
N
no. of terminals forN
no. of nodes -
Execute the following command:
java -jar target/paxos-suburbs-council-election-1.0-SNAPSHOT.jar file:///path/to/config/file_for_that_node.json
Substitute the location of config file of that node in the 1st argument
-
Paxos implementation should work when two candidates initiate election at the same time.
-
Paxos implementation should work when all the members have
IMMEDIATE
response times -
Paxos implementation should work when all them members have various
PROFILES
and fewCANDIDATES
stops or disconnects afterPREPARE
phase -
Few things to observe in logs to confirm that algorithm works:
a. All the nodes must have same state (eventually after some delay due to different response times)
b. All the
PREPARE
,PREPROMISE,
PROMISE
,REJECT
,ACCEPT
,PREACCEPTED
,ACCEPTED
phases are properly logged from which node to which node.c. Nodes with
LATE
response times eventually becomes consistent with other members -
All the methods in the code is documented for better understanding of the flow
-
Paxos algorithm works with
N
number of nodes with all the 4 response time categories -
Fast Byzantine Paxos implementation that works when members lie, collude, or intentionally do not participate in some voting queries but participate in others
a. Confirmation regarding working of Byzantine algorithm can be made by observing logs.
b. As per the algorithm, to handle
M
byzantine faults you need to have minimum of 5M+1 nodes.c. If a malicious candidate lies, it won't be taken into consideration as majority is achieved by correct nodes.
d. If a malicious candidate does not participate does not participate, consensus will still be achieved as no. of correct nodes are in majority.
e.
PREPROMISE
andPREACCEPT
messages are used to majority votes on the intention of the proposer, so if the malicious node tries to corrupt the state, it can't because the majority will never be achieved.Important node: All the nodes send `heartbeats` to each other. For keeping logs clean only `info` logs are displayed. To view the `heartbeats` please change the log level from `trace` to `info` in the source code.