/** * 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"); } }
zooKeeperServers.get(activeZKServerIndex).getZKDatabase().close();
/** * 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); }
public void shutdown() { running = false; x509Util.close(); if (leader != null) { leader.shutdown("quorum Peer shutdown"); } if (follower != null) { follower.shutdown(); } shutdownServerCnxnFactory(); if(udpSocket != null) { udpSocket.close(); } try { adminServer.shutdown(); } catch (AdminServerException e) { LOG.warn("Problem stopping AdminServer", e); } if(getElectionAlg() != null){ this.interrupt(); getElectionAlg().shutdown(); } try { zkDb.close(); } catch (IOException ie) { LOG.warn("Error closing logs ", ie); } }
zooKeeperServers.get(activeZKServerIndex).getZKDatabase().close();
/** * @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 shutdown() { running = false; if (leader != null) { leader.shutdown("quorum Peer shutdown"); } if (follower != null) { follower.shutdown(); } cnxnFactory.shutdown(); if(udpSocket != null) { udpSocket.close(); } if(getElectionAlg() != null){ this.interrupt(); getElectionAlg().shutdown(); } try { zkDb.close(); } catch (IOException ie) { LOG.warn("Error closing logs ", ie); } }
/** * Shutdown the embedded Kafka server. * * @param deleteData true if the data should be removed, or false otherwise */ public synchronized void shutdown(boolean deleteData) { if (factory != null) { try { factory.shutdown(); try { // Zookeeper 3.4.6 does not close the ZK DB during shutdown, so we must do this here to avoid file locks and open handles... server.getZKDatabase().close(); } catch (IOException e) { LOGGER.error("Unable to close zookeeper DB", e); } } finally { factory = null; if (deleteData) { // Delete all data ... try { IoUtil.delete(this.snapshotDir,this.logDir); } catch ( IOException e ) { LOGGER.error("Unable to delete data upon shutdown",e); } } } } }
/** */ private void shutdownServerInstance(ServerCnxnFactory factory) { if (factory != null) { ZKDatabase zkDb = null; { ZooKeeperServer zs = getServer(factory); if (zs != null) zkDb = zs.getZKDatabase(); } factory.shutdown(); try { if (zkDb != null) zkDb.close(); } catch (IOException ie) { // ignore } } }
@After public void teardown() throws Exception { // count down to avoid infinite blocking call due to this latch, if // any. startupDelayLatch.countDown(); if (servcnxnf != null) { servcnxnf.shutdown(); } if (zks != null) { zks.shutdown(); } if (zks.getZKDatabase() != null) { zks.getZKDatabase().close(); } ClientBase.recursiveDelete(tmpDir); }
zkDb.close(); } catch (IOException ie) { LOG.warn("Error closing logs ", ie);
@Test public void testTruncationNullLog() throws Exception { File tmpdir = ClientBase.createTmpDir(); FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpdir, tmpdir); ZKDatabase zkdb = new ZKDatabase(snaplog); for (int i = 1; i <= 100; i++) { append(zkdb, i); } zkdb.close(); File[] logs = snaplog.getDataDir().listFiles(); for(int i = 0; i < logs.length; i++) { LOG.debug("Deleting: {}", logs[i].getName()); Assert.assertTrue("Failed to delete log file: " + logs[i].getName(), logs[i].delete()); } try { zkdb.truncateLog(1); Assert.assertTrue("Should not get here", false); } catch(IOException e) { Assert.assertTrue("Should have received an IOException", true); } catch(NullPointerException npe) { Assert.fail("This should not throw NPE!"); } ClientBase.recursiveDelete(tmpdir); }
static void shutdownServerInstance(ServerCnxnFactory factory, String hostPort) { if (factory != null) { ZKDatabase zkDb = null; { ZooKeeperServer zs = getServer(factory); if (zs != null) { zkDb = zs.getZKDatabase(); } } factory.shutdown(); try { if (zkDb != null) { zkDb.close(); } } catch (IOException ie) { LOG.warn("Error closing logs ", ie); } final int PORT = getPort(hostPort); Assert.assertTrue("waiting for server down", ClientBase.waitForServerDown("127.0.0.1:" + PORT, CONNECTION_TIMEOUT, factory.isSecure())); } }
@Test public void testTruncationStreamReset() throws Exception { File tmpdir = ClientBase.createTmpDir(); FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpdir, tmpdir); ZKDatabase zkdb = new ZKDatabase(snaplog); // make sure to snapshot, so that we have something there when // truncateLog reloads the db snaplog.save(zkdb.getDataTree(), zkdb.getSessionWithTimeOuts(), false); for (int i = 1; i <= 100; i++) { append(zkdb, i); } zkdb.truncateLog(1); append(zkdb, 200); zkdb.close(); // verify that the truncation and subsequent append were processed // correctly FileTxnLog txnlog = new FileTxnLog(new File(tmpdir, "version-2")); TxnIterator iter = txnlog.read(1); TxnHeader hdr = iter.getHeader(); Record txn = iter.getTxn(); Assert.assertEquals(1, hdr.getZxid()); Assert.assertTrue(txn instanceof SetDataTxn); iter.next(); hdr = iter.getHeader(); txn = iter.getTxn(); Assert.assertEquals(200, hdr.getZxid()); Assert.assertTrue(txn instanceof SetDataTxn); iter.close(); ClientBase.recursiveDelete(tmpdir); }
@Override public void close() throws IOException { cnxnFactory.shutdown(); try { cnxnFactory.join(); } catch (InterruptedException e) { throw new InterruptedIOException(); } if (server.getZKDatabase() != null) { // see https://issues.apache.org/jira/browse/ZOOKEEPER-1459 server.getZKDatabase().close(); } }
@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(); } }
@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 IOException, InterruptedException { if (zks != null) { ZKDatabase zkDb = zks.getZKDatabase(); factory.shutdown(); try { zkDb.close(); } catch (IOException ie) { } final int PORT = Integer.parseInt(hostPort.split(":")[1]); Assert.assertTrue("waiting for server down", waitForServerDown("127.0.0.1:" + PORT, CONNECTION_TIMEOUT)); } } @Test
static void shutdownServerInstance(ServerCnxnFactory factory, String hostPort) { if (factory != null) { ZKDatabase zkDb; { ZooKeeperServer zs = getServer(factory); zkDb = zs.getZKDatabase(); } factory.shutdown(); try { zkDb.close(); } catch (IOException ie) { LOG.warn("Error closing logs ", ie); } final int PORT = getPort(hostPort); Assert.assertTrue("waiting for server down", ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT, CONNECTION_TIMEOUT)); } }