From cb97b91a6037980cd87ec5b6d90c80fea2079ff2 Mon Sep 17 00:00:00 2001 From: javanna Date: Fri, 2 Dec 2016 00:34:33 +0100 Subject: [PATCH] Don't light connect to discovery nodes received from search shards Those discovery nodes are already enough to go ahead with the remote search, no need to light connect and update the discovery node, it's already updated. --- .../action/search/SearchTransportService.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchTransportService.java b/core/src/main/java/org/elasticsearch/action/search/SearchTransportService.java index a347d463a09..38bdea35631 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchTransportService.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchTransportService.java @@ -188,23 +188,23 @@ public class SearchTransportService extends AbstractComponent { if (nodes == null) { throw new IllegalArgumentException("no remote cluster configured with name [" + clusterName + "]"); } - DiscoveryNode node = nodes.get(Randomness.get().nextInt(nodes.size())); + DiscoveryNode remoteNode = nodes.get(Randomness.get().nextInt(nodes.size())); //TODO we just take a random host for now, implement fallback in case of connect failure try { - return connectToRemoteNode(node); + DiscoveryNode discoveryNode = transportService.connectToNodeLightAndHandshake(remoteNode, 10000, false); + transportService.disconnectFromNode(remoteNode); // disconnect the light connection + // now go and do a real connection with the updated version of the node + connectToRemoteNode(discoveryNode); + //TODO at the moment the configured cluster names are really just labels. We should validate that all the nodes + //belong to the same cluster, also validate the cluster name against the configured label and make sure they match + return discoveryNode; } catch(ConnectTransportException e) { - throw new ConnectTransportException(node, "unable to connect to remote cluster [" + clusterName + "]", e); + throw new ConnectTransportException(remoteNode, "unable to connect to remote cluster [" + clusterName + "]", e); } } - DiscoveryNode connectToRemoteNode(DiscoveryNode remoteNode) { - DiscoveryNode discoveryNode = transportService.connectToNodeLightAndHandshake(remoteNode, 10000, false); - transportService.disconnectFromNode(remoteNode); // disconnect the light connection - // now go and do a real connection with the updated version of the node - transportService.connectToNode(discoveryNode); - //TODO at the moment the configured cluster names are really just labels. We should validate that all the nodes - //belong to the same cluster, also validate the cluster name against the configured label and make sure they match - return discoveryNode; + void connectToRemoteNode(DiscoveryNode remoteNode) { + transportService.connectToNode(remoteNode); } void sendSearchShards(SearchRequest searchRequest, Map> remoteIndicesByCluster, @@ -214,6 +214,7 @@ public class SearchTransportService extends AbstractComponent { final AtomicReference transportException = new AtomicReference<>(); for (Map.Entry> entry : remoteIndicesByCluster.entrySet()) { final String clusterName = entry.getKey(); + //TODO we should rather eagerly connect to every configured remote node of all remote clusters final DiscoveryNode node = connectToRemoteCluster(clusterName); final List indices = entry.getValue(); //local true so we don't go to the master for each single remote search