Hello, My project currently has the need to specify the local address that is used for leader communication (and not use the default of listening on all interfaces). This is similar to the clientPortAddress parameter that was recently added. After reviewing the code, we can't think of a reason why only the port would be used with the wildcard interface, when servers are already connecting specifically to that interface anyway. Is binding to the wildcard interface for leader communication intentional?
I believe the change would be straightforward-- one change for each leader port used. Note: this doesn't account for all leader election algorithms, only the default. Index: src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java =================================================================== --- src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java (revision 989805) +++ src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java (working copy) @@ -434,7 +434,7 @@ ss = ServerSocketChannel.open(); int port = self.quorumPeers.get(self.getId()).electionAddr.getPort(); ss.socket().setReuseAddress(true); - InetSocketAddress addr = new InetSocketAddress(port); + InetSocketAddress addr = self.quorumPeers.get(self.getId()).electionAddr; LOG.info("My election bind port: " + addr.toString()); setName(addr.toString()); ss.socket().bind(addr); Index: src/java/main/org/apache/zookeeper/server/quorum/Leader.java =================================================================== --- src/java/main/org/apache/zookeeper/server/quorum/Leader.java (revision 989805) +++ src/java/main/org/apache/zookeeper/server/quorum/Leader.java (working copy) @@ -128,10 +128,11 @@ Leader(QuorumPeer self,LeaderZooKeeperServer zk) throws IOException { this.self = self; try { - ss = new ServerSocket(self.getQuorumAddress().getPort()); + ss = new ServerSocket(); + ss.bind(self.getQuorumAddress()); } catch (BindException e) { - LOG.error("Couldn't bind to port " - + self.getQuorumAddress().getPort(), e); + LOG.error("Couldn't bind to address " + + self.getQuorumAddress().getAddress() + ":" + self.getQuorumAddress().getPort(), e); throw e; } this.zk=zk; Does this seem like a reasonable change? Thoughts? ~Jared