diff options
author | Harald Musum <musum@verizonmedia.com> | 2019-09-23 16:12:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-23 16:12:12 +0200 |
commit | 5d9cf7eab1eac805b933d07321d95524a8cb2164 (patch) | |
tree | 2980ee536afafa6126e1b783554d4e7f9e0a9cd2 /container-search | |
parent | 8affeae3e0659a7254aea22582919b85a412a8fe (diff) |
Revert "Balder/remove tld from config model rebased"
Diffstat (limited to 'container-search')
-rw-r--r-- | container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java | 35 | ||||
-rw-r--r-- | container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java | 27 |
2 files changed, 54 insertions, 8 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java b/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java index 1f621eb926c..22af77020eb 100644 --- a/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java @@ -23,6 +23,7 @@ import com.yahoo.search.dispatch.Dispatcher; import com.yahoo.search.query.ParameterParser; import com.yahoo.search.result.ErrorMessage; import com.yahoo.search.searchchain.Execution; +import com.yahoo.statistics.Statistics; import com.yahoo.vespa.config.search.DispatchConfig; import com.yahoo.vespa.streamingvisitors.VdsStreamingSearcher; import org.apache.commons.lang.StringUtils; @@ -106,9 +107,17 @@ public class ClusterSearcher extends Searcher { vipStatus.addToRotation(searcher.getName()); } else { Dispatcher dispatcher = Dispatcher.create(id.stringValue(), dispatchConfig, clusterInfoConfig.nodeCount(), vipStatus, metric); - FastSearcher searcher = searchDispatch(searchClusterIndex, fs4ResourcePool.getServerId(), docSumParams, documentDbConfig, dispatcher); - addBackendSearcher(searcher); - + for (int dispatcherIndex = 0; dispatcherIndex < searchClusterConfig.dispatcher().size(); dispatcherIndex++) { + try { + if ( ! isRemote(searchClusterConfig.dispatcher(dispatcherIndex).host())) { + FastSearcher searcher = searchDispatch(searchClusterIndex, fs4ResourcePool.getServerId(), docSumParams, + documentDbConfig, dispatcher, dispatcherIndex); + addBackendSearcher(searcher); + } + } catch (UnknownHostException e) { + throw new RuntimeException(e); + } + } } if ( server == null ) { throw new IllegalStateException("ClusterSearcher should have backend."); @@ -124,16 +133,26 @@ public class ClusterSearcher extends Searcher { return null; } - private static ClusterParams makeClusterParams(int searchclusterIndex) { - return new ClusterParams("sc" + searchclusterIndex + ".num" + 0); + /** + * Returns false if this host is local. + */ + boolean isRemote(String host) throws UnknownHostException { + return (InetAddress.getByName(host).isLoopbackAddress()) + ? false + : !host.equals(HostName.getLocalhost()); + } + + private static ClusterParams makeClusterParams(int searchclusterIndex, int dispatchIndex) { + return new ClusterParams("sc" + searchclusterIndex + ".num" + dispatchIndex); } private static FastSearcher searchDispatch(int searchclusterIndex, String serverId, SummaryParameters docSumParams, DocumentdbInfoConfig documentdbInfoConfig, - Dispatcher dispatcher) { - ClusterParams clusterParams = makeClusterParams(searchclusterIndex); + Dispatcher dispatcher, + int dispatcherIndex) { + ClusterParams clusterParams = makeClusterParams(searchclusterIndex, dispatcherIndex); return new FastSearcher(serverId, dispatcher, docSumParams, clusterParams, documentdbInfoConfig); } @@ -145,7 +164,7 @@ public class ClusterSearcher extends Searcher { if (searchClusterConfig.searchdef().size() != 1) { throw new IllegalArgumentException("Search clusters in streaming search shall only contain a single searchdefinition : " + searchClusterConfig.searchdef()); } - ClusterParams clusterParams = makeClusterParams(searchclusterIndex); + ClusterParams clusterParams = makeClusterParams(searchclusterIndex, 0); VdsStreamingSearcher searcher = new VdsStreamingSearcher(); searcher.setSearchClusterConfigId(searchClusterConfig.rankprofiles().configid()); searcher.setDocumentType(searchClusterConfig.searchdef(0)); diff --git a/container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java index f35d77de01a..c772300876b 100644 --- a/container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/cluster/ClusterSearcherTestCase.java @@ -21,9 +21,12 @@ import com.yahoo.search.Result; import com.yahoo.search.config.ClusterConfig; import com.yahoo.search.result.Hit; import com.yahoo.search.searchchain.Execution; +import com.yahoo.statistics.Statistics; import com.yahoo.vespa.config.search.DispatchConfig; import org.junit.Test; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -417,6 +420,26 @@ public class ClusterSearcherTestCase { } @Test + public void testLocalConnect() throws UnknownHostException { + ClusterSearcher cluster = new ClusterSearcher(new LinkedHashSet<>(Arrays.asList("dummy"))); + boolean canFindYahoo; + final String yahoo = "www.yahoo.com"; + + try { + canFindYahoo = (null != InetAddress.getByName(yahoo)); + } catch (Exception e) { + canFindYahoo = false; + } + + assertFalse(cluster.isRemote("127.0.0.1")); + assertFalse(cluster.isRemote("localhost")); + + if (canFindYahoo) { + assertTrue(cluster.isRemote(yahoo)); + } + } + + @Test public void testRequireThatSearchFailsForUndefinedRankProfileWithOneDocType() { Execution execution = createExecution(Arrays.asList("type1"), false); @@ -502,6 +525,10 @@ public class ClusterSearcherTestCase { searchClusterConfig.searchdef("streaming_sd"); } qrSearchersConfig.searchcluster(searchClusterConfig); + QrSearchersConfig.Searchcluster.Dispatcher.Builder dispatcherConfig = new QrSearchersConfig.Searchcluster.Dispatcher.Builder(); + dispatcherConfig.host("localhost"); + dispatcherConfig.port(0); + searchClusterConfig.dispatcher(dispatcherConfig); ClusterConfig.Builder clusterConfig = new ClusterConfig.Builder().clusterName(clusterName); if (maxQueryTimeout != null) |