Brendan Ang

Search

Search IconIcon to open search

Consensus

Last updated Feb 16, 2023 Edit Source

# Consensus

Processes propose values and they all have to agree on one of these values.

# Paxos Algorithm

An Eventual Leader Election (weakest leader elector we can use) can be used to eventually elect 1 single proposer (providing termination).

# Abortable Consensus

Algorithm aborts if there is contention of multiple proposers.

# Version 1 (Centralised)

Proposer sends value to a central acceptor. Acceptor decides on the first value which it gets. Problem 1: if this acceptor fails, we will never know of the decision

# Version 2 (Decentralised)

Proposers talk to a set of acceptors, use a majority quorum to choose a value and enable fault tolerance. Problem 2: acceptor accepts the first proposal, if messages arrive out of order, possible to have no majority

# Version 3 (Enable restarts)

If no majority value, we need to restart until there is one. Since proposers can propose again, we need a way to differentiate between them.

# Version 4 (Prepare and Accept)

We need a way to ensure that every higher number proposal results in the same chosen value

  1. Proposer $prepare(n)$:
    • Gets a promise from acceptors not to accept a proposal with lower ballot number n
    • Acceptor also responds with the value corresponding to the highest ballot number proposal
  2. Proposer $accept(n,v)$:
    • Pick the value from the maximum proposal number returned. If none of the processes return a value, proposer can pick freely.
    • Acceptor $accept(n,v)$ if not accepted any $prepare(m)$ such that $m>n$; else $reject$
  3. Proposer $decide(v)$ if majority acks; else $abort$

# Optimisations

# Multi Paxos

The motivation: replicated state machines need to agree on a sequence of commands to execute.

Approach: organise the algorithm into rounds. In each round, each server starts a new instance of Paxos. They propose (2 RTT), accept (2 RTT) and decide on 1 command, add that to the log and restart.

Initial states

# Sequence Consensus

Rather than agreeing on a single command and storing that in a Log, we can directly try to agree on the sequence of commands.

# Log Synchronisation

Modify the prepare phase and shared states such that we can work on a single synchronised log $v_a$. To do this, let 1 process act as the sole leader (proposer) until it is aborted by an election of higher ballot number

# Prepare Phase

The leader sends Prepare:

# Accept Phase

The leader sends Accept command with highest $n$ to all promised followers The followers reply with Accepted When majority accepted, Decide is sent. Any late Promise is replied with an AcceptSync

# Partial Connectivity (enabling quorum connectedness)

Chained scenario: When one server loses connectivity to the leader, it will try to elect itself as a leader. Livelock situation as servers compete to become the leader. Can be solved if A becomes the leader but can’t because it is already connected to a leader. Quorum Loss: When the leader loses quorum connectivity, deadlock situation as a majority cannot be obtained to make progress. B, D, E cannot elect a leader without a quorum. A is quorum connected but cannot elect a new leader since it is still connected to the alive leader C. Constrained Election: Leader is fully disconnected. A can become the new leader but will not be elected as it does not have the most updated log (log length).

# Failure recovery

  1. Recover state from persistent storage
  2. Send a PrepareReq to all peers
    • If elected as leader, synchronise through a Prepare phase
    • Prepare phase from another leader will synchronise

# Reconfiguration

Supporting a way to add/replace any process part of the replicated state machine. A configuration $c_i$ is defined by a set of process ids ${p1, p2, p3}$ and the new configuration can be any new set of processes e.g. ${p1,p2,p4}$

# Stop Sign

To safely stop the current configuration, we must prevent new decisions in the old configuration (“split-brain” problem) using a stop sign: The stop sign contains information about the new configuration to help processes reconfigure:

# Raft

A state of the art consensus algorithm.

# State of servers

Rather than using process ids to break ties for leader election in omnipaxos, Raft uses a form of random retrying when there are split votes.

# Log Reconciliation

A server must have the most up to date log in order to become a leader, compared to omni-paxos where any server can be the leader and be synced up during the Prepare phase.