【zookeeper核心源码解析】第一课:zk启动类核心流程序列图

系列文章目录


1. zk 启动核心流程序列图

QueermpeerMain核心代码start()方法:

    @Override
    public synchronized void start() {
        loadDataBase();
        cnxnFactory.start();        //绑定2181
        startLeaderElection();
        super.start();
    }

序列图如下:
在这里插入图片描述

2、启动流程说明

  1. 进程入口类: QuermpeerMain,从mian方法开始找
  2. 主要初始化QuorumPeer,该类三个核心方法, start() ,该类是核心类,该类是一个线程类,run方法中是核心后台线程
  3. 启动连接
  4. 初始化选举算法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网络连接工厂:服务端管理连接核心类
负责请求的连接与管理

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值