use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class FillSearcher method fill.
// TODO: Remove this method as it does nothing new
@Override
public void fill(Result result, String summaryClass, Execution execution) {
if (next == null) {
execution.fill(result, summaryClass);
} else {
Execution e = new Execution(next, execution.context());
e.fill(result, summaryClass);
}
}
use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class FederationSearcher method search.
private Optional<Result> search(Query query, Execution execution, Target target) {
long timeout = target.federationOptions().getSearchChainExecutionTimeoutInMilliseconds(query.getTimeLeft());
if (timeout <= 0) {
return Optional.empty();
}
Execution newExecution = new Execution(target.getChain(), execution.context());
if (strictSearchchain) {
query.resetTimeout();
return Optional.of(newExecution.search(createFederationQuery(query, query, Window.from(query), timeout, target)));
} else {
return Optional.of(newExecution.search(cloneFederationQuery(query, Window.from(query), timeout, target)));
}
}
use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class FederationSearcher method fill.
@Override
public void fill(Result result, String summaryClass, Execution execution) {
UniqueExecutionsToResults uniqueExecutionsToResults = new UniqueExecutionsToResults();
addResultsToFill(result.hits(), result, summaryClass, uniqueExecutionsToResults);
Set<Entry<Chain<Searcher>, Map<Query, Result>>> resultsForAllChains = uniqueExecutionsToResults.resultsToFill.entrySet();
int numberOfCallsToFillNeeded = 0;
for (Entry<Chain<Searcher>, Map<Query, Result>> resultsToFillForAChain : resultsForAllChains) {
numberOfCallsToFillNeeded += resultsToFillForAChain.getValue().size();
}
List<Pair<Result, FutureResult>> futureFilledResults = new ArrayList<>();
for (Entry<Chain<Searcher>, Map<Query, Result>> resultsToFillForAChain : resultsForAllChains) {
Chain<Searcher> chain = resultsToFillForAChain.getKey();
Execution chainExecution = (chain == null) ? execution : new Execution(chain, execution.context());
for (Entry<Query, Result> resultsToFillForAChainAndQuery : resultsToFillForAChain.getValue().entrySet()) {
Result resultToFill = resultsToFillForAChainAndQuery.getValue();
if (numberOfCallsToFillNeeded == 1) {
chainExecution.fill(resultToFill, summaryClass);
propagateErrors(resultToFill, result);
} else {
AsyncExecution asyncFill = new AsyncExecution(chainExecution);
futureFilledResults.add(new Pair<>(resultToFill, asyncFill.fill(resultToFill, summaryClass)));
}
}
}
for (Pair<Result, FutureResult> futureFilledResult : futureFilledResults) {
// futureFilledResult is a pair of a result to be filled and the future in which that same result is filled
Optional<Result> filledResult = futureFilledResult.getSecond().getIfAvailable(result.getQuery().getTimeLeft(), TimeUnit.MILLISECONDS);
if (filledResult.isPresent()) {
// fill completed
propagateErrors(filledResult.get(), result);
} else {
// fill timed out: Remove these hits as they are incomplete and may cause a race when accessed later
result.hits().addError(futureFilledResult.getSecond().createTimeoutError());
for (Iterator<Hit> i = futureFilledResult.getFirst().hits().unorderedDeepIterator(); i.hasNext(); ) {
// Note that some of these hits may be filled, but as the fill thread may still be working on them
// and we do not synchronize with it we need to discard all
Hit removed = result.hits().remove(i.next().getId());
}
}
}
}
use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class FastSearcherTestCase method testPing.
@Test
public void testPing() throws IOException, InterruptedException {
Logger.getLogger(FastSearcher.class.getName()).setLevel(Level.ALL);
BackendTestCase.MockServer server = new BackendTestCase.MockServer();
FS4ResourcePool listeners = new FS4ResourcePool(new Fs4Config(new Fs4Config.Builder()));
Backend backend = listeners.getBackend(server.host.getHostString(), server.host.getPort());
FastSearcher fastSearcher = new FastSearcher(backend, new FS4ResourcePool(1), new MockDispatcher(Collections.emptyList()), new SummaryParameters(null), new ClusterParams("testhittype"), new CacheParams(0, 0.0d), documentdbInfoConfig);
server.dispatch.packetData = BackendTestCase.PONG;
server.dispatch.setNoChannel();
Chain<Searcher> chain = new Chain<>(fastSearcher);
Execution e = new Execution(chain, Execution.Context.createContextStub());
Pong pong = e.ping(new Ping());
assertTrue(pong.getPongPacket().isPresent());
assertEquals(127, pong.getPongPacket().get().getDocstamp());
backend.shutdown();
server.dispatch.socket.close();
server.dispatch.connection.close();
server.worker.join();
pong.setPingInfo("blbl");
assertEquals("Result of pinging using blbl", pong.toString());
}
use of com.yahoo.search.searchchain.Execution in project vespa by vespa-engine.
the class FastSearcherTestCase method testSearch.
@Test
public void testSearch() {
FastSearcher fastSearcher = createFastSearcher();
// Default cache =100MB
assertEquals(100, fastSearcher.getCacheControl().capacity());
Result result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 10);
Execution execution = new Execution(chainedAsSearchChain(fastSearcher), Execution.Context.createContextStub());
assertEquals(2, result.getHitCount());
execution.fill(result);
assertCorrectHit1((FastHit) result.hits().get(0));
assertCorrectTypes1((FastHit) result.hits().get(0));
for (int idx = 0; idx < result.getHitCount(); idx++) {
assertTrue(!result.hits().get(idx).isCached());
}
// Repeat the request a couple of times, to verify whether the packet cache works
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 10);
assertEquals(2, result.getHitCount());
execution.fill(result);
assertCorrectHit1((FastHit) result.hits().get(0));
for (int i = 0; i < result.getHitCount(); i++) {
assertTrue(result.hits().get(i) + " should be cached", result.hits().get(i).isCached());
}
// outside-range cache hit
result = doSearch(fastSearcher, new Query("?query=ignored"), 6, 3);
// fill should still work (nop)
execution.fill(result);
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 10);
assertEquals(2, result.getHitCount());
assertCorrectHit1((FastHit) result.hits().get(0));
assertTrue("All hits are cached and the result knows it", result.isCached());
for (int i = 0; i < result.getHitCount(); i++) {
assertTrue(result.hits().get(i) + " should be cached", result.hits().get(i).isCached());
}
clearCache(fastSearcher);
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 10);
assertEquals(2, result.getHitCount());
execution.fill(result);
assertCorrectHit1((FastHit) result.hits().get(0));
assertTrue("All hits are not cached", !result.isCached());
for (int i = 0; i < result.getHitCount(); i++) {
assertTrue(!result.hits().get(i).isCached());
}
// Test that partial result sets can be retrieved from the cache
clearCache(fastSearcher);
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 1);
assertEquals(1, result.getConcreteHitCount());
execution.fill(result);
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 2);
assertEquals(2, result.getConcreteHitCount());
execution.fill(result);
// First hit should be cached but not second hit
assertTrue(result.hits().get(0).isCached());
assertFalse(result.hits().get(1).isCached());
// Check that the entire result set is returned from cache now
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 2);
assertEquals(2, result.getConcreteHitCount());
execution.fill(result);
// both first and second should now be cached
assertTrue(result.hits().get(0).isCached());
assertTrue(result.hits().get(1).isCached());
// Tests that the cache _hit_ is not returned if _another_
// hit is requested
clearCache(fastSearcher);
result = doSearch(fastSearcher, new Query("?query=ignored"), 0, 1);
assertEquals(1, result.getConcreteHitCount());
result = doSearch(fastSearcher, new Query("?query=ignored"), 1, 1);
assertEquals(1, result.getConcreteHitCount());
for (int i = 0; i < result.getHitCount(); i++) {
assertFalse("Hit " + i + " should not be cached.", result.hits().get(i).isCached());
}
}
Aggregations