zk 两阶段提交(待完善)

选举结束后,leader 和 follower 各自执行自己的逻辑:

org.apache.zookeeper.server.quorum.QuorumPeer#run

leader

org.apache.zookeeper.server.quorum.QuorumPeer#setLeader
// 构建 processor 链
org.apache.zookeeper.server.quorum.LeaderZooKeeperServer#setupRequestProcessors
// PrepRequestProcessor, ProposalRequestProcessor, CommitProcessor, ToBeAppliedRequestProcessor, FinalRequestProcessor
org.apache.zookeeper.server.quorum.Leader#lead

follower

org.apache.zookeeper.server.quorum.QuorumPeer#setFollower
// 构建 processor 链
org.apache.zookeeper.server.quorum.FollowerZooKeeperServer#setupRequestProcessors
// 链1:FollowerRequestProcessor, CommitProcessor, FinalRequestProcessor
// 链2:SyncRequestProcessor, SendAckRequestProcessor
org.apache.zookeeper.server.quorum.Follower#followLeader

leader 发送建议给 follower

org.apache.zookeeper.server.quorum.LearnerHandler#sendPackets

follower 接收并处理 leader 发送的建议

org.apache.zookeeper.server.quorum.Follower#processPacket
// SyncRequestProcessor 写入事务日志
org.apache.zookeeper.server.SyncRequestProcessor#run

// 发送 ACK 给 leader
org.apache.zookeeper.server.quorum.SendAckRequestProcessor#processRequest

leader 接收并处理 follower 的请求

org.apache.zookeeper.server.quorum.LearnerHandler#run
// ack 超过半数,则把写操作应用到状态机,并向 follower 发送提交事件
org.apache.zookeeper.server.quorum.Leader#processAck

follower 提交写操作

CommitProcessor 和 FinalRequestProcessor

上一篇:zookeeper启动:Could not find or load main class org.apache.zookeeper.server.quorum.


下一篇:5105 pa3 Distributed File System based on Quorum Protocol