hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r800598 - in /hadoop/zookeeper/branches/branch-3.2: ./ src/java/main/org/apache/zookeeper/server/quorum/flexible/ src/java/test/org/apache/zookeeper/test/
Date Mon, 03 Aug 2009 22:29:43 GMT
Author: mahadev
Date: Mon Aug  3 22:29:42 2009
New Revision: 800598

URL: http://svn.apache.org/viewvc?rev=800598&view=rev
Log:
ZOOKEEPER-479.  QuorumHierarchical does not count groups correctly (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/flexible/QuorumHierarchical.java
    hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumMaj.java
    hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumVerifier.java
    hadoop/zookeeper/branches/branch-3.2/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.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=800598&r1=800597&r2=800598&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/CHANGES.txt (original)
+++ hadoop/zookeeper/branches/branch-3.2/CHANGES.txt Mon Aug  3 22:29:42 2009
@@ -26,6 +26,9 @@
 
   ZOOKEEPER-481. Add lastMessageSent to QuorumCnxManager. (flavio via mahadev)
 
+  ZOOKEEPER-479.  QuorumHierarchical does not count groups correctly (flavio
+via mahadev)
+
 IMPROVEMENTS:
 
 NEW FEATURES:

Modified: hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumHierarchical.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumHierarchical.java?rev=800598&r1=800597&r2=800598&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumHierarchical.java
(original)
+++ hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumHierarchical.java
Mon Aug  3 22:29:42 2009
@@ -104,12 +104,15 @@
         LOG.info(serverWeight.size() + ", " + serverGroup.size() + ", " + groupWeight.size());
     }
     
-    /**
-     * This contructor takes the two hash maps needed to enable 
-     * validating quorums. We use it with QuorumPeerConfig. That is,
-     * we declare weights and groups in the server configuration
-     * file along with the other parameters.
-     */
+   /**
+    *  This contructor takes the two hash maps needed to enable 
+    *  validating quorums. We use it with QuorumPeerConfig. That is,
+    *  we declare weights and groups in the server configuration
+    *  file along with the other parameters.
+    * @param numGroups
+    * @param serverWeight
+    * @param serverGroup
+    */
     public QuorumHierarchical(int numGroups,
             HashMap<Long, Long> serverWeight,
             HashMap<Long, Long> serverGroup)
@@ -124,6 +127,15 @@
     
     
     /**
+     * Returns the weight of a server.
+     * 
+     * @param id
+     */
+    public long getWeight(long id){
+        return serverWeight.get(id);
+    }
+    
+    /**
      * Reads a configration file. Called from the constructor
      * that takes a file as an input.
      */
@@ -200,9 +212,15 @@
             else {
                 long totalWeight = serverWeight.get(sid) + groupWeight.get(gid);
                 groupWeight.put(gid, totalWeight);
-            }
-            
-        }        
+            } 
+        }    
+        
+        /*
+         * Do not consider groups with weight zero
+         */
+        for(long weight: groupWeight.values()){
+            if(weight == 0) numGroups--;
+        }
     }
     
     /**
@@ -230,14 +248,14 @@
         /*
          * Check if all groups have majority
          */
-        boolean majPerGroup = true;
+        int majGroupCounter = 0;
         for(long gid : expansion.keySet()) {
             LOG.info("gid: " + expansion.get(gid));
-            if(expansion.get(gid) <= (groupWeight.get(gid) / 2) )
-                majPerGroup = false;
+            if(expansion.get(gid) > (groupWeight.get(gid) / 2) )
+                majGroupCounter++;
         }
         
-        if((expansion.size() > (numGroups / 2)) && majPerGroup){
+        if((majGroupCounter > (numGroups / 2))){
             LOG.info("Positive set size: " + set.size());
             return true;
         }

Modified: hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumMaj.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumMaj.java?rev=800598&r1=800597&r2=800598&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumMaj.java
(original)
+++ hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumMaj.java
Mon Aug  3 22:29:42 2009
@@ -31,12 +31,23 @@
     
     /**
      * Defines a majority to avoid computing it every time.
+     * 
+     * @param n number of servers
      */
     public QuorumMaj(int n){
         this.half = n/2;
     }
     
     /**
+     * Returns weight of 1 by default.
+     * 
+     * @param id 
+     */
+    public long getWeight(long id){
+        return (long) 1;
+    }
+    
+    /**
      * Verifies if a set is a majority.
      */
     public boolean containsQuorum(HashSet<Long> set){

Modified: hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumVerifier.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumVerifier.java?rev=800598&r1=800597&r2=800598&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumVerifier.java
(original)
+++ hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumVerifier.java
Mon Aug  3 22:29:42 2009
@@ -28,5 +28,6 @@
  */
 
 public interface QuorumVerifier {
+    long getWeight(long id);
     boolean containsQuorum(HashSet<Long> set);
 }
\ No newline at end of file

Modified: hadoop/zookeeper/branches/branch-3.2/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.2/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java?rev=800598&r1=800597&r2=800598&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java
(original)
+++ hadoop/zookeeper/branches/branch-3.2/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java
Mon Aug  3 22:29:42 2009
@@ -93,6 +93,7 @@
 
     protected void tearDown() throws Exception {
         for(int i = 0; i < threads.size(); i++) {
+            threads.get(i).peer.shutdown();
             ((FastLeaderElection) threads.get(i).peer.getElectionAlg()).shutdown();
         }
         LOG.info("FINISHED " + getName());
@@ -144,17 +145,26 @@
 
     @Test
     public void testHierarchicalQuorum() throws Exception {
+        runTest(0);
+    }
+    
+    @Test
+    public void testHierarchicalQuorumPartial() throws Exception {
+        runTest(3);
+    }
+    
+    private void runTest(int delta) throws Exception {
         FastLeaderElection le[] = new FastLeaderElection[count];
 
         LOG.info("TestHierarchicalQuorum: " + getName()+ ", " + count);
         for(int i = 0; i < count; i++) {
-            peers.put(Long.valueOf(i), new QuorumServer(i, new InetSocketAddress(baseport+100+i),
-                    new InetSocketAddress(baseLEport+100+i)));
+            peers.put(Long.valueOf(i), new QuorumServer(i, new InetSocketAddress(baseport+i),
+                    new InetSocketAddress(baseLEport+i)));
             tmpdir[i] = ClientBase.createTmpDir();
             port[i] = baseport+i;
         }
 
-        for(int i = 0; i < le.length; i++) {
+        for(int i = 0; i < (le.length - delta); i++) {
             QuorumHierarchical hq = new QuorumHierarchical(qp);
             QuorumPeer peer = new QuorumPeer(peers, tmpdir[i], tmpdir[i], port[i], 3, i,
2, 2, 2, hq);
             peer.startLeaderElection();



Mime
View raw message