zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cami...@apache.org
Subject svn commit: r1147631 - in /zookeeper/branches/branch-3.3: CHANGES.txt src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java
Date Sun, 17 Jul 2011 14:33:39 GMT
Author: camille
Date: Sun Jul 17 14:33:38 2011
New Revision: 1147631

URL: http://svn.apache.org/viewvc?rev=1147631&view=rev
Log:
ZOOKEEPER-1069: Calling shutdown() on a QuorumPeer too quickly can lead to a corrupted log

Modified:
    zookeeper/branches/branch-3.3/CHANGES.txt
    zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
    zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java

Modified: zookeeper/branches/branch-3.3/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.3/CHANGES.txt?rev=1147631&r1=1147630&r2=1147631&view=diff
==============================================================================
--- zookeeper/branches/branch-3.3/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.3/CHANGES.txt Sun Jul 17 14:33:38 2011
@@ -35,8 +35,10 @@ BUGFIXES:
 
   ZOOKEEPER-880. QuorumCnxManager$SendWorker grows without bounds (vishal via breed)
  
-  ZOOKEEPER-1046. Creating a new sequential node results in a ZNODEEXISTS error. (Vishal
K via camille) 
-
+  ZOOKEEPER-1046. Creating a new sequential node results in a ZNODEEXISTS error. (Vishal
K via camille)
+  
+  ZOOKEEPER-1069. Calling shutdown() on a QuorumPeer too quickly can lead to a corrupt log.
(Vishal K via camille) 
+   
 IMPROVEMENTS:
   ZOOKEEPER-963. Make Forrest work with JDK6 (Carl Steinbach via henryr)
 

Modified: zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java?rev=1147631&r1=1147630&r2=1147631&view=diff
==============================================================================
--- zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
(original)
+++ zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/server/persistence/FileTxnLog.java
Sun Jul 17 14:33:38 2011
@@ -202,6 +202,8 @@ public class FileTxnLog implements TxnLo
                oa = BinaryOutputArchive.getArchive(logStream);
                FileHeader fhdr = new FileHeader(TXNLOG_MAGIC,VERSION, dbId);
                fhdr.serialize(oa, "fileheader");
+               // Make sure that the magic number is written before padding.
+               logStream.flush();
                currentSize = fos.getChannel().position();
                streamsToFlush.add(fos);
             }

Modified: zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java?rev=1147631&r1=1147630&r2=1147631&view=diff
==============================================================================
--- zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java
(original)
+++ zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java
Sun Jul 17 14:33:38 2011
@@ -1,10 +1,12 @@
 package org.apache.zookeeper.test;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.util.List;
 
 import junit.framework.TestCase;
 
+import org.apache.jute.BinaryInputArchive;
 import org.apache.jute.Record;
 import org.apache.zookeeper.PortAssignment;
 import org.apache.zookeeper.WatchedEvent;
@@ -12,6 +14,8 @@ import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.ZooDefs.OpCode;
 import org.apache.zookeeper.server.DataNode;
 import org.apache.zookeeper.server.DataTree;
+import org.apache.zookeeper.server.persistence.FileHeader;
+import org.apache.zookeeper.server.persistence.FileTxnLog;
 import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
 import org.apache.zookeeper.txn.CreateTxn;
 import org.apache.zookeeper.txn.DeleteTxn;
@@ -101,4 +105,24 @@ public class LoadFromLogTest extends Tes
                 newCversion + ", " + newPzxid + ">",
                 (newCversion == prevCversion + 1 && newPzxid == prevPzxid + 1));
     }
+    /**
+     * Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
+     * fixes it.
+     */
+    @Test
+    public void testPad() throws Exception {
+        File tmpDir = ClientBase.createTmpDir();
+        FileTxnLog txnLog = new FileTxnLog(tmpDir);
+        TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123,
+              System.currentTimeMillis(), OpCode.create);
+        Record txn = new CreateTxn("/Test", new byte[0], null, false);
+        txnLog.append(txnHeader, txn);
+        FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." +
+              Long.toHexString(txnHeader.getZxid()));
+        BinaryInputArchive ia  = BinaryInputArchive.getArchive(in);
+        FileHeader header = new FileHeader();
+        header.deserialize(ia, "fileheader");
+        Assert.assertTrue("Missing magic number ",
+              header.getMagic() == FileTxnLog.TXNLOG_MAGIC);
+    }
 }



Mime
View raw message