int numParticipators = qv.getVotingMembers().size(); int numObservers = qv.getObservingMembers().size(); if (numParticipators == 0) { if (!standaloneEnabled) { thrownew IllegalArgumentException("standaloneEnabled = false then " + "number of participants should be >0"); } if (numObservers > 0) { thrownew IllegalArgumentException("Observers w/o participants is an invalid configuration"); } } elseif (numParticipators == 1 && standaloneEnabled) { // HBase currently adds a single server line to the config, for // b/w compatibility reasons we need to keep this here. If standaloneEnabled // is true, the QuorumPeerMain script will create a standalone server instead // of a quorum configuration LOG.error("Invalid configuration, only one server specified (ignoring)"); if (numObservers > 0) { thrownew IllegalArgumentException("Observers w/o quorum is an invalid configuration"); } } else { if (warnings) { if (numParticipators <= 2) { LOG.warn("No server failure will be tolerated. You need at least 3 servers."); } elseif (numParticipators % 2 == 0) { LOG.warn("Non-optimial configuration, consider an odd number of servers."); } }
for (QuorumServer s : qv.getVotingMembers().values()) { if (s.electionAddr == null) { thrownew IllegalArgumentException("Missing election port for server: " + s.id); } } } return qv; }
createQuorumVerifier 创建QuorumVerifier
1 2 3 4 5 6 7 8 9 10 11
privatestatic QuorumVerifier createQuorumVerifier(Properties dynamicConfigProp, boolean isHierarchical)throws ConfigException { if (isHierarchical) { returnnew QuorumHierarchical(dynamicConfigProp); } else { /* * The default QuorumVerifier is QuorumMaj */ //LOG.info("Defaulting to majority quorums"); returnnew QuorumMaj(dynamicConfigProp); } }