hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r802944 - in /hadoop/zookeeper/branches/branch-3.2: ./ src/java/main/org/apache/zookeeper/server/quorum/ src/java/test/org/apache/zookeeper/server/quorum/
Date Mon, 10 Aug 2009 22:25:40 GMT
Author: mahadev
Date: Mon Aug 10 22:25:40 2009
New Revision: 802944

URL: http://svn.apache.org/viewvc?rev=802944&view=rev
Log:
ZOOKEEPER-499. electionAlg should default to FLE (3) - regression (phunt 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/QuorumCnxManager.java
    hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
    hadoop/zookeeper/branches/branch-3.2/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.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=802944&r1=802943&r2=802944&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/CHANGES.txt (original)
+++ hadoop/zookeeper/branches/branch-3.2/CHANGES.txt Mon Aug 10 22:25:40 2009
@@ -53,6 +53,9 @@
 
   ZOOKEEPER-501. CnxManagerTest failed on hudson. (flavio via mahadev) 
 
+  ZOOKEEPER-499. electionAlg should default to FLE (3) - regression (phunt via
+  mahadev)
+
 IMPROVEMENTS:
 
 NEW FEATURES:

Modified: hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java?rev=802944&r1=802943&r2=802944&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
(original)
+++ hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java
Mon Aug 10 22:25:40 2009
@@ -19,15 +19,13 @@
 package org.apache.zookeeper.server.quorum;
 
 import java.io.IOException;
-import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.Socket;
-import java.net.UnknownHostException;
 import java.nio.ByteBuffer;
 import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.SocketChannel;
+import java.nio.channels.UnresolvedAddressException;
 import java.util.Enumeration;
-import java.util.Random;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -316,17 +314,28 @@
      */
     
     synchronized void connectOne(long sid){
-        
-        if ((senderWorkerMap.get(sid) == null)){ 
+        if (senderWorkerMap.get(sid) == null){ 
+            InetSocketAddress electionAddr =
+                self.quorumPeers.get(sid).electionAddr;
             try {
                 SocketChannel channel;
                 LOG.debug("Opening channel to server "  + sid);
-                channel = SocketChannel
-                        .open(self.quorumPeers.get(sid).electionAddr);
+                channel = SocketChannel.open(electionAddr);
                 channel.socket().setTcpNoDelay(true);
                 initiateConnection(channel, sid);
+            } catch (UnresolvedAddressException e) {
+                // Sun doesn't include the address that causes this
+                // exception to be thrown, also UAE cannot be wrapped cleanly
+                // so we log the exception in order to capture this critical
+                // detail.
+                LOG.warn("Cannot open channel to " + sid
+                        + " at election address " + electionAddr,
+                        e);
+                throw e;
             } catch (IOException e) {
-                LOG.warn("Cannot open channel to " + sid, e);
+                LOG.warn("Cannot open channel to " + sid
+                        + " at election address " + electionAddr,
+                        e);
             }
         } else {
             LOG.error("There is a connection for server " + sid);

Modified: hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java?rev=802944&r1=802943&r2=802944&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
(original)
+++ hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
Mon Aug 10 22:25:40 2009
@@ -47,8 +47,8 @@
 
     protected int initLimit;
     protected int syncLimit;
-    protected int electionAlg;
-    protected int electionPort;
+    protected int electionAlg = 3;
+    protected int electionPort = 2182;
     protected int maxClientCnxns = 10;
     protected final HashMap<Long,QuorumServer> servers =
         new HashMap<Long, QuorumServer>();

Modified: hadoop/zookeeper/branches/branch-3.2/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.2/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java?rev=802944&r1=802943&r2=802944&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java
(original)
+++ hadoop/zookeeper/branches/branch-3.2/src/java/test/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java
Mon Aug 10 22:25:40 2009
@@ -181,11 +181,11 @@
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         WriterAppender appender = new WriterAppender(layout, os);
         appender.setThreshold(Level.WARN);
-        Logger.getLogger(org.apache.zookeeper.server.quorum.QuorumPeer.class)
-            .addAppender(appender);
+        Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum");
+        qlogger.addAppender(appender);
 
         try {
-            final int CLIENT_PORT_QP1 = 3181;
+            final int CLIENT_PORT_QP1 = 3191;
             final int CLIENT_PORT_QP2 = CLIENT_PORT_QP1 + 3;
 
             String quorumCfgSection =
@@ -202,23 +202,22 @@
                         5000);
 
             assertFalse("Server never came up", isup);
-            
+
             q1.shutdown();
 
             assertTrue("waiting for server 1 down",
                     ClientBase.waitForServerDown("localhost:" + CLIENT_PORT_QP1,
                             ClientBase.CONNECTION_TIMEOUT));
-            
+
         } finally {
-            Logger.getLogger(org.apache.zookeeper.server.quorum.QuorumPeer.class)
-                .removeAppender(appender);
+            qlogger.removeAppender(appender);
         }
 
         LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
         String line;
         boolean found = false;
         Pattern p =
-            Pattern.compile(".*IllegalArgumentException.*fee.fii.foo.fum.*");
+            Pattern.compile(".*Cannot open channel to .* at election address .*");
         while ((line = r.readLine()) != null) {
             found = p.matcher(line).matches();
             if (found) {
@@ -228,6 +227,75 @@
         assertTrue("complains about host", found);
     }
 
+
+    /**
+     * Verify handling of quorum defaults
+     * * default electionAlg is fast leader election
+     */
+    @Test
+    public void testQuorumDefaults() throws Exception {
+        LOG.info("STARTING " + getName());
+        ClientBase.setupTestEnv();
+
+        // setup the logger to capture all logs
+        Layout layout =
+            Logger.getRootLogger().getAppender("CONSOLE").getLayout();
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        WriterAppender appender = new WriterAppender(layout, os);
+        appender.setThreshold(Level.WARN);
+        Logger zlogger = Logger.getLogger("org.apache.zookeeper");
+        zlogger.addAppender(appender);
+
+        try {
+            final int CLIENT_PORT_QP1 = 3171;
+            final int CLIENT_PORT_QP2 = CLIENT_PORT_QP1 + 3;
+
+            String quorumCfgSection =
+                "server.1=localhost:" + (CLIENT_PORT_QP1 + 1)
+                + ":" + (CLIENT_PORT_QP1 + 2)
+                + "\nserver.2=localhost:" + (CLIENT_PORT_QP2 + 1)
+                + ":" + (CLIENT_PORT_QP2 + 2);
+
+            MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
+            MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);
+            q1.start();
+            q2.start();
+
+            assertTrue("waiting for server 1 being up",
+                    ClientBase.waitForServerUp("localhost:" + CLIENT_PORT_QP1,
+                            CONNECTION_TIMEOUT));
+            assertTrue("waiting for server 2 being up",
+                    ClientBase.waitForServerUp("localhost:" + CLIENT_PORT_QP2,
+                            CONNECTION_TIMEOUT));
+
+            q1.shutdown();
+            q2.shutdown();
+
+            assertTrue("waiting for server 1 down",
+                    ClientBase.waitForServerDown("localhost:" + CLIENT_PORT_QP1,
+                            ClientBase.CONNECTION_TIMEOUT));
+            assertTrue("waiting for server 2 down",
+                    ClientBase.waitForServerDown("localhost:" + CLIENT_PORT_QP2,
+                            ClientBase.CONNECTION_TIMEOUT));
+
+        } finally {
+            zlogger.removeAppender(appender);
+        }
+
+        LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
+        String line;
+        boolean found = false;
+        Pattern p =
+            Pattern.compile(".*FastLeaderElection.*");
+        while ((line = r.readLine()) != null) {
+            found = p.matcher(line).matches();
+            if (found) {
+                break;
+            }
+        }
+        assertTrue("fastleaderelection used", found);
+    }
+
     public void process(WatchedEvent event) {
         // ignore for this test
     }



Mime
View raw message