Search in sources :

Example 16 with QuorumVerifier

use of org.apache.zookeeper.server.quorum.flexible.QuorumVerifier in project zookeeper by apache.

the class QuorumPeerConfig method parseDynamicConfig.

/**
 * Parse dynamic configuration file and return
 * quorumVerifier for new configuration.
 * @param dynamicConfigProp Properties to parse from.
 * @throws IOException
 * @throws ConfigException
 */
public static QuorumVerifier parseDynamicConfig(Properties dynamicConfigProp, int eAlg, boolean warnings, boolean configBackwardCompatibilityMode) throws IOException, ConfigException {
    boolean isHierarchical = false;
    for (Entry<Object, Object> entry : dynamicConfigProp.entrySet()) {
        String key = entry.getKey().toString().trim();
        if (key.startsWith("group") || key.startsWith("weight")) {
            isHierarchical = true;
        } else if (!configBackwardCompatibilityMode && !key.startsWith("server.") && !key.equals("version")) {
            LOG.info(dynamicConfigProp.toString());
            throw new ConfigException("Unrecognised parameter: " + key);
        }
    }
    QuorumVerifier qv = createQuorumVerifier(dynamicConfigProp, isHierarchical);
    int numParticipators = qv.getVotingMembers().size();
    int numObservers = qv.getObservingMembers().size();
    if (numParticipators == 0) {
        if (!standaloneEnabled) {
            throw new IllegalArgumentException("standaloneEnabled = false then " + "number of participants should be >0");
        }
        if (numObservers > 0) {
            throw new IllegalArgumentException("Observers w/o participants is an invalid configuration");
        }
    } else if (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) {
            throw new 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.");
            } else if (numParticipators % 2 == 0) {
                LOG.warn("Non-optimial configuration, consider an odd number of servers.");
            }
        }
        for (QuorumServer s : qv.getVotingMembers().values()) {
            if (s.electionAddr == null)
                throw new IllegalArgumentException("Missing election port for server: " + s.id);
        }
    }
    return qv;
}
Also used : QuorumServer(org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer) QuorumVerifier(org.apache.zookeeper.server.quorum.flexible.QuorumVerifier)

Example 17 with QuorumVerifier

use of org.apache.zookeeper.server.quorum.flexible.QuorumVerifier in project zookeeper by apache.

the class LeaderBeanTest method setUp.

@Before
public void setUp() throws IOException {
    qp = new QuorumPeer();
    QuorumVerifier quorumVerifierMock = mock(QuorumVerifier.class);
    qp.setQuorumVerifier(quorumVerifierMock, false);
    File tmpDir = ClientBase.createEmptyTestDir();
    fileTxnSnapLog = new FileTxnSnapLog(new File(tmpDir, "data"), new File(tmpDir, "data_txnlog"));
    ZKDatabase zkDb = new ZKDatabase(fileTxnSnapLog);
    zks = new LeaderZooKeeperServer(fileTxnSnapLog, qp, zkDb);
    leader = new Leader(qp, zks);
    leaderBean = new LeaderBean(leader, zks);
}
Also used : File(java.io.File) ZKDatabase(org.apache.zookeeper.server.ZKDatabase) QuorumVerifier(org.apache.zookeeper.server.quorum.flexible.QuorumVerifier) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog) Before(org.junit.Before)

Aggregations

QuorumVerifier (org.apache.zookeeper.server.quorum.flexible.QuorumVerifier)17 IOException (java.io.IOException)7 SetDataTxn (org.apache.zookeeper.txn.SetDataTxn)4 TxnHeader (org.apache.zookeeper.txn.TxnHeader)4 ByteBuffer (java.nio.ByteBuffer)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Request (org.apache.zookeeper.server.Request)3 Record (org.apache.jute.Record)2 KeeperException (org.apache.zookeeper.KeeperException)2 ZooKeeper (org.apache.zookeeper.ZooKeeper)2 QuorumServer (org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer)2 Test (org.junit.Test)2 File (java.io.File)1 StringReader (java.io.StringReader)1 BindException (java.net.BindException)1 ConnectException (java.net.ConnectException)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketException (java.net.SocketException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1