hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r922442 - in /hadoop/zookeeper/trunk: ./ src/java/main/org/apache/zookeeper/server/ src/java/main/org/apache/zookeeper/server/persistence/ src/java/test/org/apache/zookeeper/test/
Date Fri, 12 Mar 2010 22:36:12 GMT
Author: mahadev
Date: Fri Mar 12 22:36:12 2010
New Revision: 922442

URL: http://svn.apache.org/viewvc?rev=922442&view=rev
Log:
ZOOKEEPER-121. SyncRequestProcessor is not closing log stream during shutdown (mahadev)

Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZKDatabase.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/SnapShot.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/TxnLog.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientBase.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=922442&r1=922441&r2=922442&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Fri Mar 12 22:36:12 2010
@@ -273,6 +273,9 @@ BUGFIXES: 
   ZOOKEEPER-604. zk needs to prevent export of any symbol not listed in their
   api (mahadev)
 
+  ZOOKEEPER-121. SyncRequestProcessor is not closing log stream during
+  shutdown (mahadev)
+
 IMPROVEMENTS:
   ZOOKEEPER-473. cleanup junit tests to eliminate false positives due to
   "socket reuse" and failure to close client (phunt via mahadev)

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java?rev=922442&r1=922441&r2=922442&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/SyncRequestProcessor.java
Fri Mar 12 22:36:12 2010
@@ -166,6 +166,11 @@ public class SyncRequestProcessor extend
     }
 
     public void shutdown() {
+        try{
+            zks.getZKDatabase().close();
+        } catch (IOException ie) {
+            LOG.warn("Error closing logs ", ie);
+        }
         queuedRequests.add(requestOfDeath);
         nextProcessor.shutdown();
     }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZKDatabase.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZKDatabase.java?rev=922442&r1=922441&r2=922442&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZKDatabase.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZKDatabase.java Fri Mar
12 22:36:12 2010
@@ -450,5 +450,12 @@ public class ZKDatabase {
         this.snapLog.commit();
     }
     
+    /**
+     * close this database. free the resources
+     * @throws IOException
+     */
+    public void close() throws IOException {
+        this.snapLog.close();
+    }
     
 }
\ No newline at end of file

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java?rev=922442&r1=922441&r2=922442&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileSnap.java
Fri Mar 12 22:36:12 2010
@@ -49,6 +49,7 @@ import org.apache.zookeeper.server.util.
  */
 public class FileSnap implements SnapShot {
     File snapDir;
+    private volatile boolean close = false;
     private static final int VERSION=2;
     private static final long dbId=-1;
     private static final Logger LOG = Logger.getLogger(FileSnap.class);
@@ -217,20 +218,32 @@ public class FileSnap implements SnapSho
      * @param sessions the sessions to be serialized
      * @param snapShot the file to store snapshot into
      */
-    public void serialize(DataTree dt, Map<Long, Integer> sessions, File snapShot)
+    public synchronized void serialize(DataTree dt, Map<Long, Integer> sessions, File
snapShot)
             throws IOException {
-        OutputStream sessOS = new BufferedOutputStream(new FileOutputStream(snapShot));
-        CheckedOutputStream crcOut = new CheckedOutputStream(sessOS, new Adler32());
-        //CheckedOutputStream cout = new CheckedOutputStream()
-        OutputArchive oa = BinaryOutputArchive.getArchive(crcOut);
-        FileHeader header = new FileHeader(SNAP_MAGIC, VERSION, dbId);
-        serialize(dt,sessions,oa, header);
-        long val = crcOut.getChecksum().getValue();
-        oa.writeLong(val, "val");
-        oa.writeString("/", "path");
-        sessOS.flush();
-        crcOut.close();
-        sessOS.close();
+        if (!close) {
+            OutputStream sessOS = new BufferedOutputStream(new FileOutputStream(snapShot));
+            CheckedOutputStream crcOut = new CheckedOutputStream(sessOS, new Adler32());
+            //CheckedOutputStream cout = new CheckedOutputStream()
+            OutputArchive oa = BinaryOutputArchive.getArchive(crcOut);
+            FileHeader header = new FileHeader(SNAP_MAGIC, VERSION, dbId);
+            serialize(dt,sessions,oa, header);
+            long val = crcOut.getChecksum().getValue();
+            oa.writeLong(val, "val");
+            oa.writeString("/", "path");
+            sessOS.flush();
+            crcOut.close();
+            sessOS.close();
+        }
+    }
+
+    /**
+     * synchronized close just so that if serialize is in place
+     * the close operation will block and will wait till serialize
+     * is done and will set the close flag
+     */
+    @Override
+    public synchronized void close() throws IOException {
+        close = true;
     }
 
  }
\ No newline at end of file

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java?rev=922442&r1=922441&r2=922442&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
Fri Mar 12 22:36:12 2010
@@ -165,6 +165,19 @@ public class FileTxnLog implements TxnLo
     }
 
     /**
+     * close all the open file handles
+     * @throws IOException
+     */
+    public synchronized void close() throws IOException {
+        if (logStream != null) {
+            logStream.close();
+        }
+        for (FileOutputStream log : streamsToFlush) {
+            log.close();
+        }
+    }
+    
+    /**
      * append an entry to the transaction log
      * @param hdr the header of the transaction
      * @param txn the transaction part of the entry

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java?rev=922442&r1=922441&r2=922442&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
Fri Mar 12 22:36:12 2010
@@ -285,4 +285,12 @@ public class FileTxnSnapLog {
         txnLog.rollLog();
     }
     
+    /**
+     * close the transaction log files
+     * @throws IOException
+     */
+    public void close() throws IOException {
+        txnLog.close();
+        snapLog.close();
+    }
 }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/SnapShot.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/SnapShot.java?rev=922442&r1=922441&r2=922442&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/SnapShot.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/SnapShot.java
Fri Mar 12 22:36:12 2010
@@ -57,4 +57,10 @@ public interface SnapShot {
      * @throws IOException
      */
     File findMostRecentSnapshot() throws IOException;
+    
+    /**
+     * free resources from this snapshot immediately
+     * @throws IOException
+     */
+    void close() throws IOException;
 } 
\ No newline at end of file

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/TxnLog.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/TxnLog.java?rev=922442&r1=922441&r2=922442&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/TxnLog.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/persistence/TxnLog.java
Fri Mar 12 22:36:12 2010
@@ -83,6 +83,10 @@ public interface TxnLog {
      */
     void commit() throws IOException;
    
+    /** 
+     * close the transactions logs
+     */
+    void close() throws IOException;
     /**
      * an iterating interface for reading 
      * transaction logs. 

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientBase.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientBase.java?rev=922442&r1=922441&r2=922442&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientBase.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/ClientBase.java Fri Mar
12 22:36:12 2010
@@ -454,9 +454,7 @@ public abstract class ClientBase extends
         stopServer();
 
         if (tmpDir != null) {
-            //assertTrue("delete " + tmpDir.toString(), recursiveDelete(tmpDir));
-            // FIXME see ZOOKEEPER-121 replace following line with previous
-            recursiveDelete(tmpDir);
+            assertTrue("delete " + tmpDir.toString(), recursiveDelete(tmpDir));
         }
 
         // This has to be set to null when the same instance of this class is reused between
test cases
@@ -475,9 +473,7 @@ public abstract class ClientBase extends
         if (d.isDirectory()) {
             File children[] = d.listFiles();
             for (File f : children) {
-                //assertTrue("delete " + f.toString(), recursiveDelete(f));
-                // FIXME see ZOOKEEPER-121 replace following line with previous
-                recursiveDelete(f);
+                assertTrue("delete " + f.toString(), recursiveDelete(f));
             }
         }
         return d.delete();



Mime
View raw message