Paxos协议/算法是分布式系统中比较重要的协议,它有多重要呢?
<分布式系统的事务处理>:
Google Chubby的作者MikeBurrows说过这个世界上只有一种一致性算法,那就是Paxos,其它的算法都是残次品。
<分布式存储系统>:
理解了这两个分布式协议之后(Paxos/2PC),学习其他分布式协议会变得相当容易。
学习Paxos算法有两部分:a) 算法的原理/证明;b) 算法的理解/运作。
理解这个算法的运作过程其实基本就可以用于工程实践。而且理解这个过程相对来说也容易得多。paxos协议
网上我觉得讲Paxos讲的好的属于这篇:paxos图解及Paxos算法详解,我这里就结合wiki上的实例进一步阐述。一些paxos基础通过这里提到的两篇文章,以及wiki上的内容基本可以理解。
Paxos在原作者的《Paxos Made Simple》中内容是比较精简的:
Phase 1
(a) A proposer selects a proposal number n and sends a preparerequest with number n to a majority of acceptors.
(b) If an acceptor receives a prepare request with number n greaterthan that of any prepare request to which it has already responded,then it responds to the request with a promise not to accept anymore proposals numbered less than n and with the highest-numberedpro-posal (if any) that it has accepted.
Phase 2
(a) If the proposer receives a response to its prepare requests(numbered n) from a majority of acceptors, then it sends an acceptrequest to each of those acceptors for a proposal numbered n with avalue v , where v is the value of the highest-numbered proposalamong the responses, or is any value if the responses reported noproposals.
(b) If an acceptor receives an accept request for a proposalnumbered n, it accepts the proposal unless it has already respondedto a prepare request having a number greater than n.
paxos的处理流程可概括为:

Paxos中有三类角色Proposer、Acceptor及Learner,主要交互过程在Proposer和Acceptor之间。
Proposer与Acceptor之间的交互主要有4类消息通信,如下图:

这4类消息对应于paxos算法的两个阶段4个过程:
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-29830-1.html
泄浊屎