This is an automated email from the ASF dual-hosted git repository.
agoncharuk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 23a392a IGNITE-12873 Do not send hostnames when IP is used in
localHost - Fixes #7640.
23a392a is described below
commit 23a392a6dcee36c25d1b2c6b4e6a556a70d20fb4
Author: ktkalenko <[email protected]>
AuthorDate: Thu Apr 16 17:21:09 2020 +0300
IGNITE-12873 Do not send hostnames when IP is used in localHost - Fixes
#7640.
Signed-off-by: Alexey Goncharuk <[email protected]>
---
.../org/apache/ignite/IgniteSystemProperties.java | 9 ++
.../spi/communication/tcp/TcpCommunicationSpi.java | 17 ++-
.../tcp/GridTcpCommunicationSpiConfigSelfTest.java | 133 +++++++++++++++++++++
3 files changed, 153 insertions(+), 6 deletions(-)
diff --git
a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
index c4f9bb0..210a048 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
@@ -37,6 +37,7 @@ import
org.apache.ignite.internal.processors.metric.GridMetricManager;
import org.apache.ignite.internal.processors.rest.GridRestCommand;
import org.apache.ignite.internal.util.GridLogThrottle;
import org.apache.ignite.mxbean.MetricsMxBean;
+import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
import org.apache.ignite.stream.StreamTransformer;
import org.jetbrains.annotations.Nullable;
@@ -1297,6 +1298,14 @@ public final class IgniteSystemProperties {
public static final String IGNITE_ENABLE_EXTRA_INDEX_REBUILD_LOGGING =
"IGNITE_ENABLE_EXTRA_INDEX_REBUILD_LOGGING";
/**
+ * Enables setting attribute value of {@link
+ * TcpCommunicationSpi#ATTR_HOST_NAMES ATTR_HOST_NAMES} when value {@link
+ * IgniteConfiguration#getLocalHost getLocalHost} is ip, for backward
+ * compatibility. By default, {@code false}.
+ */
+ public static final String IGNITE_TCP_COMM_SET_ATTR_HOST_NAMES =
"IGNITE_TCP_COMM_SET_ATTR_HOST_NAMES";
+
+ /**
* Enforces singleton.
*/
private IgniteSystemProperties() {
diff --git
a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
index dac29e3..97871d2 100755
---
a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
+++
b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
@@ -163,7 +163,10 @@ import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.thread.IgniteThread;
import org.jetbrains.annotations.Nullable;
+import static java.util.Collections.emptyList;
import static java.util.Objects.nonNull;
+import static
org.apache.ignite.IgniteSystemProperties.IGNITE_TCP_COMM_SET_ATTR_HOST_NAMES;
+import static org.apache.ignite.IgniteSystemProperties.getBoolean;
import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
import static org.apache.ignite.events.EventType.EVT_NODE_LEFT;
import static org.apache.ignite.failure.FailureType.CRITICAL_ERROR;
@@ -459,12 +462,10 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter
implements Communicati
private ConnectionPolicy chConnPlc;
/** */
- private boolean enableForcibleNodeKill = IgniteSystemProperties
- .getBoolean(IgniteSystemProperties.IGNITE_ENABLE_FORCIBLE_NODE_KILL);
+ private boolean enableForcibleNodeKill =
getBoolean(IgniteSystemProperties.IGNITE_ENABLE_FORCIBLE_NODE_KILL);
/** */
- private boolean enableTroubleshootingLog = IgniteSystemProperties
- .getBoolean(IgniteSystemProperties.IGNITE_TROUBLESHOOTING_LOGGER);
+ private boolean enableTroubleshootingLog =
getBoolean(IgniteSystemProperties.IGNITE_TROUBLESHOOTING_LOGGER);
/** Server listener. */
private final GridNioServerListener<Message> srvLsnr =
@@ -2330,10 +2331,14 @@ public class TcpCommunicationSpi extends
IgniteSpiAdapter implements Communicati
Collection<InetSocketAddress> extAddrs = addrRslvr == null ? null :
U.resolveAddresses(addrRslvr,
F.flat(Arrays.asList(addrs.get1(), addrs.get2())), boundTcpPort);
- HashMap<String, Object> res = new HashMap<>(5);
+ Map<String, Object> res = new HashMap<>(5);
+
+ boolean setEmptyHostNamesAttr =
!getBoolean(IGNITE_TCP_COMM_SET_ATTR_HOST_NAMES, false) &&
+ (!F.isEmpty(locAddr) &&
locHost.getHostAddress().equals(locAddr)) && !locHost.isAnyLocalAddress() &&
+ !locHost.isLoopbackAddress();
res.put(createSpiAttributeName(ATTR_ADDRS), addrs.get1());
- res.put(createSpiAttributeName(ATTR_HOST_NAMES), addrs.get2());
+ res.put(createSpiAttributeName(ATTR_HOST_NAMES),
setEmptyHostNamesAttr ? emptyList() : addrs.get2());
res.put(createSpiAttributeName(ATTR_PORT), boundTcpPort);
res.put(createSpiAttributeName(ATTR_SHMEM_PORT), boundTcpShmemPort
>= 0 ? boundTcpShmemPort : null);
res.put(createSpiAttributeName(ATTR_EXT_ADDRS), extAddrs);
diff --git
a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java
index 0aabf25..ffc0ddc 100644
---
a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java
+++
b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/GridTcpCommunicationSpiConfigSelfTest.java
@@ -17,11 +17,27 @@
package org.apache.ignite.spi.communication.tcp;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.util.Collection;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteSystemProperties;
import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.testframework.junits.GridAbstractTest;
+import org.apache.ignite.testframework.junits.WithSystemProperty;
import org.apache.ignite.testframework.junits.spi.GridSpiAbstractConfigTest;
import org.apache.ignite.testframework.junits.spi.GridSpiTest;
import org.junit.Test;
+import static java.util.Objects.isNull;
+import static java.util.Objects.requireNonNull;
+import static
org.apache.ignite.IgniteSystemProperties.IGNITE_TCP_COMM_SET_ATTR_HOST_NAMES;
+import static org.apache.ignite.IgniteSystemProperties.getBoolean;
+import static org.apache.ignite.internal.util.IgniteUtils.spiAttribute;
+import static
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.ATTR_HOST_NAMES;
import static org.apache.ignite.testframework.GridTestUtils.getFreeCommPort;
/**
@@ -30,6 +46,24 @@ import static
org.apache.ignite.testframework.GridTestUtils.getFreeCommPort;
@GridSpiTest(spi = TcpCommunicationSpi.class, group = "Communication SPI")
public class GridTcpCommunicationSpiConfigSelfTest extends
GridSpiAbstractConfigTest<TcpCommunicationSpi> {
/**
+ * Set value to {@link IgniteConfiguration#setLocalHost} after
+ * {@link GridAbstractTest#optimize}.
+ */
+ private String locHost = "0.0.0.0";
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ super.afterTest();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration optimize(IgniteConfiguration cfg)
throws IgniteCheckedException {
+ return super.optimize(cfg).setLocalHost(locHost);
+ }
+
+ /**
* @throws Exception If failed.
*/
@Test
@@ -71,4 +105,103 @@ public class GridTcpCommunicationSpiConfigSelfTest extends
GridSpiAbstractConfig
startGrid(cfg);
}
+ /**
+ * Test checks that attribute {@link TcpCommunicationSpi#ATTR_HOST_NAMES}
+ * is empty only if IP(don't wildcard and loopback) is set to {@link
IgniteConfiguration#setLocalHost}
+ * and property {@link
IgniteSystemProperties#IGNITE_TCP_COMM_SET_ATTR_HOST_NAMES} == {@code false}
+ * (default value).
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testEmptyHostNameAttrByDefault() throws Exception {
+ assertFalse(getBoolean(IGNITE_TCP_COMM_SET_ATTR_HOST_NAMES, false));
+
+ IgniteBiTuple<Collection<String>, Collection<String>> addrs =
U.resolveLocalAddresses(
+ new InetSocketAddress(0).getAddress()
+ );
+
+ String host = addrs.get2().iterator().next();
+
+ String ip = null;
+
+ for (String addr : addrs.get1()) {
+ InetAddress inetAddr = U.resolveLocalHost(addr);
+
+ if (!inetAddr.isLoopbackAddress() && !inetAddr.isAnyLocalAddress())
+ ip = addr;
+ }
+
+ assertNotNull("addrs=" + addrs, ip);
+
+ log.info("Testing ip=" + ip + " host=" + host);
+
+ int nodeIdx = 0;
+
+ locHost = ip;
+ checkHostNamesAttr(startGrid(nodeIdx++), false, true);
+
+ locHost = host;
+ checkHostNamesAttr(startGrid(nodeIdx++), false, false);
+
+ locHost = null;
+ checkHostNamesAttr(startGrid(nodeIdx++), true, false);
+
+ locHost = "0.0.0.0";
+ checkHostNamesAttr(startGrid(nodeIdx++), false, false);
+
+ stopAllGrids();
+
+ locHost = "127.0.0.1";
+ checkHostNamesAttr(startGrid(nodeIdx++), false, true);
+ }
+
+ /**
+ * Test checks that attribute {@link TcpCommunicationSpi#ATTR_HOST_NAMES}
is not empty.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ @WithSystemProperty(key = IGNITE_TCP_COMM_SET_ATTR_HOST_NAMES, value =
"true")
+ public void testNotEmptyHostNameAttr() throws Exception {
+ InetSocketAddress inetSockAddr = new InetSocketAddress(0);
+
+ String ip = inetSockAddr.getHostName();
+ String host =
U.resolveLocalAddresses(inetSockAddr.getAddress()).get2().iterator().next();
+
+ log.info("Testing ip=" + ip + " host=" + host);
+
+ int nodeIdx = 0;
+
+ locHost = ip;
+ checkHostNamesAttr(startGrid(nodeIdx++), false, false);
+
+ locHost = host;
+ checkHostNamesAttr(startGrid(nodeIdx++), false, false);
+
+ locHost = null;
+ checkHostNamesAttr(startGrid(nodeIdx++), true, false);
+ }
+
+ /**
+ * Checking local host on node.
+ *
+ * @param node Node.
+ * @param emptyLocHost Check whether {@link
+ * IgniteConfiguration#getLocalHost} is empty.
+ * @param emptyHostNamesAttr Check whether {@link
+ * TcpCommunicationSpi#ATTR_HOST_NAMES} attribute is empty.
+ */
+ private void checkHostNamesAttr(IgniteEx node, boolean emptyLocHost,
boolean emptyHostNamesAttr) {
+ requireNonNull(node);
+
+ IgniteConfiguration cfg = node.configuration();
+ assertEquals(emptyLocHost, isNull(cfg.getLocalHost()));
+
+ TcpCommunicationSpi spi =
(TcpCommunicationSpi)cfg.getCommunicationSpi();
+ assertEquals(
+ emptyHostNamesAttr,
+ ((Collection<String>)node.localNode().attribute(spiAttribute(spi,
ATTR_HOST_NAMES))).isEmpty()
+ );
+ }
}