Search in sources :

Example 46 with NIOServerCnxnFactory

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

the class NIOConnectionFactoryFdLeakTest method testFileDescriptorLeak.

@Test
public void testFileDescriptorLeak() throws Exception {
    OSMXBean osMbean = new OSMXBean();
    if (!osMbean.getUnix()) {
        LOG.info("Unable to run test on non-unix system");
        return;
    }
    long startFdCount = osMbean.getOpenFileDescriptorCount();
    LOG.info("Start fdcount is: {}", startFdCount);
    for (int i = 0; i < 50; ++i) {
        NIOServerCnxnFactory factory = new NIOServerCnxnFactory();
        factory.configure(new InetSocketAddress("127.0.0.1", PortAssignment.unique()), 10);
        factory.start();
        Thread.sleep(100);
        factory.shutdown();
    }
    long endFdCount = osMbean.getOpenFileDescriptorCount();
    LOG.info("End fdcount is: {}", endFdCount);
    // On my box, if selector.close() is not called fd diff is > 700.
    assertTrue(((endFdCount - startFdCount) < 50), "Possible fd leakage");
}
Also used : OSMXBean(org.apache.zookeeper.server.util.OSMXBean) InetSocketAddress(java.net.InetSocketAddress) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) Test(org.junit.jupiter.api.Test)

Example 47 with NIOServerCnxnFactory

use of org.apache.zookeeper.server.NIOServerCnxnFactory in project apex-malhar by apache.

the class HBaseTestHelper method startZooKeeperServer.

private static void startZooKeeperServer() throws IOException, InterruptedException {
    String zooLocation = System.getProperty("java.io.tmpdir");
    File zooFile = new File(zooLocation, "zookeeper-malhartest");
    ZooKeeperServer zooKeeper = new ZooKeeperServer(zooFile, zooFile, 2000);
    NIOServerCnxnFactory serverFactory = new NIOServerCnxnFactory();
    serverFactory.configure(new InetSocketAddress(2181), 10);
    serverFactory.startup(zooKeeper);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer)

Example 48 with NIOServerCnxnFactory

use of org.apache.zookeeper.server.NIOServerCnxnFactory in project parseq 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 49 with NIOServerCnxnFactory

use of org.apache.zookeeper.server.NIOServerCnxnFactory in project incubator-pulsar by apache.

the class ZookeeperServerTest method start.

public void start() throws IOException {
    try {
        zks = new ZooKeeperServer(zkTmpDir, zkTmpDir, ZooKeeperServer.DEFAULT_TICK_TIME);
        zks.setMaxSessionTimeout(20000);
        serverFactory = new NIOServerCnxnFactory();
        serverFactory.configure(new InetSocketAddress(zkPort), 1000);
        serverFactory.startup(zks);
    } catch (Exception e) {
        log.error("Exception while instantiating ZooKeeper", e);
    }
    LocalBookkeeperEnsemble.waitForServerUp(hostPort, 30000);
    log.info("ZooKeeper started at {}", hostPort);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) IOException(java.io.IOException)

Example 50 with NIOServerCnxnFactory

use of org.apache.zookeeper.server.NIOServerCnxnFactory in project incubator-pulsar by apache.

the class LocalBookkeeperEnsemble method runZookeeper.

/**
 * @param args
 */
private void runZookeeper(int maxCC) throws IOException {
    // create a ZooKeeper server(dataDir, dataLogDir, port)
    LOG.info("Starting ZK server");
    // ServerStats.registerAsConcrete();
    // ClientBase.setupTestEnv();
    File zkDataDir = isNotBlank(zkDataDirName) ? Files.createDirectories(Paths.get(zkDataDirName)).toFile() : Files.createTempDirectory("zktest").toFile();
    if (this.clearOldData) {
        cleanDirectory(zkDataDir);
    }
    try {
        zks = new ZooKeeperServer(zkDataDir, zkDataDir, ZooKeeperServer.DEFAULT_TICK_TIME);
        serverFactory = new NIOServerCnxnFactory();
        serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), maxCC);
        serverFactory.startup(zks);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        LOG.error("Exception while instantiating ZooKeeper", e);
    }
    boolean b = waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
    LOG.info("ZooKeeper server up: {}", b);
    LOG.debug("Local ZK started (port: {}, data_directory: {})", ZooKeeperDefaultPort, zkDataDir.getAbsolutePath());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NIOServerCnxnFactory(org.apache.zookeeper.server.NIOServerCnxnFactory) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) InvalidCookieException(org.apache.bookkeeper.bookie.BookieException.InvalidCookieException)

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