This protocol is the most basic of the Paxos family. Each "instance" (or "execution") of the basic Paxos protocol decides on a single output value. The protocol proceeds over several rounds. A successful round has 2 phases: phase 1 (which is divided into parts
a and
b) and phase 2 (also divided into parts
a and
b). See below the description of the phases. Remember that we assume an asynchronous model, so e.g. a processor may be in one phase while another processor may be in another.
Phase 1 Phase 1a: Prepare : A
Proposer creates a message, which we call a
Prepare. The message is identified with a unique number,
n, which must be greater than any number previously used in a Prepare message by this Proposer. Note that
n is not the value to be proposed; it is simply a unique identifier of this initial message by the Proposer. In fact, the Prepare message needn't contain the proposed value (often denoted by
v). : The Proposer chooses at least a Quorum of
Acceptors and sends the Prepare message containing
n to them. A Proposer should not initiate Paxos if it cannot communicate with enough Acceptors to constitute a Quorum.
Phase 1b: Promise : The Acceptors wait for a Prepare message from any of the Proposers. When an Acceptor receives a Prepare message, the Acceptor must examine the identifier number,
n, of that message. There are two cases: • If
n is higher than every previous proposal number received by the Acceptor (from any Proposer), then the Acceptor must return a message (called a
Promise) to the Proposer, indicating that the Acceptor will ignore all future proposals numbered less than or equal to
n. The Promise must include the highest number among the Proposals that the Acceptor previously accepted, along with the corresponding accepted value. The first Prepare message vacuously satisfies this condition. • If
n is less than or equal to any previous proposal number received by the Acceptor, the Acceptor needn't respond and can ignore the proposal. However, for the sake of optimization, sending a denial, or
negative acknowledgement (
NAK), response would tell the Proposer that it can stop its attempt to create consensus with proposal
n.
Phase 2 Phase 2a: Accept : If a Proposer receives Promises from a Quorum of Acceptors, it needs to set a value
v to its proposal. If any Acceptors had previously accepted any proposal, then they'll have sent their values to the Proposer, who now must set the value of its proposal,
v, to the value associated with the highest proposal number reported by the Acceptors, let's call it
z. If none of the Acceptors had accepted a proposal up to this point, then the Proposer may choose the value it originally wanted to propose, say
x. Because of the agreement and validity guarantees of Paxos, if accepted by a Quorum, then the Proposer is now known to be the leader to all other nodes. This satisfies the needs of
leader election because there is a single node believing it is the leader and a single node known to be the leader at all times.
Graphic representation of the flow of messages in the basic Paxos The following diagrams represent several cases/situations of the application of the Basic Paxos protocol. Some cases show how the Basic Paxos protocol copes with the failure of certain (redundant) components of the distributed system. Note that the values returned in the
Promise message are "null" the first time a proposal is made (since no Acceptor has accepted a value before in this round).
Basic Paxos without failures In the diagram below, there is 1 Client, 1 Proposer, 3 Acceptors (i.e. the Quorum size is 3) and 2 Learners (represented by the 2 vertical lines). This diagram represents the case of a first round, which is successful (i.e. no process in the network fails). Here, V is the last of (Va, Vb, Vc).
Error cases in basic Paxos The simplest error cases are the failure of an Acceptor (when a Quorum of Acceptors remains alive) and failure of a redundant Learner. In these cases, the protocol requires no "recovery" (i.e. it still succeeds): no additional rounds or messages are required, as shown below (in the next two diagrams/cases).
Basic Paxos when an Acceptor fails In the following diagram, one of the Acceptors in the Quorum fails, so the Quorum size becomes 2. In this case, the Basic Paxos protocol still succeeds. Client Proposer Acceptor Learner | | | | | | | X-------->| | | | | | Request | X--------->|->|->| | | Prepare(1) | | | | ! | | !! FAIL !! | ||->| | | Accept!(1,V) | ||->| Accepted(1,V) |
Basic Paxos when a redundant learner fails In the following case, one of the (redundant) Learners fails, but the Basic Paxos protocol still succeeds. Client Proposer Acceptor Learner | | | | | | | X-------->| | | | | | Request | X--------->|->|->| | | Prepare(1) | ||->|->| | | Accept!(1,V) | ||->| Accepted(1,V) | | | | | | ! !! FAIL !! |
Basic Paxos when a Proposer fails In this case, a Proposer fails after proposing a value, but before the agreement is reached. Specifically, it fails in the middle of the Accept message, so only one Acceptor of the Quorum receives the value. Meanwhile, a new Leader (a Proposer) is elected (but this is not shown in detail). Note that there are 2 rounds in this case (rounds proceed vertically, from the top to the bottom). Client Proposer Acceptor Learner | | | | | | | X----->| | | | | | Request | X------------>|->|->| | | Prepare(1) | || | | | | Accept!(1,V) | ! | | | | | | | | | | | | !! NEW LEADER !! | X--------->|->|->| | | Prepare(2) | ||->|->| | | Accept!(2,V) | ||->| Accepted(2,V) |
Basic Paxos when multiple Proposers conflict The most complex case is when multiple Proposers believe themselves to be Leaders. For instance, the current leader may fail and later recover, but the other Proposers have already re-selected a new leader. The recovered leader has not learned this yet and attempts to begin one round in conflict with the current leader. In the diagram below, 4 unsuccessful rounds are shown, but there could be more (as suggested at the bottom of the diagram). Client Proposer Acceptor Learner | | | | | | | X----->| | | | | | Request | X------------>|->|->| | | Prepare(1) | ||->|->| | | Prepare(2) | ||->|->| | | Prepare(2) | ||->|->| | | Prepare(3) | ||->|->| | | Accept!(2,Va) | | ||->|->| | | Prepare(4) | | ||->|->| | | Accept!(3,Vb) | |
Basic Paxos where an Acceptor accepts Two Different Values In the following case, one Proposer achieves acceptance of value V1 by one Acceptor before failing. A new Proposer prepares the Acceptors that never accepted V1, allowing it to propose V2. Then V2 is accepted by all Acceptors, including the one that initially accepted V1. Proposer Acceptor Learner | | | | | | | X--------->|->|->| | | Prepare(1) || | | | | Accept!(1,V1) | | X------------>|->| Accepted(1,V1) ! | | | | | | !! FAIL !! | | | | | | X--------->|->| | | Prepare(2) ||->|->| | | Accept!(2,V2) ||->| Accepted(2,V2) | | | | | |
Basic Paxos where a multi-identifier majority is insufficient In the following case, one Proposer achieves acceptance of value V1 of one Acceptor before failing. A new Proposer prepares the Acceptors that never accepted V1, allowing it to propose V2. This Proposer is able to get one Acceptor to accept V2 before failing. A new Proposer finds a majority that includes the Acceptor that has accepted V1, and must propose it. The Proposer manages to get two Acceptors to accept it before failing. At this point, three Acceptors have accepted V1, but not for the same identifier. Finally, a new Proposer prepares the majority that has not seen the largest accepted identifier. The value associated with the largest identifier in that majority is V2, so it must propose it. This Proposer then gets all Acceptors to accept V2, achieving consensus. Proposer Acceptor Learner | | | | | | | | | | | X--------------->|->|->|->|->| | | Prepare(1) || | | | | | | Accept!(1,V1) | | | | X------------------>|->| Accepted(1,V1) ! | | | | | | | | | | !! FAIL !! | | | | | | | | | | X--------------->|->|->|->| | | Prepare(2) || | | | | | Accept!(2,V2) | | | | X--------------->|->| Accepted(2,V2) ! | | | | | | | | | !! FAIL !! | | | | | | | | | X--------->|---->|->|->| | | Prepare(3) ||->| | | | Accept!(3,V1) | | | | X--X--------->|->| Accepted(3,V1) ! | | | | | | | | !! FAIL !! | | | | | | | | X------>|->|------->| | | Prepare(4) ||->|->|->|->| | | Accept!(4,V2) | X--X--X--X--X------>|->| Accepted(4,V2)
Basic Paxos where new Proposers cannot change an existing consensus In the following case, one Proposer achieves acceptance of value V1 of two Acceptors before failing. A new Proposer may start another round, but it is now impossible for that proposer to prepare a majority that doesn't include at least one Acceptor that has accepted V1. As such, even though the Proposer doesn't see the existing consensus, the Proposer's only option is to propose the value already agreed upon. New Proposers can continually increase the identifier to restart the process, but the consensus can never be changed. Proposer Acceptor Learner | | | | | | | X--------->|->|->| | | Prepare(1) ||->| | | | Accept!(1,V1) | | X--X--------->|->| Accepted(1,V1) ! | | | | | | !! FAIL !! | | | | | | X--------->|->| | | Prepare(2) ||->|->| | | Accept!(2,V1) ||->| Accepted(2,V1) | | | | | | == Multi-Paxos ==