hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r800893 - in /hadoop/zookeeper/branches/branch-3.2: CHANGES.txt src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
Date Tue, 04 Aug 2009 18:05:13 GMT
Author: mahadev
Date: Tue Aug  4 18:05:13 2009
New Revision: 800893

URL: http://svn.apache.org/viewvc?rev=800893&view=rev
Log:
ZOOKEEPER-480. FLE should perform leader check when node is not leading and add vote of follower
(flavio via mahadev)

Modified:
    hadoop/zookeeper/branches/branch-3.2/CHANGES.txt
    hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java

Modified: hadoop/zookeeper/branches/branch-3.2/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.2/CHANGES.txt?rev=800893&r1=800892&r2=800893&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/CHANGES.txt (original)
+++ hadoop/zookeeper/branches/branch-3.2/CHANGES.txt Tue Aug  4 18:05:13 2009
@@ -32,6 +32,9 @@
   ZOOKEEPER-466. crash on zookeeper_close() when using auth with empty cert
   (Chris Darroch via phunt)
 
+  ZOOKEEPER-480. FLE should perform leader check when node is not leading and
+  add vote of follower (flavio via mahadev)
+
 IMPROVEMENTS:
 
 NEW FEATURES:

Modified: hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java?rev=800893&r1=800892&r2=800893&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
(original)
+++ hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
Tue Aug  4 18:05:13 2009
@@ -490,9 +490,20 @@
             long epoch){
         
         boolean predicate = true;
-        if(votes.get(leader) == null) predicate = false;
-        else if(votes.get(leader).state != ServerState.LEADING) predicate = false;
+
+        /*
+         * If everyone else thinks I'm the leader, I must be the leader.
+         * The other two checks are just for the case in which I'm not the
+         * leader. If I'm not the leader and I haven't received a message 
+         * from leader stating that it is leading, then predicate is false.          
+         */
+        
+        if(leader != self.getId()){
+            if(votes.get(leader) == null) predicate = false;
+            else if(votes.get(leader).state != ServerState.LEADING) predicate = false;
+        }
         
+        //LOG.info("Leader predicate: " + predicate);
         return predicate;
     }
     
@@ -643,13 +654,18 @@
                          * this leader, then processes will naturally move
                          * to a new epoch.
                          */
-                        if((n.state == ServerState.LEADING) && 
-                                (n.epoch == logicalclock)){
-                            self.setPeerState((n.leader == self.getId()) ? 
-                                    ServerState.LEADING: ServerState.FOLLOWING);
+                        if(n.epoch == logicalclock){
+                            recvset.put(n.sid, new Vote(n.leader, n.zxid, n.epoch));
+                            if((n.state == ServerState.LEADING) ||
+                                    (termPredicate(recvset, new Vote(n.leader,
+                                            n.zxid, n.epoch, n.state))
+                                            && checkLeader(outofelection, n.leader,
n.epoch)) ){
+                                self.setPeerState((n.leader == self.getId()) ? 
+                                        ServerState.LEADING: ServerState.FOLLOWING);
                        
-                            leaveInstance();
-                            return new Vote(n.leader, n.zxid);
+                                leaveInstance();
+                                return new Vote(n.leader, n.zxid);
+                            } 
                         }
                     
                         LOG.info("Notification: " + n.leader + ", " + n.zxid + 
@@ -671,6 +687,7 @@
                             leaveInstance();
                             return new Vote(n.leader, n.zxid);
                         }
+                        
                         break;
                     }
                 }



Mime
View raw message