summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcInvokerFactory.java
diff options
context:
space:
mode:
authorOlli Virtanen <olli.virtanen@oath.com>2019-03-12 15:44:04 +0100
committerOlli Virtanen <olli.virtanen@oath.com>2019-03-12 15:44:04 +0100
commit66ec8a5349ac6e81148ba7556ce4d056e55b7bd6 (patch)
tree9aafa6b50a54850f4b6a696b2df12a2679388faa /container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcInvokerFactory.java
parent91dd5bc9eb95701aeb3110fd402257084634aa73 (diff)
Protobuf object coversion moved to separate class. RPC classes moved to subpackage
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcInvokerFactory.java')
-rw-r--r--container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcInvokerFactory.java98
1 files changed, 98 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcInvokerFactory.java b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcInvokerFactory.java
new file mode 100644
index 00000000000..c8019278710
--- /dev/null
+++ b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcInvokerFactory.java
@@ -0,0 +1,98 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.search.dispatch.rpc;
+
+import com.yahoo.prelude.fastsearch.DocumentDatabase;
+import com.yahoo.prelude.fastsearch.VespaBackEndSearcher;
+import com.yahoo.processing.request.CompoundName;
+import com.yahoo.search.Query;
+import com.yahoo.search.Result;
+import com.yahoo.search.dispatch.FillInvoker;
+import com.yahoo.search.dispatch.InterleavedSearchInvoker;
+import com.yahoo.search.dispatch.InvokerFactory;
+import com.yahoo.search.dispatch.SearchInvoker;
+import com.yahoo.search.dispatch.searchcluster.Node;
+import com.yahoo.search.dispatch.searchcluster.SearchCluster;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.OptionalInt;
+import java.util.Set;
+
+/**
+ * @author ollivir
+ */
+public class RpcInvokerFactory extends InvokerFactory {
+ /** Unless turned off this will fill summaries by dispatching directly to search nodes over RPC when possible */
+ private final static CompoundName dispatchSummaries = new CompoundName("dispatch.summaries");
+
+ private final RpcResourcePool rpcResourcePool;
+ private final SearchCluster searchCluster;
+
+ public RpcInvokerFactory(RpcResourcePool rpcResourcePool, SearchCluster searchCluster) {
+ this.rpcResourcePool = rpcResourcePool;
+ this.searchCluster = searchCluster;
+ }
+
+ @Override
+ public Optional<SearchInvoker> createSearchInvoker(VespaBackEndSearcher searcher, Query query, OptionalInt groupId, List<Node> nodes,
+ boolean acceptIncompleteCoverage) {
+ List<SearchInvoker> invokers = new ArrayList<>(nodes.size());
+ Set<Integer> failed = null;
+ for (Node node : nodes) {
+ if (node.isWorking()) {
+ invokers.add(new RpcSearchInvoker(searcher, node, rpcResourcePool));
+ } else {
+ if (failed == null) {
+ failed = new HashSet<>();
+ }
+ failed.add(node.key());
+ }
+ }
+
+ if (failed != null) {
+ List<Node> success = new ArrayList<>(nodes.size() - failed.size());
+ for (Node node : nodes) {
+ if (!failed.contains(node.key())) {
+ success.add(node);
+ }
+ }
+ if (!searchCluster.isPartialGroupCoverageSufficient(groupId, success)) {
+ if (acceptIncompleteCoverage) {
+ invokers.add(createCoverageErrorInvoker(nodes, failed));
+ } else {
+ return Optional.empty();
+ }
+ }
+ }
+
+ if (invokers.size() == 1) {
+ return Optional.of(invokers.get(0));
+ } else {
+ return Optional.of(new InterleavedSearchInvoker(invokers, searcher, searchCluster));
+ }
+ }
+
+ @Override
+ public Optional<FillInvoker> createFillInvoker(VespaBackEndSearcher searcher, Result result) {
+ Query query = result.getQuery();
+ if (query.properties().getBoolean(dispatchSummaries, true)
+ && ! searcher.summaryNeedsQuery(query)
+ && query.getRanking().getLocation() == null)
+ {
+ return Optional.of(new RpcFillInvoker(rpcResourcePool, searcher.getDocumentDatabase(query)));
+ } else {
+ return Optional.empty();
+ }
+ }
+
+ // for testing
+ public FillInvoker createFillInvoker(DocumentDatabase documentDb) {
+ return new RpcFillInvoker(rpcResourcePool, documentDb);
+ }
+
+ public void release() {
+ rpcResourcePool.release();
+ }
+}