Commit 4d44680a authored by Flavio Paiva Junqueira's avatar Flavio Paiva Junqueira
Browse files

ZOOKEEPER-1459. Standalone ZooKeeperServer is not closing

  the transaction log files on shutdown (Rakesh R via fpj)



git-svn-id: https://svn.apache.org/repos/asf/zookeeper/branches/branch-3.4@1548826 13f79535-47bb-0310-9956-ffa450edef68
parent a336d9b6
......@@ -172,6 +172,9 @@ BUGFIXES:
ZOOKEEPER-1632. fix memory leaks in cli_st (fpj via michim)
ZOOKEEPER-1459. Standalone ZooKeeperServer is not closing
the transaction log files on shutdown (Rakesh R via fpj)
IMPROVEMENTS:
ZOOKEEPER-1564. Allow JUnit test build with IBM Java
......
......@@ -93,6 +93,7 @@ public class ZooKeeperServerMain {
*/
public void runFromConfig(ServerConfig config) throws IOException {
LOG.info("Starting server");
FileTxnSnapLog txnLog = null;
try {
// Note that this thread isn't going to be doing anything else,
// so rather than spawning another thread, we will just call
......@@ -100,9 +101,9 @@ public class ZooKeeperServerMain {
// create a file logger url from the command line args
ZooKeeperServer zkServer = new ZooKeeperServer();
FileTxnSnapLog ftxn = new FileTxnSnapLog(new
File(config.dataLogDir), new File(config.dataDir));
zkServer.setTxnLogFactory(ftxn);
txnLog = new FileTxnSnapLog(new File(config.dataLogDir), new File(
config.dataDir));
zkServer.setTxnLogFactory(txnLog);
zkServer.setTickTime(config.tickTime);
zkServer.setMinSessionTimeout(config.minSessionTimeout);
zkServer.setMaxSessionTimeout(config.maxSessionTimeout);
......@@ -117,6 +118,10 @@ public class ZooKeeperServerMain {
} catch (InterruptedException e) {
// warn, but generally this is ok
LOG.warn("Server interrupted", e);
} finally {
if (txnLog != null) {
txnLog.close();
}
}
}
......
......@@ -47,10 +47,11 @@ public class ZooKeeperServerMainTest extends ZKTestCase implements Watcher {
public static class MainThread extends Thread {
final File confFile;
final TestZKSMain main;
final File tmpDir;
public MainThread(int clientPort) throws IOException {
super("Standalone server with clientPort:" + clientPort);
File tmpDir = ClientBase.createTmpDir();
tmpDir = ClientBase.createTmpDir();
confFile = new File(tmpDir, "zoo.cfg");
FileWriter fwriter = new FileWriter(confFile);
......@@ -89,9 +90,25 @@ public class ZooKeeperServerMainTest extends ZKTestCase implements Watcher {
}
}
public void shutdown() {
public void shutdown() throws IOException {
main.shutdown();
}
void deleteDirs() throws IOException{
delete(tmpDir);
}
void delete(File f) throws IOException {
if (f.isDirectory()) {
for (File c : f.listFiles())
delete(c);
}
if (!f.delete())
// double check for the file existence
if (f.exists()) {
throw new IOException("Failed to delete file: " + f);
}
}
}
public static class TestZKSMain extends ZooKeeperServerMain {
......@@ -126,6 +143,8 @@ public class ZooKeeperServerMainTest extends ZKTestCase implements Watcher {
zk.close();
main.shutdown();
main.join();
main.deleteDirs();
Assert.assertTrue("waiting for server down",
ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment