本文整理了Java中org.apache.zookeeper.server.ZKDatabase.close()
方法的一些代码示例,展示了ZKDatabase.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKDatabase.close()
方法的具体详情如下:
包路径:org.apache.zookeeper.server.ZKDatabase
类名称:ZKDatabase
方法名:close
[英]close this database. free the resources
[中]关闭这个数据库。释放资源
代码示例来源:origin: apache/hbase
/**
* 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);
}
代码示例来源:origin: apache/hbase
/**
* @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");
}
}
代码示例来源:origin: apache/hbase
zooKeeperServers.get(activeZKServerIndex).getZKDatabase().close();
代码示例来源:origin: apache/hive
/**
* 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);
}
代码示例来源:origin: apache/zookeeper
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);
}
}
代码示例来源:origin: apache/hive
zooKeeperServers.get(activeZKServerIndex).getZKDatabase().close();
代码示例来源:origin: apache/hive
/**
* @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");
}
}
代码示例来源:origin: org.apache.zookeeper/zookeeper
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);
}
}
代码示例来源:origin: debezium/debezium
/**
* 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);
}
}
}
}
}
代码示例来源:origin: apache/ignite
/** */
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
}
}
}
代码示例来源:origin: apache/zookeeper
@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);
}
代码示例来源:origin: apache/zookeeper
zkDb.close();
} catch (IOException ie) {
LOG.warn("Error closing logs ", ie);
代码示例来源:origin: apache/zookeeper
@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);
}
代码示例来源:origin: apache/zookeeper
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()));
}
}
代码示例来源:origin: apache/zookeeper
@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);
}
代码示例来源:origin: fabric8io/jube
@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();
}
}
代码示例来源:origin: io.fabric8/fabric-zookeeper
@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();
}
}
代码示例来源:origin: jboss-fuse/fabric8
@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();
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-common
@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
代码示例来源:origin: ch.cern.hadoop/hadoop-common
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));
}
}
内容来源于网络,如有侵权,请联系作者删除!