本篇内容主要讲解“zk中leader和follower启动时信息交互分析”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“zk中leader和follower启动时信息交互分析”吧!
QuorumPeer中读取节点状态信息,不同状态下设置不同角色

1 Leader启动Follower接收器LearnerCnxAcceptor
LearnerCnxAcceptor负责接收非leader连接请求,线程中创建LearnerHandler处理器
2 Learner发起和leader的连接
Follower.followLeader()
Observer.observeLeader()
3 leader启动时会创建LearnerHandler
每个learnerHandler实例都对应一个leader和learner之间的连接,负责消息通信和
数据同步
4 向leader注册
learner和leader连接后。会向leader注册,即learner服务器基础信息
LearnerInfo zxid,sid发送给leader服务器
5 leader 接收到learner信息 服务器算出最新epoch
@Override
public long getEpochToPropose(long sid, long lastAcceptedEpoch) throws InterruptedException, IOException {
synchronized (connectingFollowers) {
if (!waitingForNewEpoch) {
return epoch;
}
if (lastAcceptedEpoch >= epoch) {
epoch = lastAcceptedEpoch + 1;
}
if (isParticipant(sid)) {
connectingFollowers.add(sid);
}
QuorumVerifier verifier = self.getQuorumVerifier();
if (connectingFollowers.contains(self.getId()) && verifier.containsQuorum(connectingFollowers)) {
waitingForNewEpoch = false;
self.setAcceptedEpoch(epoch);
connectingFollowers.notifyAll();
} else {
long start = Time.currentElapsedTime();
if (sid == self.getId()) {
timeStartWaitForEpoch = start;
}
long cur = start;
long end = start + self.getInitLimit() * self.getTickTime();
while (waitingForNewEpoch && cur < end && !quitWaitForEpoch) {
connectingFollowers.wait(end - cur);
cur = Time.currentElapsedTime();
}
if (waitingForNewEpoch) {
throw new InterruptedException("Timeout while waiting for epoch from quorum");
}
}
return epoch;
}
}
到此,相信大家对“zk中leader和follower启动时信息交互分析”有了更深的了解,不妨来实际操作一番吧!这里是天达云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!