aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/fastsearch
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude/fastsearch')
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4InvokerFactory.java46
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4SearchInvoker.java36
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/fastsearch/FastSearcher.java11
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java2
4 files changed, 28 insertions, 67 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4InvokerFactory.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4InvokerFactory.java
index 5700e316493..66088faed79 100644
--- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4InvokerFactory.java
+++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4InvokerFactory.java
@@ -8,12 +8,10 @@ import com.yahoo.search.Result;
import com.yahoo.search.dispatch.FillInvoker;
import com.yahoo.search.dispatch.InterleavedFillInvoker;
import com.yahoo.search.dispatch.InterleavedSearchInvoker;
-import com.yahoo.search.dispatch.SearchErrorInvoker;
+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 com.yahoo.search.result.Coverage;
-import com.yahoo.search.result.ErrorMessage;
import com.yahoo.search.result.Hit;
import java.util.ArrayList;
@@ -33,15 +31,13 @@ import java.util.Set;
*
* @author ollivir
*/
-public class FS4InvokerFactory {
+public class FS4InvokerFactory extends InvokerFactory {
private final FS4ResourcePool fs4ResourcePool;
- private final VespaBackEndSearcher searcher;
private final SearchCluster searchCluster;
private final ImmutableMap<Integer, Node> nodesByKey;
- public FS4InvokerFactory(FS4ResourcePool fs4ResourcePool, SearchCluster searchCluster, VespaBackEndSearcher searcher) {
+ public FS4InvokerFactory(FS4ResourcePool fs4ResourcePool, SearchCluster searchCluster) {
this.fs4ResourcePool = fs4ResourcePool;
- this.searcher = searcher;
this.searchCluster = searchCluster;
ImmutableMap.Builder<Integer, Node> builder = ImmutableMap.builder();
@@ -49,7 +45,7 @@ public class FS4InvokerFactory {
this.nodesByKey = builder.build();
}
- public SearchInvoker getSearchInvoker(Query query, Node node) {
+ public SearchInvoker createSearchInvoker(VespaBackEndSearcher searcher, Query query, Node node) {
Backend backend = fs4ResourcePool.getBackend(node.hostname(), node.fs4port());
return new FS4SearchInvoker(searcher, query, backend.openChannel(), Optional.of(node));
}
@@ -57,6 +53,8 @@ public class FS4InvokerFactory {
/**
* Create a {@link SearchInvoker} for a list of content nodes.
*
+ * @param searcher
+ * the searcher processing the query
* @param query
* the search query being processed
* @param groupId
@@ -70,7 +68,9 @@ public class FS4InvokerFactory {
* @return Optional containing the SearchInvoker or <i>empty</i> if some node in the
* list is invalid and the remaining coverage is not sufficient
*/
- public Optional<SearchInvoker> getSearchInvoker(Query query, OptionalInt groupId, List<Node> nodes, boolean acceptIncompleteCoverage) {
+ @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) {
@@ -114,44 +114,27 @@ public class FS4InvokerFactory {
}
}
- private SearchInvoker createCoverageErrorInvoker(List<Node> nodes, Set<Integer> failed) {
- StringBuilder down = new StringBuilder("Connection failure on nodes with distribution-keys: ");
- int count = 0;
- for (Node node : nodes) {
- if (failed.contains(node.key())) {
- if (count > 0) {
- down.append(", ");
- }
- count++;
- down.append(node.key());
- }
- }
- Coverage coverage = new Coverage(0, 0, 0);
- coverage.setNodesTried(count);
- return new SearchErrorInvoker(ErrorMessage.createBackendCommunicationError(down.toString()), coverage);
- }
-
- public FillInvoker getFillInvoker(Query query, Node node) {
- return new FS4FillInvoker(searcher, query, fs4ResourcePool, node.hostname(), node.fs4port());
+ public FillInvoker createFillInvoker(VespaBackEndSearcher searcher, Result result, Node node) {
+ return new FS4FillInvoker(searcher, result.getQuery(), fs4ResourcePool, node.hostname(), node.fs4port());
}
/**
* Create a {@link FillInvoker} for a the hits in a {@link Result}.
*
+ * @param searcher the searcher processing the query
* @param result the Result containing hits that need to be filled
* @return Optional containing the FillInvoker or <i>empty</i> if some hit is from an unknown content node
*/
- public Optional<FillInvoker> getFillInvoker(Result result) {
+ public Optional<FillInvoker> createFillInvoker(VespaBackEndSearcher searcher, Result result) {
Collection<Integer> requiredNodes = requiredFillNodes(result);
- Query query = result.getQuery();
Map<Integer, FillInvoker> invokers = new HashMap<>();
for (Integer distKey : requiredNodes) {
Node node = nodesByKey.get(distKey);
if (node == null) {
return Optional.empty();
}
- invokers.put(distKey, getFillInvoker(query, node));
+ invokers.put(distKey, createFillInvoker(searcher, result, node));
}
if (invokers.size() == 1) {
@@ -172,4 +155,5 @@ public class FS4InvokerFactory {
}
return requiredNodes;
}
+
}
diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4SearchInvoker.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4SearchInvoker.java
index d2910ba3fbc..24653db5671 100644
--- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4SearchInvoker.java
+++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4SearchInvoker.java
@@ -12,13 +12,11 @@ import com.yahoo.search.Result;
import com.yahoo.search.dispatch.ResponseMonitor;
import com.yahoo.search.dispatch.SearchInvoker;
import com.yahoo.search.dispatch.searchcluster.Node;
-import com.yahoo.search.result.Coverage;
import com.yahoo.search.result.ErrorMessage;
import com.yahoo.search.searchchain.Execution;
import java.io.IOException;
import java.util.Optional;
-import java.util.logging.Level;
import java.util.logging.Logger;
/**
@@ -27,6 +25,7 @@ import java.util.logging.Logger;
* @author ollivir
*/
public class FS4SearchInvoker extends SearchInvoker implements ResponseMonitor<FS4Channel> {
+ private static final Logger log = Logger.getLogger(FS4SearchInvoker.class.getName());
private final VespaBackEndSearcher searcher;
private FS4Channel channel;
@@ -46,8 +45,7 @@ public class FS4SearchInvoker extends SearchInvoker implements ResponseMonitor<F
@Override
protected void sendSearchRequest(Query query, QueryPacket queryPacket) throws IOException {
- if (isLoggingFine())
- getLogger().finest("sending query packet");
+ log.finest("sending query packet");
if (queryPacket == null) {
// query changed for subchannel
@@ -77,30 +75,28 @@ public class FS4SearchInvoker extends SearchInvoker implements ResponseMonitor<F
@Override
protected Result getSearchResult(Execution execution) throws IOException {
if (pendingSearchError != null) {
- return errorResult(pendingSearchError);
+ return errorResult(query, pendingSearchError);
}
BasicPacket[] basicPackets;
try {
basicPackets = channel.receivePackets(query.getTimeLeft(), 1);
} catch (ChannelTimeoutException e) {
- return errorResult(ErrorMessage.createTimeout("Timeout while waiting for " + getName()));
+ return errorResult(query, ErrorMessage.createTimeout("Timeout while waiting for " + getName()));
} catch (InvalidChannelException e) {
- return errorResult(ErrorMessage.createBackendCommunicationError("Invalid channel for " + getName()));
+ return errorResult(query, ErrorMessage.createBackendCommunicationError("Invalid channel for " + getName()));
}
if (basicPackets.length == 0) {
- return errorResult(ErrorMessage.createBackendCommunicationError(getName() + " got no packets back"));
+ return errorResult(query, ErrorMessage.createBackendCommunicationError(getName() + " got no packets back"));
}
- if (isLoggingFine())
- getLogger().finest("got packets " + basicPackets.length + " packets");
+ log.finest(() -> "got packets " + basicPackets.length + " packets");
basicPackets[0].ensureInstanceOf(QueryResultPacket.class, getName());
QueryResultPacket resultPacket = (QueryResultPacket) basicPackets[0];
- if (isLoggingFine())
- getLogger().finest("got query packet. " + "docsumClass=" + query.getPresentation().getSummary());
+ log.finest(() -> "got query packet. " + "docsumClass=" + query.getPresentation().getSummary());
if (query.getPresentation().getSummary() == null)
query.getPresentation().setSummary(searcher.getDefaultDocsumClass());
@@ -114,14 +110,6 @@ public class FS4SearchInvoker extends SearchInvoker implements ResponseMonitor<F
return result;
}
- private Result errorResult(ErrorMessage errorMessage) {
- Result error = new Result(query, errorMessage);
- Coverage errorCoverage = new Coverage(0, 0, 0);
- errorCoverage.setNodesTried(1);
- error.setCoverage(errorCoverage);
- return error;
- }
-
@Override
public void release() {
if (channel != null) {
@@ -134,14 +122,6 @@ public class FS4SearchInvoker extends SearchInvoker implements ResponseMonitor<F
return searcher.getName();
}
- private Logger getLogger() {
- return searcher.getLogger();
- }
-
- private boolean isLoggingFine() {
- return getLogger().isLoggable(Level.FINE);
- }
-
@Override
public void responseAvailable(FS4Channel from) {
responseAvailable();
diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastSearcher.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastSearcher.java
index ac02b5f8e5e..68f8bd9d9ea 100644
--- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastSearcher.java
+++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastSearcher.java
@@ -54,8 +54,6 @@ public class FastSearcher extends VespaBackEndSearcher {
private final Backend dispatchBackend;
- private final FS4InvokerFactory fs4InvokerFactory;
-
/**
* Creates a Fastsearcher.
*
@@ -77,7 +75,6 @@ public class FastSearcher extends VespaBackEndSearcher {
init(fs4ResourcePool.getServerId(), docSumParams, clusterParams, documentdbInfoConfig);
this.dispatchBackend = dispatchBackend;
this.dispatcher = dispatcher;
- this.fs4InvokerFactory = new FS4InvokerFactory(fs4ResourcePool, dispatcher.searchCluster(), this);
}
/**
@@ -209,14 +206,14 @@ public class FastSearcher extends VespaBackEndSearcher {
* on the same host.
*/
private SearchInvoker getSearchInvoker(Query query) {
- Optional<SearchInvoker> invoker = dispatcher.getSearchInvoker(query, fs4InvokerFactory);
+ Optional<SearchInvoker> invoker = dispatcher.getSearchInvoker(query, this);
if (invoker.isPresent()) {
return invoker.get();
}
Optional<Node> direct = getDirectNode(query);
if(direct.isPresent()) {
- return fs4InvokerFactory.getSearchInvoker(query, direct.get());
+ return dispatcher.getFS4InvokerFactory().createSearchInvoker(this, query, direct.get());
}
return new FS4SearchInvoker(this, query, dispatchBackend.openChannel(), Optional.empty());
}
@@ -228,14 +225,14 @@ public class FastSearcher extends VespaBackEndSearcher {
*/
private FillInvoker getFillInvoker(Result result) {
Query query = result.getQuery();
- Optional<FillInvoker> invoker = dispatcher.getFillInvoker(result, this, getDocumentDatabase(query), fs4InvokerFactory);
+ Optional<FillInvoker> invoker = dispatcher.getFillInvoker(result, this);
if (invoker.isPresent()) {
return invoker.get();
}
Optional<Node> direct = getDirectNode(query);
if (direct.isPresent()) {
- return fs4InvokerFactory.getFillInvoker(query, direct.get());
+ return dispatcher.getFS4InvokerFactory().createFillInvoker(this, result, direct.get());
}
return new FS4FillInvoker(this, query, dispatchBackend);
}
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 bee1fab5686..dccda0bf733 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
@@ -122,7 +122,7 @@ public abstract class VespaBackEndSearcher extends PingableSearcher {
public String getServerId() { return serverId; }
- protected DocumentDatabase getDocumentDatabase(Query query) {
+ public DocumentDatabase getDocumentDatabase(Query query) {
if (query.getModel().getRestrict().size() == 1) {
String docTypeName = (String)query.getModel().getRestrict().toArray()[0];
DocumentDatabase db = documentDbs.get(docTypeName);