zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1176153 - in /zookeeper/branches/branch-3.4: CHANGES.txt src/java/main/org/apache/zookeeper/server/persistence/Util.java src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java
Date Tue, 27 Sep 2011 01:07:35 GMT
Author: mahadev
Date: Tue Sep 27 01:07:35 2011
New Revision: 1176153

URL: http://svn.apache.org/viewvc?rev=1176153&view=rev
Log:
ZOOKEEPER-1189. For an invalid snapshot file(less than 10bytes size) RandomAccessFile stream
is leaking. (Rakesh R via mahadev) - Merging  r1176144 from trunk

Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/persistence/Util.java
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1176153&r1=1176152&r2=1176153&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Tue Sep 27 01:07:35 2011
@@ -325,6 +325,9 @@ BUGFIXES: 
   ZOOKEEPER-1136. NEW_LEADER should be queued not sent to match the Zab 1.0 protocol 
   on the twiki (breed via mahadev)
 
+  ZOOKEEPER-1189. For an invalid snapshot file(less than 10bytes size) RandomAccessFile 
+  stream is leaking. (Rakesh R via mahadev)
+
 IMPROVEMENTS:
   ZOOKEEPER-724. Improve junit test integration - log harness information 
   (phunt via mahadev)

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/persistence/Util.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/persistence/Util.java?rev=1176153&r1=1176152&r2=1176153&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/persistence/Util.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/persistence/Util.java
Tue Sep 27 01:07:35 2011
@@ -164,12 +164,12 @@ public class Util {
 
         // Check for a valid snapshot
         RandomAccessFile raf = new RandomAccessFile(f, "r");
-        // including the header and the last / bytes
-        // the snapshot should be atleast 10 bytes
-        if (raf.length() < 10) {
-            return false;
-        }
         try {
+            // including the header and the last / bytes
+            // the snapshot should be atleast 10 bytes
+            if (raf.length() < 10) {
+                return false;
+            }
             raf.seek(raf.length() - 5);
             byte bytes[] = new byte[5];
             int readlen = 0;

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java?rev=1176153&r1=1176152&r2=1176153&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/ZooKeeperServerTest.java
Tue Sep 27 01:07:35 2011
@@ -19,14 +19,15 @@
 package org.apache.zookeeper.server;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.List;
 
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.server.persistence.FileTxnLog;
 import org.apache.zookeeper.server.persistence.Util;
+import org.apache.zookeeper.test.ClientBase;
 import org.junit.Assert;
 import org.junit.Test;
-import org.junit.Assert;
 
 public class ZooKeeperServerTest extends ZKTestCase {
     @Test
@@ -114,4 +115,23 @@ public class ZooKeeperServerTest extends
         }
     }
 
+    @Test
+    public void testInvalidSnapshot() {
+        File f = null;
+        File tmpFileDir = null;
+        try {
+            tmpFileDir = ClientBase.createTmpDir();
+            f = new File(tmpFileDir, "snapshot.0");
+            if (!f.exists()) {
+                f.createNewFile();
+            }
+            Assert.assertFalse("Snapshot file size is greater than 9 bytes", Util.isValidSnapshot(f));
+            Assert.assertTrue("Can't delete file", f.delete());
+        } catch (IOException e) {
+        } finally {
+            if (null != tmpFileDir) {
+                ClientBase.recursiveDelete(tmpFileDir);
+            }
+        }
+    }
 }



Mime
View raw message