Search in sources :

Example 51 with NIOServerCnxnFactory

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

the class ZKServer method restart.

public void restart() throws IOException, InterruptedException {
    shutdown(false);
    _zk = new ZooKeeperServer(_dataDir, _logDir, 5000);
    _factory = new NIOServerCnxnFactory();
    _factory.configure(new InetSocketAddress(_port), 60);
    startup();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer)

Example 52 with NIOServerCnxnFactory

use of org.apache.zookeeper.server.NIOServerCnxnFactory in project drill by apache.

the class MiniZooKeeperCluster method shutdown.

/**
 * @throws IOException
 */
public void shutdown() throws IOException {
    if (!started) {
        return;
    }
    // shut down all the zk servers
    for (int i = 0; i < standaloneServerFactoryList.size(); i++) {
        NIOServerCnxnFactory standaloneServerFactory = standaloneServerFactoryList.get(i);
        int clientPort = clientPortList.get(i);
        standaloneServerFactory.shutdown();
        if (!waitForServerDown(clientPort, CONNECTION_TIMEOUT)) {
            throw new IOException("Waiting for shutdown of standalone server");
        }
    }
    // clear everything
    started = false;
    activeZKServerIndex = 0;
    standaloneServerFactoryList.clear();
    clientPortList.clear();
    zooKeeperServers.clear();
    logger.info("Shutdown MiniZK cluster with all ZK servers");
}
Also used : NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) IOException(java.io.IOException)

Example 53 with NIOServerCnxnFactory

use of org.apache.zookeeper.server.NIOServerCnxnFactory in project hbase by apache.

the class MiniZooKeeperCluster method killCurrentActiveZooKeeperServer.

/**
 * @return clientPort return clientPort if there is another ZK backup can run
 *         when killing the current active; return -1, if there is no backups.
 * @throws IOException if waiting for the shutdown of a server fails
 */
public int killCurrentActiveZooKeeperServer() throws IOException, InterruptedException {
    if (!started || activeZKServerIndex < 0) {
        return -1;
    }
    // Shutdown the current active one
    NIOServerCnxnFactory standaloneServerFactory = standaloneServerFactoryList.get(activeZKServerIndex);
    int clientPort = clientPortList.get(activeZKServerIndex);
    standaloneServerFactory.shutdown();
    if (!waitForServerDown(clientPort, connectionTimeout)) {
        throw new IOException("Waiting for shutdown of standalone server");
    }
    zooKeeperServers.get(activeZKServerIndex).getZKDatabase().close();
    // remove the current active zk server
    standaloneServerFactoryList.remove(activeZKServerIndex);
    clientPortList.remove(activeZKServerIndex);
    zooKeeperServers.remove(activeZKServerIndex);
    LOG.info("Kill the current active ZK servers in the cluster on client port: {}", clientPort);
    if (standaloneServerFactoryList.isEmpty()) {
        // there is no backup servers;
        return -1;
    }
    clientPort = clientPortList.get(activeZKServerIndex);
    LOG.info("Activate a backup zk server in the cluster on client port: {}", clientPort);
    // return the next back zk server's port
    return clientPort;
}
Also used : NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 54 with NIOServerCnxnFactory

use of org.apache.zookeeper.server.NIOServerCnxnFactory in project hbase by apache.

the class MiniZooKeeperCluster method shutdown.

/**
 * @throws IOException if waiting for the shutdown of a server fails
 */
public void shutdown() throws IOException {
    // shut down all the zk servers
    for (int i = 0; i < standaloneServerFactoryList.size(); i++) {
        NIOServerCnxnFactory standaloneServerFactory = standaloneServerFactoryList.get(i);
        int clientPort = clientPortList.get(i);
        standaloneServerFactory.shutdown();
        if (!waitForServerDown(clientPort, connectionTimeout)) {
            throw new IOException("Waiting for shutdown of standalone server at port=" + clientPort + ", timeout=" + this.connectionTimeout);
        }
    }
    standaloneServerFactoryList.clear();
    for (ZooKeeperServer zkServer : zooKeeperServers) {
        // Explicitly close ZKDatabase since ZookeeperServer does not close them
        zkServer.getZKDatabase().close();
    }
    zooKeeperServers.clear();
    // clear everything
    if (started) {
        started = false;
        activeZKServerIndex = 0;
        clientPortList.clear();
        LOG.info("Shutdown MiniZK cluster with all ZK servers");
    }
}
Also used : NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer)

Example 55 with NIOServerCnxnFactory

use of org.apache.zookeeper.server.NIOServerCnxnFactory in project hbase by apache.

the class MiniZooKeeperCluster method killOneBackupZooKeeperServer.

/**
 * Kill one back up ZK servers.
 *
 * @throws IOException if waiting for the shutdown of a server fails
 */
public void killOneBackupZooKeeperServer() throws IOException, InterruptedException {
    if (!started || activeZKServerIndex < 0 || standaloneServerFactoryList.size() <= 1) {
        return;
    }
    int backupZKServerIndex = activeZKServerIndex + 1;
    // Shutdown the current active one
    NIOServerCnxnFactory standaloneServerFactory = standaloneServerFactoryList.get(backupZKServerIndex);
    int clientPort = clientPortList.get(backupZKServerIndex);
    standaloneServerFactory.shutdown();
    if (!waitForServerDown(clientPort, connectionTimeout)) {
        throw new IOException("Waiting for shutdown of standalone server");
    }
    zooKeeperServers.get(backupZKServerIndex).getZKDatabase().close();
    // remove this backup zk server
    standaloneServerFactoryList.remove(backupZKServerIndex);
    clientPortList.remove(backupZKServerIndex);
    zooKeeperServers.remove(backupZKServerIndex);
    LOG.info("Kill one backup ZK servers in the cluster on client port: {}", clientPort);
}
Also used : NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Aggregations

NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)55 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)24 IOException (java.io.IOException)22 InetSocketAddress (java.net.InetSocketAddress)19 File (java.io.File)16 Test (org.junit.Test)13 CuratorFramework (org.apache.curator.framework.CuratorFramework)12 RetryNTimes (org.apache.curator.retry.RetryNTimes)12 FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)10 ZooKeeperGroup (io.fabric8.groups.internal.ZooKeeperGroup)6 ZooKeeperGroup (org.apache.camel.component.zookeepermaster.group.internal.ZooKeeperGroup)6 ServerConfig (org.apache.zookeeper.server.ServerConfig)5 InterruptedIOException (java.io.InterruptedIOException)4 BindException (java.net.BindException)3 ZKDatabase (org.apache.zookeeper.server.ZKDatabase)3 Field (java.lang.reflect.Field)2 SelectionKey (java.nio.channels.SelectionKey)2 ServerSocketChannel (java.nio.channels.ServerSocketChannel)2 SocketChannel (java.nio.channels.SocketChannel)2 ArrayList (java.util.ArrayList)2