diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-11-14 09:33:00 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-11-14 09:33:00 +0100 |
commit | 4ea03600dd88069460934d36c7843f713acc0965 (patch) | |
tree | c3bd0e42843130361552893377f2428e4558d526 /container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java | |
parent | 03d90c743ae83cfea09be55cb7f1787aa8c8453b (diff) |
Remove leftovers from dispatching through fdispatch
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java')
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java | 47 |
1 files changed, 15 insertions, 32 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java b/container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java index 1f58a2df5c2..ab010001d90 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java @@ -49,7 +49,6 @@ public class Dispatcher extends AbstractComponent { private static final String INTERNAL = "internal"; private static final String PROTOBUF = "protobuf"; - private static final String FDISPATCH_METRIC = "dispatch_fdispatch"; private static final String INTERNAL_METRIC = "dispatch_internal"; private static final int MAX_GROUP_SELECTION_ATTEMPTS = 3; @@ -61,7 +60,6 @@ public class Dispatcher extends AbstractComponent { private final SearchCluster searchCluster; private final LoadBalancer loadBalancer; - private final boolean multilevelDispatch; private final InvokerFactory invokerFactory; @@ -115,11 +113,13 @@ public class Dispatcher extends AbstractComponent { InvokerFactory invokerFactory, PingFactory pingFactory, Metric metric) { + if (dispatchConfig.useMultilevelDispatch()) + throw new IllegalArgumentException(searchCluster + " is configured with multilevel dispatch, but this is not supported"); + this.searchCluster = searchCluster; this.loadBalancer = new LoadBalancer(searchCluster, dispatchConfig.distributionPolicy() == DispatchConfig.DistributionPolicy.ROUNDROBIN); this.invokerFactory = invokerFactory; - this.multilevelDispatch = dispatchConfig.useMultilevelDispatch(); this.metric = metric; this.metricContext = metric.createContext(null); @@ -137,27 +137,18 @@ public class Dispatcher extends AbstractComponent { searchCluster.shutDown(); } - public Optional<FillInvoker> getFillInvoker(Result result, VespaBackEndSearcher searcher) { + public FillInvoker getFillInvoker(Result result, VespaBackEndSearcher searcher) { return invokerFactory.createFillInvoker(searcher, result); } - public Optional<SearchInvoker> getSearchInvoker(Query query, VespaBackEndSearcher searcher) { - if (multilevelDispatch) { - emitDispatchMetric(Optional.empty()); - return Optional.empty(); - } - - Optional<SearchInvoker> invoker = getSearchPathInvoker(query, searcher); + public SearchInvoker getSearchInvoker(Query query, VespaBackEndSearcher searcher) { + SearchInvoker invoker = getSearchPathInvoker(query, searcher).orElseGet(() -> getInternalInvoker(query, searcher)); - if (invoker.isEmpty()) { - invoker = getInternalInvoker(query, searcher); - } - if (invoker.isPresent() && query.properties().getBoolean(com.yahoo.search.query.Model.ESTIMATE)) { + if (query.properties().getBoolean(com.yahoo.search.query.Model.ESTIMATE)) { query.setHits(0); query.setOffset(0); } - emitDispatchMetric(invoker); - + metric.add(INTERNAL_METRIC, 1, metricContext); return invoker; } @@ -177,12 +168,13 @@ public class Dispatcher extends AbstractComponent { } } - private Optional<SearchInvoker> getInternalInvoker(Query query, VespaBackEndSearcher searcher) { + private SearchInvoker getInternalInvoker(Query query, VespaBackEndSearcher searcher) { Optional<Node> directNode = searchCluster.localCorpusDispatchTarget(); if (directNode.isPresent()) { Node node = directNode.get(); - query.trace(false, 2, "Dispatching directly to ", node); - return invokerFactory.createSearchInvoker(searcher, query, OptionalInt.empty(), Arrays.asList(node), true); + query.trace(false, 2, "Dispatching to ", node); + return invokerFactory.createSearchInvoker(searcher, query, OptionalInt.empty(), Arrays.asList(node), true) + .orElseThrow(() -> new IllegalStateException("Could not dispatch directly to " + node)); } int covered = searchCluster.groupsWithSufficientCoverage(); @@ -201,10 +193,10 @@ public class Dispatcher extends AbstractComponent { group.nodes(), acceptIncompleteCoverage); if (invoker.isPresent()) { - query.trace(false, 2, "Dispatching internally to search group ", group.id()); + query.trace(false, 2, "Dispatching to group ", group.id()); query.getModel().setSearchPath("/" + group.id()); invoker.get().teardown((success, time) -> loadBalancer.releaseGroup(group, success, time)); - return invoker; + return invoker.get(); } else { loadBalancer.releaseGroup(group, false, 0); if (rejected == null) { @@ -213,16 +205,7 @@ public class Dispatcher extends AbstractComponent { rejected.add(group.id()); } } - - return Optional.empty(); - } - - private void emitDispatchMetric(Optional<SearchInvoker> invoker) { - if (invoker.isEmpty()) { - metric.add(FDISPATCH_METRIC, 1, metricContext); - } else { - metric.add(INTERNAL_METRIC, 1, metricContext); - } + throw new IllegalStateException("No suitable groups to dispatch query. Rejected: " + rejected); } } |