zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f..@apache.org
Subject svn commit: r1548825 - in /zookeeper/trunk: 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:16:34 GMT
Author: fpj
Date: Sat Dec  7 10:16:34 2013
New Revision: 1548825

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


Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
    zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1548825&r1=1548824&r2=1548825&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Sat Dec  7 10:16:34 2013
@@ -485,6 +485,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-1170. Fix compiler (eclipse) warnings: unused imports,

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java?rev=1548825&r1=1548824&r2=1548825&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java Sat
Dec  7 10:16:34 2013
@@ -97,12 +97,14 @@ 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
             // run() in this thread.
             // create a file logger url from the command line args
-            ZooKeeperServer zkServer = new ZooKeeperServer( new FileTxnSnapLog(config.dataLogDir,
config.dataDir),
+            txnLog = new FileTxnSnapLog(config.dataLogDir, config.dataDir);
+            ZooKeeperServer zkServer = new ZooKeeperServer( txnLog,
                     config.tickTime, config.minSessionTimeout, config.maxSessionTimeout,
null);
 
             cnxnFactory = ServerCnxnFactory.createFactory();
@@ -116,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/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java?rev=1548825&r1=1548824&r2=1548825&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java
(original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/server/ZooKeeperServerMainTest.java
Sat Dec  7 10:16:34 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