Let's look at the specification of the consensus problem again.
The distributed consensus problem: Each agent in a system proposes a value; the problem is to develop an algorithm by which all agents agree on a single value chosen among the proposed values. The algorithm has the following requirements:
Specification of the Paxos Algorithm Paxos is a distributed consensus algorithm that guarantees validity and agreement, but not termination.
The Paxos algorithm was constructed by Leslie Lamport.
The FLP theorem says that distributed consensus is impossible in a system where messages are arbitrarily slow and an agent may halt. This class describes the Paxos algorithm in which agents may never decide on a consensus value. The algorithm does guarantee validity and agreement. If agents decide on a value then (consensus) all agents decide on the same value and (validity) that value is one of the proposed values.
The Paxos fault model allows more faults than the FLP theorem assumes. Messages may get lost, duplicated, delayed for arbitrary durations, and delivered out of order. An arbitrary number of agents may halt (not just one) as FLP assumes. Agents may halt and then restart, and agents may operate at arbitrary speeds.
We begin by describing serializability of transactions in Paxos and then describe the Paxos algorithm.
Why serializability Serializability of transactions allow us to prove properties of a distributed algorithm, Paxos, by proving properties of a sequential for loop. Proving correctness is easier for sequential programs than for concurrent programs.
Consider a system that executes transactions - at this point it doesn't matter what a transaction is. Each step in a computation is associated with a single transaction.
The figure below shows a computation with two transactions blue and red. The color of each event identifies the transaction to which the event belongs. A dotted message line indicates a message that is sent but is lost. Lost messages play no part in a computation and are ignored when determining whether a computation is serializable.
The transactions in this computation are serializable because the events can be partitioned into sets past_0, past_1, past_2 where past_1 consists of all blue steps and past_2 consists of all blue and red steps.
The computation in the top diagram has steps of the two transactions interspersed — some red steps occur before some blue steps and some blue steps occur before some red steps.
The lower diagram is obtained from the top diagram by permuting steps so that all blue steps occur before all red steps. The order of steps between different agents is permuted, but the order of steps at each agent is the same in both graphs. The curvilinear cuts of the top computation are vertical lines in the lower computation.
The next two figures show transactions that are not serializable. If past_1 consists of all blue steps and no red ones, then there is an edge from the future to the past. Similarly, the for the case where past_1 consists of all red steps and no blue ones.
The proof that these conditions are sufficient for serializability is that the computation can be partitioned into a sequence of consistent cuts where each cut separates steps of transactions with smaller ids from steps of transactions with larger ids.
In figure 1, the blue transaction has a smaller id than the red transaction, and in the computation of each of the five agents: all blue events occur before all red events. In figure 2 and 3, there are some agents with computations in which red events occur before blue, and there are other agents with computations in which blue events occur before red.
Each transaction is associated with a transaction id which is a pair: (n, X) where n is a number and X is agent the agent that starts the transaction. Assume that agents are totally ordered; so transaction ids are totally ordered with (n, X) < (m, Y) if n < m or if n = m and X < Y.
Rule 1 An agent executes at most one transaction at a time. When an agent starts a new transaction it sets the id of the new transaction to be greater than the id of transactions that it has executed.
Rule 2 When an agent executing a transaction with id T sends a message it appends T to the message.
Rule 3 An agent executing a transaction with id T ignores a message with transaction id T' if T' < T; the message is treated as lost.
Example Assume transaction ordering: green -> blue -> red
Rule 4 When an agent executing a transaction with id T receives a message in a transaction with id T' where T' > T, the agent stops executing the transaction with id T and starts executing the transaction with id T'.
Example Transaction ordering, green -> blue -> red
Observation The four rules guarantee that transactions are serializable.
Proof: Transaction ids for successive events at an agent are nondecreasing, and messages sent in a transaction with id T are received in a transaction with id T. Define past as the set of events with transaction id less than or equal to T. Then all edges to past are from past.
When transactions of a computation are serializable, the dataflow graph is one in which transactions are executed sequentially. So, the computation of each agent is the same as one obtained by executing the following loop where L is the list of transaction ids in increasing order.
for i in L: execute transaction with id i
Instead of studying computations in which events from different transactions may be interspersed we need only study computations in which transactions are executed sequentially. We can determine the state of each agent after each step in any computation by determining the state in the corresponding sequential computation.