hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r941473 - in /hadoop/zookeeper/trunk: ./ src/java/main/org/apache/zookeeper/server/quorum/ src/java/test/org/apache/zookeeper/test/
Date Wed, 05 May 2010 20:32:33 GMT
Author: mahadev
Date: Wed May  5 20:32:33 2010
New Revision: 941473

URL: http://svn.apache.org/viewvc?rev=941473&view=rev
Log:
ZOOKEEPER-764. Observer elected leader due to inconsistent voting view (henry via mahadev)

Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderElection.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumZooKeeperServer.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncHammerTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java
    hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumBase.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=941473&r1=941472&r2=941473&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Wed May  5 20:32:33 2010
@@ -46,6 +46,9 @@ BUGFIXES: 
 
   ZOOKEEPER-737. some 4 letter words may fail with netcat (nc). (mahadev)
 
+  ZOOKEEPER-764. Observer elected leader due to inconsistent voting view 
+  (henry via mahadev)
+
 IMPROVEMENTS:
   ZOOKEEPER-724. Improve junit test integration - log harness information 
   (phunt via mahadev)

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java?rev=941473&r1=941472&r2=941473&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
Wed May  5 20:32:33 2010
@@ -587,7 +587,7 @@ public class FastLeaderElection implemen
      * @return ServerState
      */
     private ServerState learningState(){
-        if(self.getPeerType() == LearnerType.PARTICIPANT){
+        if(self.getLearnerType() == LearnerType.PARTICIPANT){
             LOG.debug("I'm a participant: " + self.getId());
             return ServerState.FOLLOWING;
         }
@@ -603,7 +603,7 @@ public class FastLeaderElection implemen
      * @return long
      */
     private long getInitId(){
-        if(self.getPeerType() == LearnerType.PARTICIPANT)
+        if(self.getLearnerType() == LearnerType.PARTICIPANT)
             return self.getId();
         else return Long.MIN_VALUE;
     }
@@ -614,7 +614,7 @@ public class FastLeaderElection implemen
      * @return long
      */
     private long getInitLastLoggedZxid(){
-        if(self.getPeerType() == LearnerType.PARTICIPANT)
+        if(self.getLearnerType() == LearnerType.PARTICIPANT)
             return self.getLastLoggedZxid();
         else return Long.MIN_VALUE;
     }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderElection.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderElection.java?rev=941473&r1=941472&r2=941473&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderElection.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/LeaderElection.java
Wed May  5 20:32:33 2010
@@ -226,7 +226,7 @@ public class LeaderElection implements E
                             self.setCurrentVote(result.winner);
                             s.close();
                             Vote current = self.getCurrentVote();
-                            LOG.info("Found leader: my type is: " + self.getPeerType());
+                            LOG.info("Found leader: my type is: " + self.getLearnerType());
                             /*
                              * We want to make sure we implement the state machine
                              * correctly. If we are a PARTICIPANT, once a leader
@@ -234,7 +234,7 @@ public class LeaderElection implements E
                              * FOLLOWING. However if we are an OBSERVER, it is an
                              * error to be elected as a Leader.
                              */
-                            if (self.getPeerType() == LearnerType.OBSERVER) {
+                            if (self.getLearnerType() == LearnerType.OBSERVER) {
                                 if (current.id == self.getId()) {
                                     // This should never happen!
                                     LOG.error("OBSERVER elected as leader!");

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java?rev=941473&r1=941472&r2=941473&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
Wed May  5 20:32:33 2010
@@ -148,14 +148,24 @@ public class QuorumPeer extends Thread i
     /*
      * Default value of peer is participant
      */
-    private LearnerType peerType = LearnerType.PARTICIPANT;
+    private LearnerType learnerType = LearnerType.PARTICIPANT;
     
-    public LearnerType getPeerType() {
-        return peerType;
+    public LearnerType getLearnerType() {
+        return learnerType;
     }
     
-    public void setPeerType(LearnerType p) {
-        peerType = p;
+    /**
+     * Sets the LearnerType both in the QuorumPeer and in the peerMap
+     */
+    public void setLearnerType(LearnerType p) {
+        learnerType = p;
+        if (quorumPeers.containsKey(this.myid)) {
+            this.quorumPeers.get(myid).type = p;
+        } else {
+            LOG.error("Setting LearnerType to " + p + " but " + myid 
+                    + " not in QuorumPeers. ");
+        }
+        
     }
     /**
      * The servers that make up the cluster

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java?rev=941473&r1=941472&r2=941473&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java
Wed May  5 20:32:33 2010
@@ -138,7 +138,7 @@ public class QuorumPeerMain {
           quorumPeer.setQuorumVerifier(config.getQuorumVerifier());
           quorumPeer.setCnxnFactory(cnxnFactory);
           quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory()));
-          quorumPeer.setPeerType(config.getPeerType());
+          quorumPeer.setLearnerType(config.getPeerType());
   
           quorumPeer.start();
           quorumPeer.join();

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumZooKeeperServer.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumZooKeeperServer.java?rev=941473&r1=941472&r2=941473&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumZooKeeperServer.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumZooKeeperServer.java
Wed May  5 20:32:33 2010
@@ -57,6 +57,6 @@ public abstract class QuorumZooKeeperSer
         pwriter.print("quorumPort=");
         pwriter.println(self.quorumPeers.get(self.getId()).addr.getPort());
         pwriter.print("peerType=");
-        pwriter.println(self.getPeerType().ordinal());
+        pwriter.println(self.getLearnerType().ordinal());
     }
 }

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncHammerTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncHammerTest.java?rev=941473&r1=941472&r2=941473&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncHammerTest.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/AsyncHammerTest.java Wed
May  5 20:32:33 2010
@@ -49,9 +49,8 @@ public class AsyncHammerTest extends ZKT
 
     private volatile boolean bang;
 
-    @Before
-    public void setUp() throws Exception {
-        qb.setUp();
+    public void setUp(boolean withObservers) throws Exception {
+        qb.setUp(withObservers);
     }
 
     protected void restart() throws Exception {
@@ -63,7 +62,6 @@ public class AsyncHammerTest extends ZKT
         qb.startServers();
     }
 
-    @After
     public void tearDown() throws Exception {
         LOG.info("Test clients shutting down");
         qb.tearDown();
@@ -171,6 +169,7 @@ public class AsyncHammerTest extends ZKT
 
     @Test
     public void testHammer() throws Exception {
+        setUp(false);
         bang = true;
         LOG.info("Starting hammers");
         HammerThread[] hammers = new HammerThread[100];
@@ -197,12 +196,12 @@ public class AsyncHammerTest extends ZKT
         // after restart
         LOG.info("Verifying hammers 2");
         qb.verifyRootOfAllServersMatch(qb.hostPort);
+        tearDown();
     }
 
     @Test
     public void testObserversHammer() throws Exception {
-        qb.tearDown();
-        qb.setUp(true);
+        setUp(true);
         bang = true;
         Thread[] hammers = new Thread[100];
         for (int i = 0; i < hammers.length; i++) {
@@ -217,6 +216,7 @@ public class AsyncHammerTest extends ZKT
         }
         // before restart
         qb.verifyRootOfAllServersMatch(qb.hostPort);
+        tearDown();
     }
 
     @SuppressWarnings("unchecked")

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java?rev=941473&r1=941472&r2=941473&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java
(original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java
Wed May  5 20:32:33 2010
@@ -166,7 +166,7 @@ public class HierarchicalQuorumTest exte
         QuorumHierarchical hq4 = new QuorumHierarchical(qp); 
         s4 = new QuorumPeer(peers, s4dir, s4dir, port4, 3, 4, tickTime, initLimit, syncLimit,
hq4);
         if (withObservers) {
-            s4.setPeerType(QuorumPeer.LearnerType.OBSERVER);
+            s4.setLearnerType(QuorumPeer.LearnerType.OBSERVER);
         }
         Assert.assertEquals(port4, s4.getClientPort());
                        
@@ -174,7 +174,7 @@ public class HierarchicalQuorumTest exte
         QuorumHierarchical hq5 = new QuorumHierarchical(qp); 
         s5 = new QuorumPeer(peers, s5dir, s5dir, port5, 3, 5, tickTime, initLimit, syncLimit,
hq5);
         if (withObservers) {
-            s5.setPeerType(QuorumPeer.LearnerType.OBSERVER);
+            s5.setLearnerType(QuorumPeer.LearnerType.OBSERVER);
         }
         Assert.assertEquals(port5, s5.getClientPort());
         

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java?rev=941473&r1=941472&r2=941473&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java
(original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java
Wed May  5 20:32:33 2010
@@ -169,7 +169,7 @@ public class LENonTerminateTest extends 
                             self.setCurrentVote(result.winner);
                             s.close();
                             Vote current = self.getCurrentVote();
-                            LOG.info("Found leader: my type is: " + self.getPeerType());
+                            LOG.info("Found leader: my type is: " + self.getLearnerType());
                             /*
                              * We want to make sure we implement the state machine
                              * correctly. If we are a PARTICIPANT, once a leader
@@ -177,7 +177,7 @@ public class LENonTerminateTest extends 
                              * FOLLOWING. However if we are an OBSERVER, it is an
                              * error to be elected as a Leader.
                              */
-                            if (self.getPeerType() == LearnerType.OBSERVER) {
+                            if (self.getLearnerType() == LearnerType.OBSERVER) {
                                 if (current.id == self.getId()) {
                                     // This should never happen!
                                     LOG.error("OBSERVER elected as leader!");

Modified: hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumBase.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumBase.java?rev=941473&r1=941472&r2=941473&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumBase.java (original)
+++ hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/QuorumBase.java Wed May
 5 20:32:33 2010
@@ -159,10 +159,16 @@ public class QuorumBase extends ClientBa
         Assert.assertEquals(port5, s5.getClientPort());
         
         if (withObservers) {
-            s4.setPeerType(LearnerType.OBSERVER);
-            s5.setPeerType(LearnerType.OBSERVER);
+            s4.setLearnerType(LearnerType.OBSERVER);
+            s5.setLearnerType(LearnerType.OBSERVER);
         }
         
+        LOG.info("QuorumPeer 1 voting view: " + s1.getVotingView());
+        LOG.info("QuorumPeer 2 voting view: " + s2.getVotingView());
+        LOG.info("QuorumPeer 3 voting view: " + s3.getVotingView());
+        LOG.info("QuorumPeer 4 voting view: " + s4.getVotingView());
+        LOG.info("QuorumPeer 5 voting view: " + s5.getVotingView());       
+        
         LOG.info("start QuorumPeer 1");
         s1.start();
         LOG.info("start QuorumPeer 2");



Mime
View raw message