Author: fpj Date: Wed Sep 25 21:44:11 2013 New Revision: 1526313 URL: http://svn.apache.org/r1526313 Log: ZOOKEEPER-1096. Leader communication should listen on specified IP, not wildcard address (Jared Cantwell, German Blanco via fpj)
Modified: zookeeper/branches/branch-3.4/CHANGES.txt zookeeper/branches/branch-3.4/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/Leader.java zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java Modified: zookeeper/branches/branch-3.4/CHANGES.txt URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1526313&r1=1526312&r2=1526313&view=diff ============================================================================== --- zookeeper/branches/branch-3.4/CHANGES.txt (original) +++ zookeeper/branches/branch-3.4/CHANGES.txt Wed Sep 25 21:44:11 2013 @@ -107,6 +107,8 @@ BUGFIXES: ZOOKEEPER-1753. ClientCnxn is not properly releasing the resources, which are used to ping RwServer (Rakesh R via fpj) + ZOOKEEPER-1096. Leader communication should listen on specified IP, not wildcard address (Jared Cantwell, German Blanco via fpj) + IMPROVEMENTS: ZOOKEEPER-1564. Allow JUnit test build with IBM Java Modified: zookeeper/branches/branch-3.4/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml?rev=1526313&r1=1526312&r2=1526313&view=diff ============================================================================== --- zookeeper/branches/branch-3.4/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml (original) +++ zookeeper/branches/branch-3.4/src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml Wed Sep 25 21:44:11 2013 @@ -1109,6 +1109,20 @@ server.3=zoo3:2888:3888</programlisting> but opens up full access to the data tree to everyone.</para> </listitem> </varlistentry> + + <varlistentry> + <term>quorumListenOnAllIPs</term> + + <listitem> + <para>When set to true the ZooKeeper server will listen + for connections from its peers on all available IP addresses, + and not only the address configured in the server list of the + configuration file. It affects the connections handling the + ZAB protocol and the Fast Leader Election protocol. Default + value is <emphasis role="bold">false</emphasis>.</para> + </listitem> + </varlistentry> + </variablelist> </section> Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/Leader.java URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/Leader.java?rev=1526313&r1=1526312&r2=1526313&view=diff ============================================================================== --- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/Leader.java (original) +++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/Leader.java Wed Sep 25 21:44:11 2013 @@ -39,6 +39,7 @@ import java.util.concurrent.ConcurrentLi import java.util.concurrent.ConcurrentMap; import org.apache.jute.BinaryOutputArchive; +import org.apache.zookeeper.server.ZooKeeperServer; import org.apache.zookeeper.server.FinalRequestProcessor; import org.apache.zookeeper.server.Request; import org.apache.zookeeper.server.RequestProcessor; @@ -182,12 +183,21 @@ public class Leader { Leader(QuorumPeer self,LeaderZooKeeperServer zk) throws IOException { this.self = self; try { - ss = new ServerSocket(); + if (self.getQuorumListenOnAllIPs()) { + ss = new ServerSocket(self.getQuorumAddress().getPort()); + } else { + ss = new ServerSocket(); + } ss.setReuseAddress(true); - ss.bind(new InetSocketAddress(self.getQuorumAddress().getPort())); + if (!self.getQuorumListenOnAllIPs()) { + ss.bind(self.getQuorumAddress()); + } } catch (BindException e) { - LOG.error("Couldn't bind to port " - + self.getQuorumAddress().getPort(), e); + if (self.getQuorumListenOnAllIPs()) { + LOG.error("Couldn't bind to port " + self.getQuorumAddress().getPort(), e); + } else { + LOG.error("Couldn't bind to " + self.getQuorumAddress(), e); + } throw e; } this.zk=zk; Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java?rev=1526313&r1=1526312&r2=1526313&view=diff ============================================================================== --- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java (original) +++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java Wed Sep 25 21:44:11 2013 @@ -39,6 +39,8 @@ import java.util.Date; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.zookeeper.server.ZooKeeperServer; + /** * This class implements a connection manager for leader election using TCP. It * maintains one connection for every pair of servers. The tricky part is to @@ -487,13 +489,17 @@ public class QuorumCnxManager { @Override public void run() { int numRetries = 0; + InetSocketAddress addr; while((!shutdown) && (numRetries < 3)){ try { ss = new ServerSocket(); ss.setReuseAddress(true); - int port = self.quorumPeers.get(self.getId()).electionAddr - .getPort(); - InetSocketAddress addr = new InetSocketAddress(port); + if (self.getQuorumListenOnAllIPs()) { + int port = self.quorumPeers.get(self.getId()).electionAddr.getPort(); + addr = new InetSocketAddress(port); + } else { + addr = self.quorumPeers.get(self.getId()).electionAddr; + } LOG.info("My election bind port: " + addr.toString()); setName(self.quorumPeers.get(self.getId()).electionAddr .toString()); Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java?rev=1526313&r1=1526312&r2=1526313&view=diff ============================================================================== --- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java (original) +++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java Wed Sep 25 21:44:11 2013 @@ -249,6 +249,12 @@ public class QuorumPeer extends Thread i protected volatile int tick; /** + * Whether or not to listen on all IPs for the two quorum ports + * (broadcast and fast leader election). + */ + protected boolean quorumListenOnAllIPs = false; + + /** * @deprecated As of release 3.4.0, this class has been deprecated, since * it is used with one of the udp-based versions of leader election, which * we are also deprecating. @@ -376,13 +382,14 @@ public class QuorumPeer extends Thread i long myid, int tickTime, int initLimit, int syncLimit, ServerCnxnFactory cnxnFactory) throws IOException { this(quorumPeers, dataDir, dataLogDir, electionType, myid, tickTime, - initLimit, syncLimit, cnxnFactory, + initLimit, syncLimit, false, cnxnFactory, new QuorumMaj(countParticipants(quorumPeers))); } public QuorumPeer(Map<Long, QuorumServer> quorumPeers, File dataDir, File dataLogDir, int electionType, long myid, int tickTime, int initLimit, int syncLimit, + boolean quorumListenOnAllIPs, ServerCnxnFactory cnxnFactory, QuorumVerifier quorumConfig) throws IOException { this(); @@ -393,6 +400,7 @@ public class QuorumPeer extends Thread i this.tickTime = tickTime; this.initLimit = initLimit; this.syncLimit = syncLimit; + this.quorumListenOnAllIPs = quorumListenOnAllIPs; this.logFactory = new FileTxnSnapLog(dataLogDir, dataDir); this.zkDb = new ZKDatabase(this.logFactory); if(quorumConfig == null) @@ -515,7 +523,7 @@ public class QuorumPeer extends Thread i throws IOException { this(quorumPeers, snapDir, logDir, electionAlg, - myid,tickTime, initLimit,syncLimit, + myid,tickTime, initLimit,syncLimit, false, ServerCnxnFactory.createFactory(new InetSocketAddress(clientPort), -1), new QuorumMaj(countParticipants(quorumPeers))); } @@ -531,7 +539,7 @@ public class QuorumPeer extends Thread i throws IOException { this(quorumPeers, snapDir, logDir, electionAlg, - myid,tickTime, initLimit,syncLimit, + myid,tickTime, initLimit,syncLimit, false, ServerCnxnFactory.createFactory(new InetSocketAddress(clientPort), -1), quorumConfig); } @@ -1016,6 +1024,14 @@ public class QuorumPeer extends Thread i this.electionType = electionType; } + public boolean getQuorumListenOnAllIPs() { + return quorumListenOnAllIPs; + } + + public void setQuorumListenOnAllIPs(boolean quorumListenOnAllIPs) { + this.quorumListenOnAllIPs = quorumListenOnAllIPs; + } + public ServerCnxnFactory getCnxnFactory() { return cnxnFactory; } Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java?rev=1526313&r1=1526312&r2=1526313&view=diff ============================================================================== --- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java (original) +++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java Wed Sep 25 21:44:11 2013 @@ -59,6 +59,7 @@ public class QuorumPeerConfig { protected int syncLimit; protected int electionAlg = 3; protected int electionPort = 2182; + protected boolean quorumListenOnAllIPs = false; protected final HashMap<Long,QuorumServer> servers = new HashMap<Long, QuorumServer>(); protected final HashMap<Long,QuorumServer> observers = @@ -157,6 +158,8 @@ public class QuorumPeerConfig { syncLimit = Integer.parseInt(value); } else if (key.equals("electionAlg")) { electionAlg = Integer.parseInt(value); + } else if (key.equals("quorumListenOnAllIPs")) { + quorumListenOnAllIPs = Boolean.parseBoolean(value); } else if (key.equals("peerType")) { if (value.toLowerCase().equals("observer")) { peerType = LearnerType.OBSERVER; @@ -408,4 +411,8 @@ public class QuorumPeerConfig { public LearnerType getPeerType() { return peerType; } + + public Boolean getQuorumListenOnAllIPs() { + return quorumListenOnAllIPs; + } } Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java?rev=1526313&r1=1526312&r2=1526313&view=diff ============================================================================== --- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java (original) +++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java Wed Sep 25 21:44:11 2013 @@ -147,6 +147,7 @@ public class QuorumPeerMain { quorumPeer.setCnxnFactory(cnxnFactory); quorumPeer.setZKDatabase(new ZKDatabase(quorumPeer.getTxnFactory())); quorumPeer.setLearnerType(config.getPeerType()); + quorumPeer.setQuorumListenOnAllIPs(config.getQuorumListenOnAllIPs()); quorumPeer.start(); quorumPeer.join(); Modified: zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java?rev=1526313&r1=1526312&r2=1526313&view=diff ============================================================================== --- zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java (original) +++ zookeeper/branches/branch-3.4/src/java/test/org/apache/zookeeper/test/LENonTerminateTest.java Wed Sep 25 21:44:11 2013 @@ -216,7 +216,7 @@ public class LENonTerminateTest extends throws IOException { super(quorumPeers, snapDir, logDir, electionAlg, - myid,tickTime, initLimit,syncLimit, + myid,tickTime, initLimit,syncLimit, false, ServerCnxnFactory.createFactory(clientPort, -1), new QuorumMaj(countParticipants(quorumPeers))); }