List of usage examples for org.apache.zookeeper.server ZooKeeperServer getZKDatabase
public ZKDatabase getZKDatabase()
From source file:com.github.zkclient.ZkServer.java
License:Apache License
@PreDestroy public void shutdown() { ZooKeeperServer zk = _zk; if (zk == null) { LOG.warn("shutdown duplication"); return;//from ww w. j a v a2s. com } else { _zk = null; } LOG.info("Shutting down ZkServer..."); try { _zkClient.close(); } catch (ZkException e) { LOG.warn("Error on closing zkclient: " + e.getClass().getName()); } if (_nioFactory != null) { _nioFactory.shutdown(); try { _nioFactory.join(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } _nioFactory = null; } zk.shutdown(); if (zk.getZKDatabase() != null) { try { // release file description zk.getZKDatabase().close(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } LOG.info("Shutting down ZkServer...done"); }
From source file:com.linkedin.d2.quorum.ZKPeer.java
License:Apache License
public void close() throws Exception { _log.info("Closing quorum peer #" + getPeerPortsInfo()); try {/* ww w. j a v a2s . co m*/ ZooKeeperServer zkServer = _peer.getActiveServer(); if (zkServer != null) { ZKDatabase zkDb = zkServer.getZKDatabase(); if (zkDb != null) { // make ZK server close its log files zkDb.close(); } } } catch (Exception e) { _log.debug("Failed to close peer #" + getPeerPortsInfo(), e); } }
From source file:org.apache.curator.test.TestingZooKeeperMain.java
License:Apache License
@Override public void close() throws IOException { try {//from w w w . ja v a 2 s. c o m shutdown(); } catch (Throwable e) { e.printStackTrace(); // just ignore - this class is only for testing } try { ServerCnxnFactory cnxnFactory = getServerConnectionFactory(); if (cnxnFactory != null) { ZooKeeperServer zkServer = getZooKeeperServer(cnxnFactory); if (zkServer != null) { ZKDatabase zkDb = zkServer.getZKDatabase(); if (zkDb != null) { // make ZK server close its log files zkDb.close(); } } } } catch (Exception e) { e.printStackTrace(); // just ignore - this class is only for testing } }
From source file:org.apache.hadoop.ha.ActiveStandbyElectorTestUtil.java
License:Apache License
public static void waitForActiveLockData(TestContext ctx, ZooKeeperServer zks, String parentDir, byte[] activeData) throws Exception { long st = Time.now(); long lastPrint = st; while (true) { if (ctx != null) { ctx.checkException();/* w ww .ja va 2 s .co m*/ } try { Stat stat = new Stat(); byte[] data = zks.getZKDatabase().getData(parentDir + "/" + ActiveStandbyElector.LOCK_FILENAME, stat, null); if (activeData != null && Arrays.equals(activeData, data)) { return; } if (Time.now() > lastPrint + LOG_INTERVAL_MS) { LOG.info("Cur data: " + StringUtils.byteToHexString(data)); lastPrint = Time.now(); } } catch (NoNodeException nne) { if (activeData == null) { return; } if (Time.now() > lastPrint + LOG_INTERVAL_MS) { LOG.info("Cur data: no node"); lastPrint = Time.now(); } } Thread.sleep(50); } }
From source file:org.apache.hadoop.ha.ClientBaseWithFixes.java
License:Apache License
static void shutdownServerInstance(ServerCnxnFactory factory, String hostPort) { if (factory != null) { ZKDatabase zkDb;//from w w w .j av a 2s. com { 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)); } }
From source file:org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster.java
License:Apache License
/** * @throws IOException//w w w .j av a 2 s. c o m */ 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"); } } for (ZooKeeperServer zkServer : zooKeeperServers) { //explicitly close ZKDatabase since ZookeeperServer does not close them zkServer.getZKDatabase().close(); } // clear everything started = false; activeZKServerIndex = 0; standaloneServerFactoryList.clear(); clientPortList.clear(); zooKeeperServers.clear(); LOG.info("Shutdown MiniZK cluster with all ZK servers"); }
From source file:org.apache.hive.testutils.MiniZooKeeperCluster.java
License:Apache License
/** * @throws IOException/*from w w w .j a va 2s . co m*/ */ 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"); } }
From source file:org.apache.pulsar.zookeeper.ZooKeeperServerAspect.java
License:Apache License
@After("zkServerConstructorPointCut()") public void zkServerConstructor(JoinPoint joinPoint) throws Throwable { // ZooKeeperServer instance was created ZooKeeperServer zkServer = (ZooKeeperServer) joinPoint.getThis(); synchronized (ZooKeeperServerAspect.class) { if (metricsRegistered) { // We can only register the metrics a single time for the process return; }//from w w w.j a v a 2 s . c om metricsRegistered = true; } Gauge.build().name("zookeeper_server_znode_count").help("Number of z-nodes stored").create() .setChild(new Gauge.Child() { @Override public double get() { return zkServer.getZKDatabase().getNodeCount(); } }).register(); Gauge.build().name("zookeeper_server_data_size_bytes").help("Size of all of z-nodes stored (bytes)") .create().setChild(new Gauge.Child() { @Override public double get() { return zkServer.getZKDatabase().getDataTree().approximateDataSize(); } }).register(); Gauge.build().name("zookeeper_server_connections").help("Number of currently opened connections").create() .setChild(new Gauge.Child() { @Override public double get() { return zkServer.serverStats().getNumAliveClientConnections(); } }).register(); Gauge.build().name("zookeeper_server_watches_count").help("Number of watches").create() .setChild(new Gauge.Child() { @Override public double get() { return zkServer.getZKDatabase().getDataTree().getWatchCount(); } }).register(); Gauge.build().name("zookeeper_server_ephemerals_count").help("Number of ephemerals z-nodes").create() .setChild(new Gauge.Child() { @Override public double get() { return zkServer.getZKDatabase().getDataTree().getEphemeralsCount(); } }).register(); }
From source file:org.apache.slider.core.zk.MiniZooKeeperCluster.java
License:Apache License
@Override protected void serviceStop() throws Exception { if (!started) { return;//from ww w .j a v a2 s.co m } started = false; try { // 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"); } } for (ZooKeeperServer zkServer : zooKeeperServers) { //explicitly close ZKDatabase since ZookeeperServer does not close them zkServer.getZKDatabase().close(); } } finally { // clear everything activeZKServerIndex = 0; standaloneServerFactoryList.clear(); clientPortList.clear(); zooKeeperServers.clear(); } LOG.info("Shutdown MiniZK cluster with all ZK servers"); }