Search in sources :

Example 1 with Election

use of org.apache.zookeeper.server.quorum.Election in project zookeeper by apache.

the class QuorumBase method shutdown.

public static void shutdown(QuorumPeer qp) {
    if (qp == null) {
        return;
    }
    try {
        LOG.info("Shutting down quorum peer " + qp.getName());
        qp.shutdown();
        Election e = qp.getElectionAlg();
        if (e != null) {
            LOG.info("Shutting down leader election " + qp.getName());
            e.shutdown();
        } else {
            LOG.info("No election available to shutdown " + qp.getName());
        }
        LOG.info("Waiting for " + qp.getName() + " to exit thread");
        long readTimeout = qp.getTickTime() * qp.getInitLimit();
        long connectTimeout = qp.getTickTime() * qp.getSyncLimit();
        long maxTimeout = Math.max(readTimeout, connectTimeout);
        maxTimeout = Math.max(maxTimeout, ClientBase.CONNECTION_TIMEOUT);
        qp.join(maxTimeout * 2);
        if (qp.isAlive()) {
            Assert.fail("QP failed to shutdown in " + (maxTimeout * 2) + " seconds: " + qp.getName());
        }
    } catch (InterruptedException e) {
        LOG.debug("QP interrupted: " + qp.getName(), e);
    }
}
Also used : Election(org.apache.zookeeper.server.quorum.Election)

Example 2 with Election

use of org.apache.zookeeper.server.quorum.Election in project zookeeper by apache.

the class QuorumUtil method shutdown.

public void shutdown(int id) {
    QuorumPeer qp = getPeer(id).peer;
    try {
        LOG.info("Shutting down quorum peer " + qp.getName());
        qp.shutdown();
        Election e = qp.getElectionAlg();
        if (e != null) {
            LOG.info("Shutting down leader election " + qp.getName());
            e.shutdown();
        } else {
            LOG.info("No election available to shutdown " + qp.getName());
        }
        LOG.info("Waiting for " + qp.getName() + " to exit thread");
        qp.join(30000);
        if (qp.isAlive()) {
            Assert.fail("QP failed to shutdown in 30 seconds: " + qp.getName());
        }
    } catch (InterruptedException e) {
        LOG.debug("QP interrupted: " + qp.getName(), e);
    }
}
Also used : QuorumPeer(org.apache.zookeeper.server.quorum.QuorumPeer) Election(org.apache.zookeeper.server.quorum.Election)

Example 3 with Election

use of org.apache.zookeeper.server.quorum.Election in project rest.li by linkedin.

the class ZKPeer method shutdown.

public void shutdown(boolean removeDirectories) throws IOException {
    try {
        String peerType = "";
        if (_peer.leader != null) {
            peerType = "leader";
        }
        _log.info("Shutting down quorum " + peerType + " peer #" + getPeerPortsInfo());
        try {
            _peer.shutdown();
        } catch (Exception e) {
            _log.debug("Exception during peer " + _peer.getName() + " shutdown.", e);
        }
        Election e = _peer.getElectionAlg();
        if (e != null) {
            _log.debug("Shutting down " + _peer.getName() + " leader election ");
            e.shutdown();
        } else {
            _log.debug("No election available to shutdown ");
        }
        _log.debug("Waiting for " + _peer.getName() + " to exit thread");
        _peer.join(60000);
        if (_peer.isAlive()) {
            fail("QP failed to shutdown in 60 seconds: " + _peer.getName());
        }
        if (removeDirectories) {
            FileUtils.deleteDirectory(_dataDir);
            FileUtils.deleteDirectory(_logDir);
        }
    } catch (InterruptedException e) {
        _log.debug("Shutdown interrupted: " + _peer.getName(), e);
    }
    try {
        waitForServerDown(TIMEOUT);
    } catch (Exception e) {
    }
}
Also used : Election(org.apache.zookeeper.server.quorum.Election) IOException(java.io.IOException)

Aggregations

Election (org.apache.zookeeper.server.quorum.Election)3 IOException (java.io.IOException)1 QuorumPeer (org.apache.zookeeper.server.quorum.QuorumPeer)1