You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2017/02/13 11:29:47 UTC
[07/40] ignite git commit: IGNITE-4545 Added cache for router
hostnames. - Fixes #1428.
IGNITE-4545 Added cache for router hostnames. - Fixes #1428.
Signed-off-by: Andrey Novikov <an...@gridgain.com>
(cherry picked from commit 27ba69b)
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/71176473
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/71176473
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/71176473
Branch: refs/heads/ignite-2.0
Commit: 71176473f9fd0aa2088ba4e611ba4b7fc45e76b8
Parents: c3eae9f
Author: Andrey Novikov <an...@gridgain.com>
Authored: Mon Jan 16 11:22:34 2017 +0700
Committer: Andrey Novikov <an...@gridgain.com>
Committed: Tue Jan 17 12:43:16 2017 +0700
----------------------------------------------------------------------
.../GridClientConnectionManagerAdapter.java | 7 ++-
.../impl/connection/GridClientTopology.java | 53 ++++++++++++++++----
2 files changed, 49 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/71176473/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientConnectionManagerAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientConnectionManagerAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientConnectionManagerAdapter.java
index 6ea7c22..0928c90 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientConnectionManagerAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientConnectionManagerAdapter.java
@@ -85,6 +85,9 @@ public abstract class GridClientConnectionManagerAdapter implements GridClientCo
/** Class logger. */
private final Logger log;
+ /** All local enabled MACs. */
+ private final Collection<String> macs;
+
/** NIO server. */
private GridNioServer srv;
@@ -166,6 +169,8 @@ public abstract class GridClientConnectionManagerAdapter implements GridClientCo
if (marshId == null && cfg.getMarshaller() == null)
throw new GridClientException("Failed to start client (marshaller is not configured).");
+ macs = U.allLocalMACs();
+
if (cfg.getProtocol() == GridClientProtocol.TCP) {
try {
IgniteLogger gridLog = new JavaLogger(false);
@@ -315,7 +320,7 @@ public abstract class GridClientConnectionManagerAdapter implements GridClientCo
}
boolean sameHost = node.attributes().isEmpty() ||
- F.containsAny(U.allLocalMACs(), node.attribute(ATTR_MACS).toString().split(", "));
+ F.containsAny(macs, node.attribute(ATTR_MACS).toString().split(", "));
Collection<InetSocketAddress> srvs = new LinkedHashSet<>();
http://git-wip-us.apache.org/repos/asf/ignite/blob/71176473/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientTopology.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientTopology.java b/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientTopology.java
index effd5b3..97aa586 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientTopology.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientTopology.java
@@ -21,7 +21,6 @@ import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
@@ -61,12 +60,18 @@ public class GridClientTopology {
/** Cached last error prevented topology from update. */
private GridClientException lastError;
+ /** Router addresses from configuration. */
+ private final String routers;
+
/**
* Set of router addresses to infer direct connectivity
* when client is working in router connection mode.
* {@code null} when client is working in direct connection node.
*/
- private final Set<String> routerAddrs;
+ private final Set<InetSocketAddress> routerAddrs;
+
+ /** List of all known local MACs */
+ private final Collection<String> macsCache;
/** Protocol. */
private final GridClientProtocol prot;
@@ -96,8 +101,38 @@ public class GridClientTopology {
metricsCache = cfg.isEnableMetricsCache();
attrCache = cfg.isEnableAttributesCache();
prot = cfg.getProtocol();
- routerAddrs = (!cfg.getRouters().isEmpty() && cfg.getServers().isEmpty()) ?
- new HashSet<>(cfg.getRouters()) : null;
+
+ if (!cfg.getRouters().isEmpty() && cfg.getServers().isEmpty()) {
+ routers = cfg.getRouters().toString();
+
+ routerAddrs = U.newHashSet(cfg.getRouters().size());
+
+ for (String router : cfg.getRouters()) {
+ int portIdx = router.lastIndexOf(":");
+
+ if (portIdx > 0) {
+ String hostName = router.substring(0, portIdx);
+
+ try {
+ int port = Integer.parseInt(router.substring(portIdx + 1));
+
+ InetSocketAddress inetSockAddr = new InetSocketAddress(hostName, port);
+
+ routerAddrs.add(inetSockAddr);
+ }
+ catch (Exception ignore) {
+ // No-op.
+ }
+ }
+ }
+ }
+ else {
+ routers = null;
+
+ routerAddrs = Collections.emptySet();
+ }
+
+ macsCache = U.allLocalMACs();
}
/**
@@ -279,7 +314,7 @@ public class GridClientTopology {
try {
if (lastError != null)
throw new GridClientDisconnectedException(
- "Topology is failed [protocol=" + prot + ", routers=" + routerAddrs + ']', lastError);
+ "Topology is failed [protocol=" + prot + ", routers=" + routers + ']', lastError);
else
return nodes.get(id);
}
@@ -376,19 +411,17 @@ public class GridClientTopology {
(metricsCache && attrCache) || (node.attributes().isEmpty() && node.metrics() == null);
// Try to bypass object copying.
- if (noAttrsAndMetrics && routerAddrs == null && node.connectable())
+ if (noAttrsAndMetrics && routerAddrs.isEmpty() && node.connectable())
return node;
// Return a new node instance based on the original one.
GridClientNodeImpl.Builder nodeBuilder = GridClientNodeImpl.builder(node, !attrCache, !metricsCache);
for (InetSocketAddress addr : node.availableAddresses(prot, true)) {
- boolean router = routerAddrs == null ||
- routerAddrs.contains(addr.getHostName() + ":" + addr.getPort()) ||
- routerAddrs.contains(addr.getAddress().getHostAddress() + ":" + addr.getPort());
+ boolean router = routerAddrs.isEmpty() || routerAddrs.contains(addr);
boolean reachable = noAttrsAndMetrics || !addr.getAddress().isLoopbackAddress() ||
- F.containsAny(U.allLocalMACs(), node.attribute(ATTR_MACS).toString().split(", "));
+ F.containsAny(macsCache, node.<String>attribute(ATTR_MACS).split(", "));
if (router && reachable) {
nodeBuilder.connectable(true);