public QuorumVerifier setQuorumVerifier(QuorumVerifier qv, boolean writeToDisk) {
synchronized (QV_LOCK) {
if ((quorumVerifier != null) && (quorumVerifier.getVersion() >= qv.getVersion())) { // 最开始quorumVerifier为null
// this is normal. For example - server found out about new config through FastLeaderElection gossiping
// and then got the same config in UPTODATE message so its already known
...
return quorumVerifier;
}
QuorumVerifier prevQV = quorumVerifier;
quorumVerifier = qv;
if (lastSeenQuorumVerifier == null || (qv.getVersion() > lastSeenQuorumVerifier.getVersion())) {
lastSeenQuorumVerifier = qv;
}
...
QuorumServer qs = qv.getAllMembers().get(getId()); // qv.getAllMembers()为Map<Long, QuorumServer>,键为sid(myid),值为表示ip:port1:port2的数据结构,对应配置文件的server.x
if (qs != null) {
setAddrs(qs.addr, qs.electionAddr, qs.clientAddr);
// qs.addr是数据同步ip+port(对应配置文件host:port1:port2中的host+port1),qs.electionAddr是选举ip+port(对应配置文件host:port1:port2中的host+port2)
}
updateObserverMasterList();
return prevQV;
}
}
QuorumPeer.setQuorumVerifier
最新推荐文章于 2023-09-05 19:39:36 发布