zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r1421098 - in /zookeeper/trunk: CHANGES.txt src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java
Date Thu, 13 Dec 2012 07:25:36 GMT
Author: phunt
Date: Thu Dec 13 07:25:35 2012
New Revision: 1421098

URL: http://svn.apache.org/viewvc?rev=1421098&view=rev
Log:
ZOOKEEPER-1387. Wrong epoch file created (Benjamin Busjaeger via breed, phunt)

Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
    zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1421098&r1=1421097&r2=1421098&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Thu Dec 13 07:25:35 2012
@@ -287,6 +287,9 @@ BUGFIXES:
   ZOOKEEPER-1478. Small bug in QuorumTest.testFollowersStartAfterLeader( )
   (Alexander Shraer via fpj, breed, phunt)
 
+  ZOOKEEPER-1387. Wrong epoch file created
+  (Benjamin Busjaeger via breed, phunt)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java?rev=1421098&r1=1421097&r2=1421098&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java Thu Dec
13 07:25:35 2012
@@ -612,7 +612,7 @@ public class QuorumPeer extends Thread i
             	LOG.info(ACCEPTED_EPOCH_FILENAME
             	        + " not found! Creating with a reasonable default of {}. This should
only happen when you are upgrading your installation",
             	        acceptedEpoch);
-            	writeLongToFile(CURRENT_EPOCH_FILENAME, acceptedEpoch);
+            	writeLongToFile(ACCEPTED_EPOCH_FILENAME, acceptedEpoch);
             }
             if (acceptedEpoch < currentEpoch) {
                 throw new IOException("The current epoch, " + ZxidUtils.zxidToString(currentEpoch)
+ " is less than the accepted epoch, " + ZxidUtils.zxidToString(acceptedEpoch));

Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java?rev=1421098&r1=1421097&r2=1421098&view=diff
==============================================================================
--- zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java (original)
+++ zookeeper/trunk/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java Thu Dec
13 07:25:35 2012
@@ -20,10 +20,12 @@ package org.apache.zookeeper.server.quor
 
 import static org.junit.Assert.assertEquals;
 
+import java.io.BufferedReader;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
+import java.io.FileReader;
 import java.io.IOException;
 import java.lang.reflect.Field;
 import java.net.InetSocketAddress;
@@ -43,6 +45,7 @@ import org.apache.zookeeper.ZooDefs;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.server.ByteBufferInputStream;
 import org.apache.zookeeper.server.ByteBufferOutputStream;
+import org.apache.zookeeper.server.Request;
 import org.apache.zookeeper.server.ServerCnxn;
 import org.apache.zookeeper.server.ServerCnxnFactory;
 import org.apache.zookeeper.server.ZKDatabase;
@@ -53,6 +56,7 @@ import org.apache.zookeeper.server.quoru
 import org.apache.zookeeper.server.util.ZxidUtils;
 import org.apache.zookeeper.txn.CreateSessionTxn;
 import org.apache.zookeeper.txn.CreateTxn;
+import org.apache.zookeeper.txn.ErrorTxn;
 import org.apache.zookeeper.txn.SetDataTxn;
 import org.apache.zookeeper.txn.TxnHeader;
 import org.junit.Assert;
@@ -1009,4 +1013,40 @@ public class Zab1_0Test {
         fos.close();
         return peer;
     }
+
+    private String readContentsOfFile(File f) throws IOException {
+        return new BufferedReader(new FileReader(f)).readLine();
+    }
+
+    @Test
+    public void testInitialAcceptedCurrent() throws Exception {
+        File tmpDir = File.createTempFile("test", ".dir");
+        tmpDir.delete();
+        tmpDir.mkdir();
+        try {
+            FileTxnSnapLog logFactory = new FileTxnSnapLog(tmpDir, tmpDir);
+            File version2 = new File(tmpDir, "version-2");
+            version2.mkdir();
+            long zxid = ZxidUtils.makeZxid(3, 3);
+            logFactory.append(new Request(1, 1, ZooDefs.OpCode.error,
+                    new TxnHeader(1, 1, zxid, 1, ZooDefs.OpCode.error),
+                    new ErrorTxn(1), zxid));
+            logFactory.commit();
+            ZKDatabase zkDb = new ZKDatabase(logFactory);
+            QuorumPeer peer = new QuorumPeer();
+            peer.setZKDatabase(zkDb);
+            peer.setTxnFactory(logFactory);
+            peer.getLastLoggedZxid();
+            Assert.assertEquals(3, peer.getAcceptedEpoch());
+            Assert.assertEquals(3, peer.getCurrentEpoch());
+            Assert.assertEquals(3, Integer
+                    .parseInt(readContentsOfFile(new File(version2,
+                            QuorumPeer.CURRENT_EPOCH_FILENAME))));
+            Assert.assertEquals(3, Integer
+                    .parseInt(readContentsOfFile(new File(version2,
+                            QuorumPeer.ACCEPTED_EPOCH_FILENAME))));
+        } finally {
+            recursiveDelete(tmpDir);
+        }
+    }
 }



Mime
View raw message