You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2019/08/13 14:27:27 UTC
[GitHub] [zookeeper] anmolnar commented on a change in pull request #1048:
ZOOKEEPER-3188: Improve resilience to network
anmolnar commented on a change in pull request #1048: ZOOKEEPER-3188: Improve resilience to network
URL: https://github.com/apache/zookeeper/pull/1048#discussion_r313423346
##########
File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/Leader.java
##########
@@ -271,39 +278,42 @@ public boolean isQuorumSynced(QuorumVerifier qv) {
return qv.containsQuorum(ids);
}
- private final ServerSocket ss;
+ private final List<ServerSocket> serverSockets = new LinkedList<>();
Leader(QuorumPeer self,LeaderZooKeeperServer zk) throws IOException {
this.self = self;
this.proposalStats = new BufferStats();
+
+ Set<InetSocketAddress> addresses;
+ if (self.getQuorumListenOnAllIPs()) {
+ addresses = self.getQuorumAddress().getWildcardAddresses();
+ } else {
+ addresses = self.getQuorumAddress().getAllAddresses();
+ }
+
+ for (InetSocketAddress address : addresses) {
+ serverSockets.add(createServerSocket(address, self.shouldUsePortUnification(), self.isSslQuorum()));
+ }
+
+ this.zk = zk;
+ }
+
+ ServerSocket createServerSocket(InetSocketAddress address, boolean portUnification, boolean sslQuorum)
+ throws IOException {
+ ServerSocket serverSocket;
try {
- if (self.shouldUsePortUnification() || self.isSslQuorum()) {
- boolean allowInsecureConnection = self.shouldUsePortUnification();
- if (self.getQuorumListenOnAllIPs()) {
- ss = new UnifiedServerSocket(self.getX509Util(), allowInsecureConnection, self.getQuorumAddress().getPort());
- } else {
- ss = new UnifiedServerSocket(self.getX509Util(), allowInsecureConnection);
- }
+ if (portUnification || sslQuorum) {
+ serverSocket = new UnifiedServerSocket(self.getX509Util(), portUnification);
} else {
- if (self.getQuorumListenOnAllIPs()) {
- ss = new ServerSocket(self.getQuorumAddress().getPort());
- } else {
- ss = new ServerSocket();
- }
- }
- ss.setReuseAddress(true);
- if (!self.getQuorumListenOnAllIPs()) {
- ss.bind(self.getQuorumAddress());
+ serverSocket = new ServerSocket();
}
+ serverSocket.setReuseAddress(true);
+ serverSocket.bind(address);
+ return serverSocket;
} catch (BindException 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);
- }
+ LOG.error("Couldn't bind to " + self.getQuorumAddress(), e);
Review comment:
Instead of `self.getQuorumAddress()`, you should print `address`, because that's the actual address that you're trying to bind.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services