一致性算法之一:paxos 文章汇总

强一致性

建议按顺序读。 不然会难懂。

如果Proposer只有一个(leader),那么是就是fast paxos, 避免活锁,但是需要leader选举。 fast paxos如果只能提交一个协议而且是所有节点(而不是一个多数派) 而且第一阶段就提供value就变成了两阶段提交协议。

paxos算法的关键是:两阶段提供了锁和商量的机制,多数派概念支持了冲突中的一致性。


1. 介绍的比较全面中国人最容易懂的paxos:

算法原理:http://blog.csdn.net/chen77716/article/details/6166675

算法过程: http://blog.csdn.net/chen77716/article/details/6170235

实现探讨:http://blog.csdn.net/chen77716/article/details/6172392


2. 中文wiki  //例子中有错误,prepare阶段提交的proposal是没有value的,但是例子里讲prepare阶段有value而且返回了另一个proposer。

http://zh.wikipedia.org/wiki/Paxos%E7%AE%97%E6%B3%95


3.  英文wiki上,比较全面科学的

http://en.wikipedia.org/wiki/Paxos_%28computer_science%29


4. 权威原著

http://research.microsoft.com/en-us/um/people/lamport/pubs/pubs.html#lamport-paxos


5.  基于活锁,所以采用Fast Paxos

http://blog.csdn.net/chen77716/article/details/7297122


6. 但是Fast Paxos 需要选举leader, leader 选举采用 paxos lease,下面链接介绍 paxos lease, 而且T时间内不可用. 但是SVC 没有采用这么复杂的leader选举。

http://blog.csdn.net/chen77716/article/details/6265394


7. zookeeper的leader选举使用paxos, 但是一致性使用两阶段提交。 所以参考一下文章了解paxos如何选举 leader。

http://shuofenglxy.iteye.com/blog/1188422


 paxos 例子chubby:

http://www.dedecms.com/knowledge/data-base/nosql/2012/0820/9063.html


//软件实现分析

http://www.docin.com/p-558552752.html


Disk paxos and paxos in IBM svc/v7000 is also example.  

My colleague of Paxos of SVC/V7000, google chubby author was his mentee.


others

paxos simple:

http://blog.csdn.net/sparkliang/article/details/5740882


Paxos cheap:  you can search by yourself



基本思想:

Basic Paxos

This protocol is the most basic of the Paxos family. Each instance of the Basic Paxos protocol decides on a single output value. The protocol proceeds over several rounds. A successful round has two phases. A Proposer should not initiate Paxos if it cannot communicate with at least a Quorum of Acceptors:

Phase 1a: Prepare

A Proposer (the leader) creates a proposal identified with a number N. This number must be greater than any previous proposal number used by this Proposer. Then, it sends a Prepare message containing this proposal to a Quorum of Acceptors. The Proposer decides who is in the Quorum.

Phase 1b: Promise

If the proposal's number N is higher than any previous proposal number received from any Proposer by the Acceptor, then the Acceptor must return a promise to ignore all future proposals having a number less than N. If the Acceptor accepted a proposal at some point in the past, it must include the previous proposal number and previous value in its response to the Proposer.
Otherwise, the Acceptor can ignore the received proposal. It does not have to answer in this case for Paxos to work. However, for the sake of optimization, sending a denial ( Nack) response would tell the Proposer that it can stop its attempt to create consensus with proposal N.

Phase 2a: Accept Request

If a Proposer receives enough promises from a Quorum of Acceptors, it needs to set a value 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 to the value associated with the highest proposal number reported by the Acceptors. If none of the Acceptors had accepted a proposal up to this point, then the Proposer may choose any value for its proposal. [17]
The Proposer sends an Accept Request message to a Quorum of Acceptors with the chosen value for its proposal.

Phase 2b: Accepted

If an Acceptor receives an Accept Request message for a proposal N, it must accept it if and only if it has not already promised to only consider proposals having an identifier greater than N. In this case, it should register the corresponding value v and send an Accepted message to the Proposer and every Learner. Else, it can ignore the Accept Request.
Rounds fail when multiple Proposers send conflicting Prepare messages, or when the Proposer does not receive a Quorum of responses ( Promise or Accepted). In these cases, another round must be started with a higher proposal number.
Notice that when Acceptors accept a request, they also acknowledge the leadership of the Proposer. Hence, Paxos can be used to select a leader in a cluster of nodes.
Here is a graphic representation of the Basic Paxos protocol. 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.


Learn学习决议时,还有一个重要的问题就是要按顺序学习,之前的选举算法花费很多精力就是为了给所有的proposal全局编号,目的是能被按顺序使用。但learn收到的决议的顺序可能不不一致,有可能先收到10号决议,但9号还未到,这时必须等9号到达,或主动向acceptor去请求9号决议,之后才能学习9号、10号决议。


在学习的过程中,遇到的第一个问题就是learn如何知道决议已被选出,简单的做法就是每个批准proposal的acceptor都告诉每个需要学习的learn,但这样的通信量非常大。简单的优化方式就是只告诉一个learn,让这个唯一learn通知其他learn,这样做的好是减少了通信量,但坏处同样明显,会形成单点;当然折中方案是告诉一小部分learn,复杂性是learn之间又会有分布式的问题。因此优化的问题缩减为一个还是多个learn的问题

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值