/** * 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); }
/** * @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"); } } 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"); } }
int clientPort = clientPortList.get(activeZKServerIndex); standaloneServerFactory.shutdown(); if (!waitForServerDown(clientPort, connectionTimeout)) { throw new IOException("Waiting for shutdown of standalone server");
@After public void tearDown() { if (factory != null) { factory.shutdown(); } }
@Test public void testShutdownWithoutStart_SocketReleased() throws IOException { factory.shutdown(); factory = null; ServerSocket ss = new ServerSocket(listenAddress.getPort()); ss.close(); } }
@After public void cleanUp() throws IOException { FileUtils.deleteDirectory(baseFile); if (factory != null) { factory.shutdown(); } }
/** * Kill one back up ZK servers * @throws IOException * @throws InterruptedException */ 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); }
int clientPort = clientPortList.get(activeZKServerIndex); standaloneServerFactory.shutdown(); if (!waitForServerDown(clientPort, connectionTimeout)) { throw new IOException("Waiting for shutdown of standalone server");
/** * @throws IOException */ 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"); } } 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"); } }
public void killServer() throws Exception { if (zkc != null) { zkc.close(); } // shutdown ZK server if (serverFactory != null) { serverFactory.shutdown(); Assert.assertTrue(ClientBase.waitForServerDown(getZooKeeperConnectString(), ClientBase.CONNECTION_TIMEOUT), "waiting for server down"); } if (zks != null) { zks.getTxnLogFactory().close(); } // ServerStats.unregister(); FileUtils.deleteDirectory(ZkTmpDir); } }
@Test public void testFileDescriptorLeak() throws Exception { OSMXBean osMbean = new OSMXBean(); if (osMbean.getUnix() != true) { 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. Assert.assertTrue("Possible fd leakage", ((endFdCount - startFdCount) < 50)); } }
@Override public void close() throws IOException { zookeeper.shutdown(); factory.shutdown(); FileUtils.deleteDirectory(tmpDir); } }
@Override public synchronized void shutdown() { if(_mainThread == null) throw new IllegalStateException("not started"); if(_shutdown) return; _cnxnFactory.shutdown(); _shutdown = true; }
public static void shutdownZkServer() throws Exception { if (server != null) { server.shutdown(); standaloneServerFactory.shutdown(); standaloneServerFactory = null; server = null; } }
@Override public void stop() { if (null != serverFactory) { serverFactory.shutdown(); } if (null != zks) { zks.shutdown(); } } }
public void close() { if (zk != null) { zk.shutdown(true); } if (factory != null) { factory.shutdown(); } delete(dir); }
public void shutdown() { zooKeeperServer.shutdown(); nioServerCnxnFactory.shutdown(); Utils.delete(logDir); Utils.delete(snapshotDir); }
public void restart() throws IOException, InterruptedException { if (zk != null) { zk.shutdown(false); } // Reuse the existing port InetSocketAddress addr = factory.getLocalAddress(); factory.shutdown(); zk = new ZooKeeperServer(dir, dir, 1000); start(addr); }
@Override public void destroy() throws Exception { cnxnFactory.shutdown(); cnxnFactory.join(); if (server.getZKDatabase() != null) { // see https://issues.apache.org/jira/browse/ZOOKEEPER-1459 server.getZKDatabase().close(); } }
@After public void tearDown() throws Exception { zkPort.unlock(); try { standaloneServerFactory.shutdown(); } catch (Throwable t) { LOG.error(t.getMessage(), t); } finally { FileUtils.deleteSilent(zkDir); } }