zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f..@apache.org
Subject svn commit: r1548826 - in /zookeeper/branches/branch-3.4: CHANGES.txt src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java
Date Sat, 07 Dec 2013 10:17:54 GMT
Author: fpj
Date: Sat Dec  7 10:17:54 2013
New Revision: 1548826

URL: http://svn.apache.org/r1548826
Log:
ZOOKEEPER-1459. Standalone ZooKeeperServer is not closing 
  the transaction log files on shutdown (Rakesh R via fpj)


Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1548826&r1=1548825&r2=1548826&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Sat Dec  7 10:17:54 2013
@@ -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

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java?rev=1548826&r1=1548825&r2=1548826&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
Sat Dec  7 10:17:54 2013
@@ -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();
+            }
         }
     }
 

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java?rev=1548826&r1=1548825&r2=1548826&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java
Sat Dec  7 10:17:54 2013
@@ -47,10 +47,11 @@ public class ZooKeeperServerMainTest ext
     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 ext
             }
         }
 
-        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 ext
         zk.close();
 
         main.shutdown();
+        main.join();
+        main.deleteDirs();
 
         Assert.assertTrue("waiting for server down",
                 ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT,



Mime
View raw message