Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Each server stores a term number called currentTerm. This indicates the most recent term that has been seen by this server.
  • Every log entry contains the term in which the entry was created. When a server starts up, it sets currentTerm to the term from the last entry in its log; if the log is empty, currentTerm is initialized to 0.
  • Every message from server to server contains the term of the sender, plus an indication whether the sender is a candidate or leader (passive servers never issue requests). This value (call it senderTerm) is used to update currentTerm and to detect out-of-data servers:
    • senderTerm < currentTerm: reject the message with an indication that the sender is out of date; the rejection also includes currentTerm. When the sender receives the rejection it updates its currentTerm to match the one in the response, then passivates. This makes sense for leaders because it means their term of leadership is over. This also make sense for candidates because it means there is already a new election cycle with other active candidates; there is no need for the sender to participate.
    • senderTerm == currentTerm: process the request normally.
    • senderTerm > currentTerm: set currentTerm to senderTerm. If the recipient is currently a leader or candidate, then it passivates. Finally, it processes the request.
  • When a server switches from passive to candidate, it increments currentTerm to force a new election cycle.

Requests

Here is a complete list of all requests sent between servers in ALPO:

appendEntry(entry, prevTerm): add entry to the local log, assuming that entry properly follows the last entry currently in the log.

heartbeat(currentTerm, lastLogId, lastTerm): used to inform passive servers that there is a leader and that the leader is alive and well. The lastlogId and lastTerm arguments specify the id and term from the leader's last log entry; if these don't match the last log entry in the recipient, then it returns the id and term from its last log entry so that leader can replay missing entries.

requestVote(term, lastLogId, lastTerm): used by a candidate to request another server's vote for term. lastLogId and lastTerm specify the id and term from the sender's last log entry; if either of the recipient's corresponding items is larger then it means the sender's log is not complete enough for it to become the new leader.

State for each server

  • currentTerm: number of the most recent term seen by this server.
  • Vote: the server id and log length of the candidate who has received this server's vote for currentTerm (if any).
  • Server id of this server.
  • Log entries that have been accepted by the server.
  • Id of the most recent log entry that has been fully replicated.
  • Time of receipt of the last request from the leader.
  • Cluster map: id and location of each server in the cluster, whether dead or alive.

...