zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f..@apache.org
Subject svn commit: r1567661 - in /zookeeper/branches/branch-3.4: ./ src/java/main/org/apache/zookeeper/server/persistence/ src/java/test/org/apache/zookeeper/test/
Date Wed, 12 Feb 2014 16:00:34 GMT
Author: fpj
Date: Wed Feb 12 16:00:34 2014
New Revision: 1567661

URL: http://svn.apache.org/r1567661
Log:
ZOOKEEPER-1844. TruncateTest fails on windows (Rakesh R via fpj)


Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/TruncateTest.java

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1567661&r1=1567660&r2=1567661&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Wed Feb 12 16:00:34 2014
@@ -244,6 +244,8 @@ BUGFIXES:
   ZOOKEEPER-1873. Unnecessarily InstanceNotFoundException is coming when
   unregister failed jmxbeans (Rakesh R via michim)
 
+  ZOOKEEPER-1844. TruncateTest fails on windows (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/persistence/FileTxnLog.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java?rev=1567661&r1=1567660&r2=1567661&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
Wed Feb 12 16:00:34 2014
@@ -285,9 +285,10 @@ public class FileTxnLog implements TxnLo
         // if a log file is more recent we must scan it to find
         // the highest zxid
         long zxid = maxLog;
+        TxnIterator itr = null;
         try {
             FileTxnLog txn = new FileTxnLog(logDir);
-            TxnIterator itr = txn.read(maxLog);
+            itr = txn.read(maxLog);
             while (true) {
                 if(!itr.next())
                     break;
@@ -296,10 +297,22 @@ public class FileTxnLog implements TxnLo
             }
         } catch (IOException e) {
             LOG.warn("Unexpected exception", e);
+        } finally {
+            close(itr);
         }
         return zxid;
     }
 
+    private void close(TxnIterator itr) {
+        if (itr != null) {
+            try {
+                itr.close();
+            } catch (IOException ioe) {
+                LOG.warn("Error closing file iterator", ioe);
+            }
+        }
+    }
+
     /**
      * commit the logs. make sure that evertyhing hits the
      * disk
@@ -347,17 +360,22 @@ public class FileTxnLog implements TxnLo
      * @return true if successful false if not
      */
     public boolean truncate(long zxid) throws IOException {
-        FileTxnIterator itr = new FileTxnIterator(this.logDir, zxid);
-        PositionInputStream input = itr.inputStream;
-        long pos = input.getPosition();
-        // now, truncate at the current position
-        RandomAccessFile raf=new RandomAccessFile(itr.logFile,"rw");
-        raf.setLength(pos);
-        raf.close();
-        while(itr.goToNextLog()) {
-            if (!itr.logFile.delete()) {
-                LOG.warn("Unable to truncate " + itr.logFile);
+        FileTxnIterator itr = null;
+        try {
+            itr = new FileTxnIterator(this.logDir, zxid);
+            PositionInputStream input = itr.inputStream;
+            long pos = input.getPosition();
+            // now, truncate at the current position
+            RandomAccessFile raf = new RandomAccessFile(itr.logFile, "rw");
+            raf.setLength(pos);
+            raf.close();
+            while (itr.goToNextLog()) {
+                if (!itr.logFile.delete()) {
+                    LOG.warn("Unable to truncate {}", itr.logFile);
+                }
             }
+        } finally {
+            close(itr);
         }
         return true;
     }
@@ -657,7 +675,9 @@ public class FileTxnLog implements TxnLo
          * and release the resources.
          */
         public void close() throws IOException {
-            inputStream.close();
+            if (inputStream != null) {
+                inputStream.close();
+            }
         }
     }
 

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java?rev=1567661&r1=1567660&r2=1567661&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java
Wed Feb 12 16:00:34 2014
@@ -132,30 +132,36 @@ public class FileTxnSnapLog {
         TxnIterator itr = txnLog.read(dt.lastProcessedZxid+1);
         long highestZxid = dt.lastProcessedZxid;
         TxnHeader hdr;
-        while (true) {
-            // iterator points to 
-            // the first valid txn when initialized
-            hdr = itr.getHeader();
-            if (hdr == null) {
-                //empty logs 
-                return dt.lastProcessedZxid;
+        try {
+            while (true) {
+                // iterator points to 
+                // the first valid txn when initialized
+                hdr = itr.getHeader();
+                if (hdr == null) {
+                    //empty logs 
+                    return dt.lastProcessedZxid;
+                }
+                if (hdr.getZxid() < highestZxid && highestZxid != 0) {
+                    LOG.error("{}(higestZxid) > {}(next log) for type {}",
+                            new Object[] { highestZxid, hdr.getZxid(),
+                                    hdr.getType() });
+                } else {
+                    highestZxid = hdr.getZxid();
+                }
+                try {
+                    processTransaction(hdr,dt,sessions, itr.getTxn());
+                } catch(KeeperException.NoNodeException e) {
+                   throw new IOException("Failed to process transaction type: " +
+                         hdr.getType() + " error: " + e.getMessage(), e);
+                }
+                listener.onTxnLoaded(hdr, itr.getTxn());
+                if (!itr.next()) 
+                    break;
             }
-            if (hdr.getZxid() < highestZxid && highestZxid != 0) {
-                LOG.error(highestZxid + "(higestZxid) > "
-                        + hdr.getZxid() + "(next log) for type "
-                        + hdr.getType());
-            } else {
-                highestZxid = hdr.getZxid();
+        } finally {
+            if (itr != null) {
+                itr.close();
             }
-            try {
-                processTransaction(hdr,dt,sessions, itr.getTxn());
-            } catch(KeeperException.NoNodeException e) {
-               throw new IOException("Failed to process transaction type: " +
-                     hdr.getType() + " error: " + e.getMessage(), e);
-            }
-            listener.onTxnLoaded(hdr, itr.getTxn());
-            if (!itr.next()) 
-                break;
         }
         return highestZxid;
     }

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/TruncateTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/TruncateTest.java?rev=1567661&r1=1567660&r2=1567661&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/TruncateTest.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/TruncateTest.java
Wed Feb 12 16:00:34 2014
@@ -111,6 +111,8 @@ public class TruncateTest extends ZKTest
         txn = iter.getTxn();
         Assert.assertEquals(200, hdr.getZxid());
         Assert.assertTrue(txn instanceof SetDataTxn);
+        iter.close();
+        ClientBase.recursiveDelete(tmpdir);
     }
 
     private void append(ZKDatabase zkdb, int i) throws IOException {



Mime
View raw message