[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16056019#comment-16056019 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user hanm commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/173#discussion_r123022889 --- Diff: src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml --- @@ -1076,6 +1076,26 @@ server.3=zoo3:2888:3888 + +zookeeper.ipReachableTimeout --- End diff -- Thanks @bensherman for pointing this out. Fixed in commit 677b5ccb7ce214eee750fda70eba3643d8c7a6c0. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2, 3.4.11 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: Jiang Jiafu >Assignee: Jiang Jiafu >Priority: Minor > Fix For: 3.4.11 > > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr =
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16054773#comment-16054773 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user bensherman commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/173#discussion_r120952370 --- Diff: src/docs/src/documentation/content/xdocs/zookeeperAdmin.xml --- @@ -1076,6 +1076,26 @@ server.3=zoo3:2888:3888 + +zookeeper.ipReachableTimeout --- End diff -- Looks like there is a small problem with this as I add my change to documentation. Shouldn't this say `ipReachableTimeout ` zookeeper is added by the system property setter, but isn't required (and won't work) if it is actually in the config file. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2, 3.4.11 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: Jiang Jiafu >Assignee: Jiang Jiafu >Priority: Minor > Fix For: 3.4.11 > > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16027209#comment-16027209 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user JiangJiafu closed the pull request at: https://github.com/apache/zookeeper/pull/173 > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2, 3.4.11 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > Fix For: 3.4.11 > > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > public InetAddress getReachableAddress(String hostname) throws >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16026965#comment-16026965 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user hanm commented on the issue: https://github.com/apache/zookeeper/pull/173 PR merged, please close this @JiangJiafu > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2, 3.4.11 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > Fix For: 3.4.11 > > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > public InetAddress
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16026961#comment-16026961 ] Michael Han commented on ZOOKEEPER-2691: [~phunt], [~rakeshr], please add JiangJiafu to contributor list and assign this JIRA to him. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2, 3.4.11 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > Fix For: 3.4.11 > > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > public InetAddress getReachableAddress(String hostname) throws > UnknownHostException { >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16022297#comment-16022297 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user hanm commented on the issue: https://github.com/apache/zookeeper/pull/173 Thanks for updates, @JiangJiafu. Patch looks good to me, will merge soon. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2, 3.4.11 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > public InetAddress
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16018735#comment-16018735 ] JiangJiafu commented on ZOOKEEPER-2691: --- Can this patch be merged? > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2, 3.4.11 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > public InetAddress getReachableAddress(String hostname) throws > UnknownHostException { > InetAddress[] addresses = InetAddress.getAllByName(hostname); > for (InetAddress
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16013761#comment-16013761 ] Hadoop QA commented on ZOOKEEPER-2691: -- -1 overall. GitHub Pull Request Build +1 @author. The patch does not contain any @author tags. +0 tests included. The patch appears to be a documentation patch that doesn't require tests. -1 javadoc. The javadoc tool appears to have generated 1 warning messages. +1 javac. The applied patch does not increase the total number of javac compiler warnings. -1 findbugs. The patch appears to introduce 90 new Findbugs (version 3.0.1) warnings. +1 release audit. The applied patch does not increase the total number of release audit warnings. +1 core tests. The patch passed core unit tests. +1 contrib tests. The patch passed contrib unit tests. Test results: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/696//testReport/ Findbugs warnings: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/696//artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html Console output: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/696//console This message is automatically generated. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2, 3.4.11 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16013742#comment-16013742 ] Hadoop QA commented on ZOOKEEPER-2691: -- -1 overall. GitHub Pull Request Build +1 @author. The patch does not contain any @author tags. +0 tests included. The patch appears to be a documentation patch that doesn't require tests. -1 javadoc. The javadoc tool appears to have generated 1 warning messages. +1 javac. The applied patch does not increase the total number of javac compiler warnings. -1 findbugs. The patch appears to introduce 90 new Findbugs (version 3.0.1) warnings. +1 release audit. The applied patch does not increase the total number of release audit warnings. +1 core tests. The patch passed core unit tests. +1 contrib tests. The patch passed contrib unit tests. Test results: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/695//testReport/ Findbugs warnings: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/695//artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html Console output: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/695//console This message is automatically generated. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2, 3.4.11 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16013718#comment-16013718 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user JiangJiafu commented on the issue: https://github.com/apache/zookeeper/pull/173 Please have a look to the new code, thank you. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2, 3.4.11 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > public InetAddress getReachableAddress(String hostname) throws
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16012725#comment-16012725 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user hanm commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/173#discussion_r116799126 --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java --- @@ -117,13 +117,21 @@ private QuorumServer(long id, InetSocketAddress addr, this.id = id; this.addr = addr; this.electionAddr = electionAddr; +String ipReachableValue = System.getProperty("zookeeper.ipReachableTimeout"); --- End diff -- This code is duplicated four times, not good :) - you can pull this into a dedicated function instead. Also make sure to add try catch around the parseInt to prevent crash against illegal input values. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2, 3.4.11 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16012719#comment-16012719 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user hanm commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/173#discussion_r116798516 --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java --- @@ -198,6 +246,12 @@ public void recreateSocketAddresses() { public long id; public LearnerType type = LearnerType.PARTICIPANT; + +/** + * the time, in milliseconds, before {@link InetAddress#isReachable} aborts + * in {@link #getReachableAddress}. + */ +private int ipReachableTimeout = 0; --- End diff -- I think we can remove this. This will also remove the four copies of exact same initialization code fragment that you use to initialize the value. We can get the sys property and parse the value inside recreateSocketAddress directly. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2, 3.4.11 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16007921#comment-16007921 ] Hadoop QA commented on ZOOKEEPER-2691: -- -1 overall. GitHub Pull Request Build +1 @author. The patch does not contain any @author tags. +0 tests included. The patch appears to be a documentation patch that doesn't require tests. -1 javadoc. The javadoc tool appears to have generated 1 warning messages. +1 javac. The applied patch does not increase the total number of javac compiler warnings. -1 findbugs. The patch appears to introduce 90 new Findbugs (version 3.0.1) warnings. +1 release audit. The applied patch does not increase the total number of release audit warnings. +1 core tests. The patch passed core unit tests. +1 contrib tests. The patch passed contrib unit tests. Test results: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/680//testReport/ Findbugs warnings: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/680//artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html Console output: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/680//console This message is automatically generated. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > }
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16007918#comment-16007918 ] Hadoop QA commented on ZOOKEEPER-2691: -- -1 overall. GitHub Pull Request Build +1 @author. The patch does not contain any @author tags. +0 tests included. The patch appears to be a documentation patch that doesn't require tests. -1 javadoc. The javadoc tool appears to have generated 1 warning messages. +1 javac. The applied patch does not increase the total number of javac compiler warnings. -1 findbugs. The patch appears to introduce 90 new Findbugs (version 3.0.1) warnings. +1 release audit. The applied patch does not increase the total number of release audit warnings. +1 core tests. The patch passed core unit tests. +1 contrib tests. The patch passed contrib unit tests. Test results: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/679//testReport/ Findbugs warnings: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/679//artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html Console output: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/679//console This message is automatically generated. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > }
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16007652#comment-16007652 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user hanm commented on the issue: https://github.com/apache/zookeeper/pull/173 I'll review later, but a quick answer to your question on how to update doc: no don't modify the html directly. Instead only modify the source of the docs. The sources are in folder src/docs/src/documentation/content/xdocs . In addition it would be good to verify your doc change locally by compiling the doc source with apache forrest (https://forrest.apache.org/). But please don't include the compiled documents (the html and pdf files) as part of the patch - you only need to change the source of the documents. You can check commit history of src/docs/src/documentation/content/xdocs and learn by example, should be pretty straightforward.. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16007623#comment-16007623 ] Hadoop QA commented on ZOOKEEPER-2691: -- -1 overall. GitHub Pull Request Build +1 @author. The patch does not contain any @author tags. +0 tests included. The patch appears to be a documentation patch that doesn't require tests. -1 javadoc. The javadoc tool appears to have generated 1 warning messages. +1 javac. The applied patch does not increase the total number of javac compiler warnings. -1 findbugs. The patch appears to introduce 90 new Findbugs (version 3.0.1) warnings. +1 release audit. The applied patch does not increase the total number of release audit warnings. -1 core tests. The patch failed core unit tests. +1 contrib tests. The patch passed contrib unit tests. Test results: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/678//testReport/ Findbugs warnings: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/678//artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html Console output: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/678//console This message is automatically generated. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > }
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16007588#comment-16007588 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user JiangJiafu commented on the issue: https://github.com/apache/zookeeper/pull/173 @hanm Hi, I have modified the code according to your advices except the second one: "Documentation (see Abe's comment)" > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16007456#comment-16007456 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user JiangJiafu commented on the issue: https://github.com/apache/zookeeper/pull/173 Eh, sorry for asking this question, but how to update the documentation? Should I modify the html files in docs directory? > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16007180#comment-16007180 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user hanm commented on the issue: https://github.com/apache/zookeeper/pull/173 @JiangJiafu Apologize for lagging on code review. I think this patch still needs a little bit work to get it merged: * Provide a way to use old address creation function by checking the sys property (See my comment in code.). * Documentation (see Abe's comment) * Typo (see Edward's comment) > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16007175#comment-16007175 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user hanm commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/173#discussion_r116099795 --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java --- @@ -181,6 +197,33 @@ public void recreateSocketAddresses() { } } +/** + * Resolve the hostname to IP addresses, and find one reachable address. + * + * @param hostname the name of the host + * @param timeout the time, in millseconds, before {@link InetAddress#isReachable} + *aborts + * @return a reachable IP address. If no such IP address can be found, + * just return the first IP address of the hostname. + * + * @exception UnknownHostException + */ +public InetAddress getReachableAddress(String hostname, int timeout) +throws UnknownHostException { +InetAddress[] addresses = InetAddress.getAllByName(hostname); +for (InetAddress a : addresses) { +try { +if (a.isReachable(timeout)) { --- End diff -- I think this is a valid concern. On top of this, I think we should make sure user can resort to old behavior if needed. With this patch the `isReachable` will be called in any case, regardless of the property 'zookeeper.ipReachableTimeout' is defined or not. How about something like this: if (zookeeper.ipReachableTimeout is not defined) { address = InetAddress.getByName(this.hostname); } else { address = getReachableAddress(this.hostname, ipReachableTimeout); } > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16006277#comment-16006277 ] Hadoop QA commented on ZOOKEEPER-2691: -- -1 overall. GitHub Pull Request Build +1 @author. The patch does not contain any @author tags. +1 tests included. The patch appears to include 3 new or modified tests. -1 javadoc. The javadoc tool appears to have generated 1 warning messages. +1 javac. The applied patch does not increase the total number of javac compiler warnings. -1 findbugs. The patch appears to introduce 90 new Findbugs (version 3.0.1) warnings. +1 release audit. The applied patch does not increase the total number of release audit warnings. +1 core tests. The patch passed core unit tests. +1 contrib tests. The patch passed contrib unit tests. Test results: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/677//testReport/ Findbugs warnings: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/677//artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html Console output: https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/677//console This message is automatically generated. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8, 3.4.9, 3.4.10, 3.5.0, 3.5.1, 3.5.2 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16005777#comment-16005777 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user JiangJiafu commented on the issue: https://github.com/apache/zookeeper/pull/173 @hanm Hi, May I ask when will this problem be fixed? And will it be fixed on 3.4.X(stable) version? Thanks. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > public InetAddress
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15884909#comment-15884909 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user eribeiro commented on the issue: https://github.com/apache/zookeeper/pull/173 @JiangJiafu @rakeshadr @hanm @fpj Guys, does my considerations on this comment https://github.com/apache/zookeeper/pull/173#discussion_r101845264 make any sense? Probably it's just me being paranoid and/or playing devil's advocate, but I would love to hear your opinions. Thanks! > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15873701#comment-15873701 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user eribeiro commented on the issue: https://github.com/apache/zookeeper/pull/173 @jiangjiafu glad to help. :) Thanks for driving this change. Great work. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > public InetAddress getReachableAddress(String hostname) throws >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15873694#comment-15873694 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user rakeshadr commented on the issue: https://github.com/apache/zookeeper/pull/173 I'm really sorry, I didn't get much time on this work. I could see very good discussions about this and I'm thinking you all are reaching to a pretty good solution. My previous comment was to converge the 3.4.10 release discussions and filter out tasks if it is not really important now. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15873517#comment-15873517 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user JiangJiafu commented on the issue: https://github.com/apache/zookeeper/pull/173 @rakeshadr Thank you for your respond. If you have decided how to fix this problem, please let me know. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > public InetAddress
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15873513#comment-15873513 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user rakeshadr commented on the issue: https://github.com/apache/zookeeper/pull/173 Thanks a lot @JiangJiafu for the effort in driving this. I'm not sure whether this is a blocker for 3.4.10 release. Is it good if we just release 3.4.10 without this and make it a blocker for 3.4.11 and 3.5.3-alpha? Also, we could set a time frame for 3.5.3-alpha release and mark this to beta version, later. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15873391#comment-15873391 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user JiangJiafu commented on the issue: https://github.com/apache/zookeeper/pull/173 @hanm Yes, I hope this PR can be solved in 3.4.10~ Since 3.5.X is still in alpha state now. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > public InetAddress getReachableAddress(String hostname)
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15872922#comment-15872922 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user JiangJiafu commented on the issue: https://github.com/apache/zookeeper/pull/173 @eribeiro Thank you for your review. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > public InetAddress getReachableAddress(String hostname) throws > UnknownHostException { >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15872522#comment-15872522 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user eribeiro commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/173#discussion_r101843611 --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java --- @@ -194,6 +237,12 @@ public void recreateSocketAddresses() { public long id; public LearnerType type = LearnerType.PARTICIPANT; + +/** + * the time, in millseconds, before {@link InetAddress#isReachable} aborts --- End diff -- typo: miliseconds. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15872519#comment-15872519 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user eribeiro commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/173#discussion_r101843864 --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java --- @@ -113,13 +113,21 @@ private QuorumServer(long id, InetSocketAddress addr, this.id = id; this.addr = addr; this.electionAddr = electionAddr; +String checkIPReachableValue = System.getProperty("zookeeper.checkIPTimeout"); +if(checkIPReachableValue != null){ --- End diff -- nit: space between if and ( > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15872520#comment-15872520 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user eribeiro commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/173#discussion_r101843810 --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java --- @@ -128,24 +136,32 @@ private QuorumServer(long id, InetSocketAddress addr, this.addr = addr; this.electionAddr = electionAddr; this.type = type; +String checkIPReachableValue = System.getProperty("zookeeper.checkIPTimeout"); +if(checkIPReachableValue != null){ --- End diff -- nit: space between if and ( > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15872521#comment-15872521 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user eribeiro commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/173#discussion_r101845264 --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java --- @@ -181,6 +197,33 @@ public void recreateSocketAddresses() { } } +/** + * Resolve the hostname to IP addresses, and find one reachable address. + * + * @param hostname the name of the host + * @param timeout the time, in millseconds, before {@link InetAddress#isReachable} + *aborts + * @return a reachable IP address. If no such IP address can be found, + * just return the first IP address of the hostname. + * + * @exception UnknownHostException + */ +public InetAddress getReachableAddress(String hostname, int timeout) +throws UnknownHostException { +InetAddress[] addresses = InetAddress.getAllByName(hostname); +for (InetAddress a : addresses) { +try { +if (a.isReachable(timeout)) { --- End diff -- My main problem with this PR is that call to `isReachable(timeout)` for two reasons: 1) the most important one: `isReachable(timeout)` seems unreliable so there are plenty cases where it returns false even tough the node is reachable or vice-versa! https://bugs.openjdk.java.net/browse/JDK-8159410 (google "InetAddress.isReachable not working" or "InetAddress.isReachable unreliable" to see further cases). 2) This timeout can add an arbitrary delay until a reachable node can be tested. IDK what a good compromise would be for both points above (leaving as it is today could work, so no problem, even tough I am a bit concerned), but maybe we could use a solution similar to ZOOKEEPER-2184 and return the next address in the array (using `next = ++next % addresses.length` to prevent out of bound exceptions). > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15872523#comment-15872523 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user eribeiro commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/173#discussion_r101843694 --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java --- @@ -128,24 +136,32 @@ private QuorumServer(long id, InetSocketAddress addr, this.addr = addr; this.electionAddr = electionAddr; this.type = type; +String checkIPReachableValue = System.getProperty("zookeeper.checkIPTimeout"); +if(checkIPReachableValue != null){ +this.checkIPReachableTO = Integer.parseInt(checkIPReachableValue); +} } public QuorumServer(long id, String hostname, Integer port, Integer electionPort, LearnerType type) { - this.id = id; - this.hostname=hostname; - if (port!=null){ + this.id = id; + this.hostname=hostname; + if (port!=null){ this.port=port; - } - if (electionPort!=null){ + } + if (electionPort!=null){ this.electionPort=electionPort; - } - if (type!=null){ + } + if (type!=null){ this.type = type; - } - this.recreateSocketAddresses(); } +String checkIPReachableValue = System.getProperty("zookeeper.checkIPTimeout"); +if(checkIPReachableValue != null){ --- End diff -- nit: space between `if` and `(` > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > }
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15872518#comment-15872518 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user eribeiro commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/173#discussion_r101843855 --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java --- @@ -113,13 +113,21 @@ private QuorumServer(long id, InetSocketAddress addr, this.id = id; this.addr = addr; this.electionAddr = electionAddr; +String checkIPReachableValue = System.getProperty("zookeeper.checkIPTimeout"); +if(checkIPReachableValue != null){ +this.checkIPReachableTO = Integer.parseInt(checkIPReachableValue); +} } // VisibleForTesting public QuorumServer(long id, InetSocketAddress addr) { this.id = id; this.addr = addr; this.electionAddr = null; +String checkIPReachableValue = System.getProperty("zookeeper.checkIPTimeout"); +if(checkIPReachableValue != null){ --- End diff -- nit: space between if and ( > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15872517#comment-15872517 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user eribeiro commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/173#discussion_r101846854 --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java --- @@ -113,13 +113,21 @@ private QuorumServer(long id, InetSocketAddress addr, this.id = id; this.addr = addr; this.electionAddr = electionAddr; +String checkIPReachableValue = System.getProperty("zookeeper.checkIPTimeout"); --- End diff -- I think we can improve this naming game just a little bit. Why not call this variable `ipTimeout`? And `checkIPReachableTO` as `ipReachableTimeout` or `reachableIPTimeout`? > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15872069#comment-15872069 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user hanm commented on the issue: https://github.com/apache/zookeeper/pull/173 @JiangJiafu What I meant is we can solve the problem (sharing code between this issue and ZOOKEEPER-2181) later, after both issues are merged in. We can make things progress by doing one step at a time. Regarding your question of 3.4.10, are you intended to have this patch being part of the incoming 3.4.10 release? > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15871005#comment-15871005 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user JiangJiafu commented on the issue: https://github.com/apache/zookeeper/pull/173 Hi, @hanm , do you mean that you will merge ZOOKEEPER-2691 and ZOOKEEPER-2184 to solve the problem later? If so, may I ask will the problem be solved in version zokkeper 3.4.10? > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15870909#comment-15870909 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user afine commented on the issue: https://github.com/apache/zookeeper/pull/173 nit: would this change be worth documenting? Otherwise, +1. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > public InetAddress getReachableAddress(String hostname) throws > UnknownHostException {
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15870905#comment-15870905 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user afine commented on the issue: https://github.com/apache/zookeeper/pull/173 sure, one is on the client and one is on the server but I do not think that means the problem is inherently different. I think it would be fair to say that both pr's revolve around what to do when the answer we select from dns is not one that we could use (they both revolve around calls to `InetAddress.getAllByName`). This patch description is framed in a way where we are assuming there is a list of possible ip addresses for some hostname and we just need to find one that is working. Nevertheless, this patch should work when the address the hostname resolves to changes entirely. Likewise, ZOOKEEPER-2184 should handle the "first record doesn't work" issue you are solving here. I think it may be valuable to have some shared code that effectively deals with mapping ip addresses to hostnames. After an offline discussion with @hanm we concluded that this may be good to look into after both 2691 and 2184 are merged in. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15870904#comment-15870904 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user hanm commented on the issue: https://github.com/apache/zookeeper/pull/173 >> on the surface this pr reminds me of ZOOKEEPER-2184, wondering if some of the logic can be shared? I had a chat with @afine offline again about this and I think Abe had a good point of view of both problems at a higher level - they are not resolving exact same problem but there is an opportunity that we could do some refactoring and code sharing regarding effectively map between usable IP and host names. This improvement could be done later though given the current many things in flight status to reduce the risk of this PR being stale... > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15868874#comment-15868874 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user hanm commented on the issue: https://github.com/apache/zookeeper/pull/173 Thanks for updates, @JiangJiafu. Patch looks good, and I agree that this patch is solving a different problem than ZOOKEEPER-2184. I'll give a few more days in case anyone has addition feedback before merging this in. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15866869#comment-15866869 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user afine commented on the issue: https://github.com/apache/zookeeper/pull/173 on the surface this pr reminds me of ZOOKEEPER-2184, wondering if some of the logic can be shared? we seem to be solving the same problem of dns resolutions not giving the "best" answers in more than one place. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15865213#comment-15865213 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user JiangJiafu commented on the issue: https://github.com/apache/zookeeper/pull/173 I have modified the source code according to your advise, please review the code. @hanm > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > public InetAddress getReachableAddress(String hostname) throws
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15864810#comment-15864810 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user JiangJiafu commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/173#discussion_r100940145 --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java --- @@ -159,7 +159,7 @@ public QuorumServer(long id, String hostname, public void recreateSocketAddresses() { InetAddress address = null; try { -address = InetAddress.getByName(this.hostname); +address = getReachableAddress(this.hostname, 2000); --- End diff -- Thanks for your advices, I will send another pull request later. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15864390#comment-15864390 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- Github user hanm commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/173#discussion_r100893741 --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java --- @@ -159,7 +159,7 @@ public QuorumServer(long id, String hostname, public void recreateSocketAddresses() { InetAddress address = null; try { -address = InetAddress.getByName(this.hostname); +address = getReachableAddress(this.hostname, 2000); --- End diff -- Instead of hardcoding 2000 here, we can have a constant variable represent the timeout value at the beginning of QuorumPeer.java. [QuorumCnxManager](https://github.com/apache/zookeeper/blob/master/src/java/main/org/apache/zookeeper/server/quorum/QuorumCnxManager.java) is a good example on how it uses constants. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { >
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15863527#comment-15863527 ] ASF GitHub Bot commented on ZOOKEEPER-2691: --- GitHub user JiangJiafu opened a pull request: https://github.com/apache/zookeeper/pull/173 ZOOKEEPER-2691: recreateSocketAddresses may recreate the unreachable … …IP address You can merge this pull request into a Git repository by running: $ git pull https://github.com/JiangJiafu/zookeeper ZOOKEEPER-2691 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/zookeeper/pull/173.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #173 commit 489cec9b78b21a2a241eeab18ddfb968758b2e67 Author: JiangJiafuDate: 2017-02-13T11:36:44Z ZOOKEEPER-2691: recreateSocketAddresses may recreate the unreachable IP address > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave
[jira] [Commented] (ZOOKEEPER-2691) recreateSocketAddresses may recreate the unreachable IP address
[ https://issues.apache.org/jira/browse/ZOOKEEPER-2691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15862575#comment-15862575 ] Michael Han commented on ZOOKEEPER-2691: Thank you for reporting this issue, [~jiangjiafu]. Would you like to submit a pull request to address this issue? The guideline of contribution is documented as https://cwiki.apache.org/confluence/display/ZOOKEEPER/HowToContribute. > recreateSocketAddresses may recreate the unreachable IP address > --- > > Key: ZOOKEEPER-2691 > URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2691 > Project: ZooKeeper > Issue Type: Bug >Affects Versions: 3.4.8 > Environment: Centos6.5 > Java8 > ZooKeeper3.4.8 >Reporter: JiangJiafu >Priority: Minor > > The QuorumPeer$QuorumServer.recreateSocketAddress() is used to resolved the > hostname to a new IP address(InetAddress) when any exception happens to the > socket. It will be very useful when a hostname can be resolved to more than > one IP address. > But the problem is Java API InetAddress.getByName(String hostname) will > always return the first IP address when the hostname can be resolved to more > than one IP address, and the first IP address may be unreachable forever. For > example, if a machine has two network interfaces: eth0, eth1, say eth0 has > ip1, eth1 has ip2, the relationship between hostname and the IP addresses is > set in /etc/hosts. When I "close" the eth0 by command "ifdown eth0", the > InetAddress.getByName(String hostname) will still return ip1, which is > unreachable forever. > So I think it will be better to check the IP address by > InetAddress.isReachable(long) and choose the reachable IP address. > I have modified the ZooKeeper source code, and test the new code in my own > environment, and it can work very well when I turn down some network > interfaces using "ifdown" command. > The original code is: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = InetAddress.getByName(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > {code} > After my modification: > {code:title=QuorumPeer.java|borderStyle=solid} > public void recreateSocketAddresses() { > InetAddress address = null; > try { > address = getReachableAddress(this.hostname); > LOG.info("Resolved hostname: {} to address: {}", > this.hostname, address); > this.addr = new InetSocketAddress(address, this.port); > if (this.electionPort > 0){ > this.electionAddr = new InetSocketAddress(address, > this.electionPort); > } > } catch (UnknownHostException ex) { > LOG.warn("Failed to resolve address: {}", this.hostname, ex); > // Have we succeeded in the past? > if (this.addr != null) { > // Yes, previously the lookup succeeded. Leave things as > they are > return; > } > // The hostname has never resolved. Create our > InetSocketAddress(es) as unresolved > this.addr = InetSocketAddress.createUnresolved(this.hostname, > this.port); > if (this.electionPort > 0){ > this.electionAddr = > InetSocketAddress.createUnresolved(this.hostname, > > this.electionPort); > } > } > } > public InetAddress