Author: mahadev Date: Mon Aug 3 22:28:19 2009 New Revision: 800597 URL: http://svn.apache.org/viewvc?rev=800597&view=rev Log: ZOOKEEPER-479. QuorumHierarchical does not count groups correctly (flavio via mahadev)
Modified: hadoop/zookeeper/trunk/CHANGES.txt hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumHierarchical.java hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumMaj.java hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumVerifier.java hadoop/zookeeper/trunk/src/java/test/org/apache/zookeeper/test/HierarchicalQuorumTest.java Modified: hadoop/zookeeper/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=800597&r1=800596&r2=800597&view=diff ============================================================================== --- hadoop/zookeeper/trunk/CHANGES.txt (original) +++ hadoop/zookeeper/trunk/CHANGES.txt Mon Aug 3 22:28:19 2009 @@ -30,6 +30,9 @@ ZOOKEEPER-481. Add lastMessageSent to QuorumCnxManager. (flavio via mahadev) + ZOOKEEPER-479. QuorumHierarchical does not count groups correctly (flavio +via mahadev) + IMPROVEMENTS: ZOOKEEPER-473. cleanup junit tests to eliminate false positives due to "socket reuse" and failure to close client (phunt via mahadev) Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumHierarchical.java URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumHierarchical.java?rev=800597&r1=800596&r2=800597&view=diff ============================================================================== --- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumHierarchical.java (original) +++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumHierarchical.java Mon Aug 3 22:28:19 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/trunk/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumMaj.java URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumMaj.java?rev=800597&r1=800596&r2=800597&view=diff ============================================================================== --- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumMaj.java (original) +++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumMaj.java Mon Aug 3 22:28:19 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/trunk/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumVerifier.java URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumVerifier.java?rev=800597&r1=800596&r2=800597&view=diff ============================================================================== --- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumVerifier.java (original) +++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/flexible/QuorumVerifier.java Mon Aug 3 22:28:19 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/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=800597&r1=800596&r2=800597&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 Mon Aug 3 22:28:19 2009 @@ -146,19 +146,29 @@ @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++) { + int clientport = PortAssignment.unique(); peers.put(Long.valueOf(i), new QuorumServer(i, - new InetSocketAddress(PortAssignment.unique()), + new InetSocketAddress(clientport), new InetSocketAddress(PortAssignment.unique()))); tmpdir[i] = ClientBase.createTmpDir(); - port[i] = PortAssignment.unique(); + port[i] = clientport; } - 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();