forked from ongardie/raft-pseudocode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.py
More file actions
31 lines (30 loc) · 991 Bytes
/
state.py
File metadata and controls
31 lines (30 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#*\codetitle{server state}*\#
# FOLLOWER, CANDIDATE, or LEADER
state := FOLLOWER
# latest term server has seen (increases monotonically)
currentTerm := 1
# candidate that received vote in current term
votedFor := None
# log entries; each entry contains command for state
# machine, and term when entry was received by leader
log := [] # indexed from 1
# index of highest log entry known to be committed
commitIndex := 0
# time after which to start new election
electionAlarm := 0.0
# applies committed commands in log order
stateMachine := new SM()
# identity of last known leader
leader := None
# State per peer, valid only for the current term
foreach peer:
| # time after which to send another RPC
| # (RequestVote or heartbeat)
| rpcDue[peer] := 0.0
| # True if peer has granted this server its vote
| voteGranted[peer] := False
| # index of highest log entry known to be replicated
| # on peer
| matchIndex[peer] := 0
| # index of next log entry to send to peer
| nextIndex[peer] := 1