系列文章目录
【zookeeper核心源码解析】第一课:zk启动类核心流程序列图
1. zk 启动核心流程序列图
QueermpeerMain核心代码start()方法:
@Override
public synchronized void start() {
loadDataBase();
cnxnFactory.start(); //绑定2181
startLeaderElection();
super.start();
}
序列图如下:

2、启动流程说明
- 进程入口类: QuermpeerMain,从mian方法开始找
- 主要初始化QuorumPeer,该类三个核心方法, start() ,该类是核心类,该类是一个线程类,run方法中是核心后台线程
- 启动连接
- 初始化选举算法FastLeaderElection, 这时还没开始选举
3. 核心类解释
3.1 QuorumPeer类注释
* This class manages the quorum protocol. There are three states this server
* can be in:
* <ol>
* <li>Leader election - each server will elect a leader (proposing itself as a
* leader initially).</li>
* <li>Follower - the server will synchronize with the leader and replicate any
* transactions.</li>
* <li>Leader - the server will process requests and forward them to followers.
* A majority of followers must log the request before it can be accepted.
* </ol>
*
* This class will setup a datagram socket that will always respond with its
* view of the current leader. The response will take the form of:
*
核心方法功能有三个,分别是:1.leader选举 2.Follower 功能 3.Leader 功能
3.2 ServerCnxnFactory
Server网络连接工厂:服务端管理连接核心类
负责请求的连接与管理

3011

被折叠的 条评论
为什么被折叠?



