diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2018-04-05 22:13:42 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2018-04-05 22:47:24 +0200 |
commit | fcbe9060eb975ac488c665f097d516dec4226811 (patch) | |
tree | 0c9391cb45656baf5875b5a0bea028641e71c6c3 /container-search/src/main | |
parent | 9d8d6613058bf05bee2e7bcbbe9d3fd6a163bcde (diff) |
Remove support for multiple TLD's
Diffstat (limited to 'container-search/src/main')
3 files changed, 31 insertions, 208 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 a2e806dde93..968504ec018 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 @@ -66,8 +66,6 @@ public class ClusterSearcher extends Searcher { private final ClusterMonitor monitor; - private final Hasher hasher; - private final Value cacheHitRatio; private final String clusterModelName; @@ -90,6 +88,9 @@ public class ClusterSearcher extends Searcher { private final long maxQueryCacheTimeout; // in milliseconds private final static long DEFAULT_MAX_QUERY_CACHE_TIMEOUT = 10000L; + private VespaBackEndSearcher server = null; + + /** * Creates a new ClusterSearcher. */ @@ -105,15 +106,13 @@ public class ClusterSearcher extends Searcher { FS4ResourcePool fs4ResourcePool, VipStatus vipStatus) { super(id); - this.hasher = new Hasher(); this.fs4ResourcePool = fs4ResourcePool; Dispatcher dispatcher = new Dispatcher(dispatchConfig, fs4ResourcePool, clusterInfoConfig.nodeCount(), vipStatus); - if (dispatcher.searchCluster().directDispatchTarget().isPresent()) // dispatcher should decide vip status instead - monitor = new ClusterMonitor(this, monitorConfig, Optional.empty()); - else - monitor = new ClusterMonitor(this, monitorConfig, Optional.of(vipStatus)); + monitor = (dispatcher.searchCluster().directDispatchTarget().isPresent()) // dispatcher should decide vip status instead + ? new ClusterMonitor(this, monitorConfig, Optional.empty()) + : new ClusterMonitor(this, monitorConfig, Optional.of(vipStatus)); int searchClusterIndex = clusterConfig.clusterId(); clusterModelName = clusterConfig.clusterName(); @@ -143,13 +142,11 @@ public class ClusterSearcher extends Searcher { } } - boolean gotExpectedBackend = false; if (searchClusterConfig.indexingmode() == STREAMING) { VdsStreamingSearcher searcher = vdsCluster(searchClusterIndex, searchClusterConfig, cacheParams, emulationConfig, docSumParams, documentDbConfig); addBackendSearcher(searcher); - gotExpectedBackend = true; } else { for (int dispatcherIndex = 0; dispatcherIndex < searchClusterConfig.dispatcher().size(); dispatcherIndex++) { try { @@ -158,22 +155,19 @@ public class ClusterSearcher extends Searcher { FastSearcher searcher = searchDispatch(searchClusterIndex, fs4ResourcePool, searchClusterConfig, cacheParams, emulationConfig, docSumParams, documentDbConfig, b, dispatcher, dispatcherIndex); - searcher.setLocalDispatching(true); backends.add(b); addBackendSearcher(searcher); - gotExpectedBackend |= searcher.isLocalDispatching(); } } catch (UnknownHostException e) { throw new RuntimeException(e); } } } - if ( ! gotExpectedBackend) { + if ( backends.size() != 1 ) { log.log(Level.SEVERE, "ClusterSearcher should have a local top level dispatch." + " The possibility to configure dispatchers explicitly will be removed" + " in a future release."); } - hasher.running = true; monitor.freeze(); monitor.startPingThread(); } @@ -244,7 +238,6 @@ public class ClusterSearcher extends Searcher { /** Do not use, for internal testing purposes only. **/ ClusterSearcher(Set<String> documentTypes) { - this.hasher = new Hasher(); this.failoverToRemote = false; this.documentTypes = documentTypes; monitor = new ClusterMonitor(this, new QrMonitorConfig(new QrMonitorConfig.Builder()), Optional.of(new VipStatus())); @@ -286,7 +279,7 @@ public class ClusterSearcher extends Searcher { void addBackendSearcher(VespaBackEndSearcher searcher) { monitor.add(searcher); - hasher.add(searcher); + server = searcher; } void addValidRankProfile(String profileName, String docTypeName) { @@ -355,29 +348,21 @@ public class ClusterSearcher extends Searcher { @Override public void fill(com.yahoo.search.Result result, String summaryClass, Execution execution) { Query query = result.getQuery(); - int tries = 0; - - do { - // The loop is in case there are other searchers available - // able to produce results - VespaBackEndSearcher searcher = hasher.select(tries++); - if (searcher != null) { - if (query.getTimeLeft() > 0) { - doFill(searcher, result, summaryClass, execution); - } else { - if (result.hits().getErrorHit() == null) { - result.hits().addError(ErrorMessage.createTimeout("No time left to get summaries")); - } - } + + VespaBackEndSearcher searcher = server; + if (searcher != null) { + if (query.getTimeLeft() > 0) { + doFill(searcher, result, summaryClass, execution); } else { if (result.hits().getErrorHit() == null) { - result.hits().addError(ErrorMessage.createNoBackendsInService("Could not fill result")); + result.hits().addError(ErrorMessage.createTimeout("No time left to get summaries")); } } - // no error: good result, let's return - if (result.hits().getError() == null) return; - - } while (tries < hasher.getNodeCount() && failoverToRemote); + } else { + if (result.hits().getErrorHit() == null) { + result.hits().addError(ErrorMessage.createNoBackendsInService("Could not fill result")); + } + } } public void doFill(Searcher searcher, Result result, String summaryClass, Execution execution) { @@ -399,37 +384,17 @@ public class ClusterSearcher extends Searcher { @Override public Result search(Query query, Execution execution) { - Result result; - int tries = 0; - - do { - // The loop is in case there are other searchers available able to produce results - validateQueryTimeout(query); - validateQueryCache(query); - VespaBackEndSearcher searcher = hasher.select(tries++); - if (searcher == null) { - return new Result(query, ErrorMessage.createNoBackendsInService("Could not search")); - } - if (query.getTimeLeft() <= 0) { - return new Result(query, ErrorMessage.createTimeout("No time left for searching")); - } - - result = doSearch(searcher, query, execution); - - // no error: good result, let's return - if (result.hits().getError() == null) { - return result; - } - if (result.hits().getError().getCode() == Error.TIMEOUT.code) { - return result; // Retry is unlikely to help - } - if (result.hits().getError().getCode() == Error.INVALID_QUERY_PARAMETER.code) { - return result; // Retry is unlikely to help here as well - } - } while (tries < hasher.getNodeCount()); + validateQueryTimeout(query); + validateQueryCache(query); + VespaBackEndSearcher searcher = server; + if (searcher == null) { + return new Result(query, ErrorMessage.createNoBackendsInService("Could not search")); + } + if (query.getTimeLeft() <= 0) { + return new Result(query, ErrorMessage.createTimeout("No time left for searching")); + } - // only error-result gets returned here. - return result; + return doSearch(searcher, query, execution); } private void validateQueryTimeout(Query query) { @@ -554,12 +519,12 @@ public class ClusterSearcher extends Searcher { /** NodeManager method, called from ClusterMonitor. */ void working(VespaBackEndSearcher node) { - hasher.add(node); + server = node; } /** Called from ClusterMonitor. */ void failed(VespaBackEndSearcher node) { - hasher.remove(node); + server = null; } /** diff --git a/container-search/src/main/java/com/yahoo/prelude/cluster/Hasher.java b/container-search/src/main/java/com/yahoo/prelude/cluster/Hasher.java deleted file mode 100644 index c82aeae3bc8..00000000000 --- a/container-search/src/main/java/com/yahoo/prelude/cluster/Hasher.java +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.prelude.cluster; - -import java.util.Random; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Logger; - -import com.yahoo.container.handler.VipStatus; -import com.yahoo.log.LogLevel; -import com.yahoo.prelude.fastsearch.VespaBackEndSearcher; - -/** - * Failover between multiple Vespa backends. - * - * @author bratseth - * @author Prashanth B. Bhat - * @author Steinar Knutsen - */ -public class Hasher { - - boolean running = false; - - private static final Logger log = Logger.getLogger(Hasher.class.getName()); - private static final Random tldSeeder = new Random(); - - private volatile VespaBackEndSearcher[] allNodes = new VespaBackEndSearcher[0]; - private volatile VespaBackEndSearcher[] localNodes = new VespaBackEndSearcher[0]; - - private AtomicInteger avoidAllQrsHitSameTld = new AtomicInteger(tldSeed()); - - /** - * Creates a hasher independent of the {@linkplain VipStatus programmatic VIP API}. - */ - public Hasher() { - } - - private static synchronized int tldSeed() { - return tldSeeder.nextInt(); - } - - static private VespaBackEndSearcher[] addNode(VespaBackEndSearcher node, VespaBackEndSearcher[] oldNodes) { - for (VespaBackEndSearcher n : oldNodes) { - if (n == node) return oldNodes; // already present - } - VespaBackEndSearcher[] newNodes = new VespaBackEndSearcher[oldNodes.length + 1]; - System.arraycopy(oldNodes, 0, newNodes, 0, oldNodes.length); - newNodes[oldNodes.length] = node; - return newNodes; - } - - /** - * Make a node available for search. - * @param node the backend searcher (must never be null) - */ - public void add(VespaBackEndSearcher node) { - allNodes = addNode(node, allNodes); - - if (node.isLocalDispatching()) { - localNodes = addNode(node, localNodes); - } - } - - private VespaBackEndSearcher[] removeNode(VespaBackEndSearcher node, VespaBackEndSearcher[] oldNodes) { - int newLen = oldNodes.length; - for (VespaBackEndSearcher n : oldNodes) { - if (n == node) { - --newLen; - } - } - if (newLen == oldNodes.length) { - return oldNodes; - } - VespaBackEndSearcher[] newNodes = new VespaBackEndSearcher[newLen]; - int idx = 0; - for (VespaBackEndSearcher n : oldNodes) { - if (n != node) { - newNodes[idx++] = n; - } - } - assert idx == newLen; - return newNodes; - } - - /** Removes a node */ - public void remove(VespaBackEndSearcher node) { - if (allNodes.length == 0) return; - - VespaBackEndSearcher[] newNodes = removeNode(node, allNodes); - if (newNodes != allNodes) { - if (running && newNodes.length == 0) { - log.log(LogLevel.WARNING, "No longer any nodes for this cluster when" - + " removing malfunctioning " + node.toString() + "."); - } - allNodes = newNodes; - } - - newNodes = removeNode(node, localNodes); - if (newNodes != localNodes) { - if (running && localNodes.length == 0) { - log.log(LogLevel.WARNING, "Removing malfunctioning " + node.toString() - + " from traffic leaves no local dispatchers, performance" - + " degradation is to expected."); - } - localNodes = newNodes; - } - } - - public int getNodeCount() { - return allNodes.length; - } - - /** - * Return a node, prefer local nodes, try to skip already hit nodes. - * - * @param trynum hint for skipping (ignored in current implementation) - * @return the selected node, or null if this hasher has no nodes - */ - public VespaBackEndSearcher select(int trynum) { - VespaBackEndSearcher[] nodes = allNodes; - - if (localNodes.length > 0) { - nodes = localNodes; - } - if (nodes.length == 0) { - return null; - } - int idx = 0; - if (nodes.length > 1) { - idx = Math.abs(avoidAllQrsHitSameTld.incrementAndGet() % nodes.length); - } - return nodes[idx]; - } - -} diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java index 6945877883d..eac1579a821 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java @@ -74,8 +74,6 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { return result.hits().unorderedDeepIterator(); } - private boolean localDispatching = true; - /** The name of this source */ private String name; @@ -709,10 +707,4 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { return getLogger().isLoggable(Level.FINE); } - public boolean isLocalDispatching() { return localDispatching; } - - public void setLocalDispatching(boolean localDispatching) { - this.localDispatching = localDispatching; - } - } |