zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1197890 - in /zookeeper/branches/branch-3.4: CHANGES.txt src/java/main/org/apache/zookeeper/server/quorum/Leader.java src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java
Date Sat, 05 Nov 2011 06:14:21 GMT
Author: mahadev
Date: Sat Nov  5 06:14:20 2011
New Revision: 1197890

URL: http://svn.apache.org/viewvc?rev=1197890&view=rev
Log:
ZOOKEEPER-1192. Leader.waitForEpochAck() checks waitingForNewEpoch instead of checking electionFinished
(Alexander Shraer via mahadev)

Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/Leader.java
    zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1197890&r1=1197889&r2=1197890&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Sat Nov  5 06:14:20 2011
@@ -358,6 +358,9 @@ BUGFIXES: 
   ZOOKEEPER-1271. testEarlyLeaderAbandonment failing on solaris -
   clients not retrying connection (mahadev via phunt)
 
+  ZOOKEEPER-1192. Leader.waitForEpochAck() checks waitingForNewEpoch instead 
+  of checking electionFinished (Alexander Shraer 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/quorum/Leader.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/Leader.java?rev=1197890&r1=1197889&r2=1197890&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/Leader.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/Leader.java
Sat Nov  5 06:14:20 2011
@@ -784,9 +784,15 @@ public class Leader {
 				waitingForNewEpoch = false;
 				connectingFollowers.notifyAll();
 			} else {
-				connectingFollowers.wait(self.getInitLimit()*self.getTickTime());
+                   long start = System.currentTimeMillis();
+                   long cur = start;
+                long end = start + self.getInitLimit()*self.getTickTime();
+                while(waitingForNewEpoch && cur < end) {
+                    connectingFollowers.wait(end - cur);
+                    cur = System.currentTimeMillis();
+                }
 				if (waitingForNewEpoch) {
-					throw new InterruptedException("Out of time to propose an epoch");
+                    throw new InterruptedException("Timeout while waiting for epoch from
quorum");        
 				}
 			}
 			return epoch;
@@ -810,10 +816,16 @@ public class Leader {
 			if (readyToStart && verifier.containsQuorum(electingFollowers)) {
 				electionFinished = true;
 				electingFollowers.notifyAll();
-			} else {
-				electingFollowers.wait(self.getInitLimit()*self.getTickTime());
-				if (waitingForNewEpoch) {
-					throw new InterruptedException("Out of time to propose an epoch");
+            } else {                
+                long start = System.currentTimeMillis();
+                long cur = start;
+                long end = start + self.getInitLimit()*self.getTickTime();
+                while(!electionFinished && cur < end) {
+                    electingFollowers.wait(end - cur);
+                    cur = System.currentTimeMillis();
+                }
+                if (!electionFinished) {
+                    throw new InterruptedException("Timeout while waiting for epoch to be
acked by quorum");
 				}
 			}
 		}

Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java?rev=1197890&r1=1197889&r2=1197890&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/server/quorum/Zab1_0Test.java
Sat Nov  5 06:14:20 2011
@@ -44,7 +44,10 @@ import org.apache.zookeeper.server.ZooKe
 import org.apache.zookeeper.server.ZooKeeperServer.DataTreeBuilder;
 import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
 import org.apache.zookeeper.server.quorum.Leader;
+import org.apache.zookeeper.server.quorum.LearnerInfo;
+import org.apache.zookeeper.server.quorum.QuorumPacket;
 import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer;
+import org.apache.zookeeper.server.quorum.Zab1_0Test.LeaderConversation;
 import org.apache.zookeeper.server.quorum.flexible.QuorumMaj;
 import org.apache.zookeeper.server.util.ZxidUtils;
 import org.junit.Assert;
@@ -124,7 +127,7 @@ public class Zab1_0Test {
     }
     
     static public interface LeaderConversation {
-        void converseWithLeader(InputArchive ia, OutputArchive oa) throws Exception;
+        void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l) throws Exception;
     }
     
     static public interface FollowerConversation {
@@ -160,7 +163,7 @@ public class Zab1_0Test {
             OutputArchive oa = BinaryOutputArchive.getArchive(followerSocket
                     .getOutputStream());
 
-            conversation.converseWithLeader(ia, oa);
+            conversation.converseWithLeader(ia, oa, leader);
         } finally {
             recursiveDelete(tmpDir);
             if (leader != null) {
@@ -176,7 +179,7 @@ public class Zab1_0Test {
     @Test
     public void testNormalRun() throws Exception {
         testConversation(new LeaderConversation() {
-            public void converseWithLeader(InputArchive ia, OutputArchive oa)
+            public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l)
                     throws IOException {
                 /* we test a normal run. everything should work out well. */
                 LearnerInfo li = new LearnerInfo(1, 0x10000);
@@ -209,7 +212,7 @@ public class Zab1_0Test {
     @Test
     public void testLeaderBehind() throws Exception {
         testConversation(new LeaderConversation() {
-            public void converseWithLeader(InputArchive ia, OutputArchive oa)
+            public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l)
                     throws IOException {
                 /* we test a normal run. everything should work out well. */
                 LearnerInfo li = new LearnerInfo(1, 0x10000);
@@ -240,7 +243,38 @@ public class Zab1_0Test {
         });
     }
 
-
+    /**
+     * Tests that when a quorum of followers send LearnerInfo but do not ack the epoch (which
is sent
+     * by the leader upon receipt of LearnerInfo from a quorum), the leader does not start
using this epoch
+     * as it would in the normal case (when a quorum do ack the epoch). This tests ZK-1192
+     * @throws Exception
+     */
+    @Test
+    public void testAbandonBeforeACKEpoch() throws Exception {
+        testConversation(new LeaderConversation() {
+            public void converseWithLeader(InputArchive ia, OutputArchive oa, Leader l)
+                    throws IOException, InterruptedException {
+                /* we test a normal run. everything should work out well. */            

+                LearnerInfo li = new LearnerInfo(1, 0x10000);
+                byte liBytes[] = new byte[12];
+                ByteBufferOutputStream.record2ByteBuffer(li,
+                        ByteBuffer.wrap(liBytes));
+                QuorumPacket qp = new QuorumPacket(Leader.FOLLOWERINFO, 0,
+                        liBytes, null);
+                oa.writeRecord(qp, null);
+                readPacketSkippingPing(ia, qp);
+                Assert.assertEquals(Leader.LEADERINFO, qp.getType());
+                Assert.assertEquals(ZxidUtils.makeZxid(1, 0), qp.getZxid());
+                Assert.assertEquals(ByteBuffer.wrap(qp.getData()).getInt(),
+                        0x10000);                
+                Thread.sleep(l.self.getInitLimit()*l.self.getTickTime() + 5000);
+                
+                // The leader didn't get a quorum of acks - make sure that leader's current
epoch is not advanced
+                Assert.assertEquals(0, l.self.getCurrentEpoch());			
+            }
+        });
+    }
+    
     private void recursiveDelete(File file) {
         if (file.isFile()) {
             file.delete();



Mime
View raw message