Search in sources :

Example 1 with Execution

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);
    }
}
Also used : Execution(com.yahoo.search.searchchain.Execution)

Example 2 with Execution

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)));
    }
}
Also used : Execution(com.yahoo.search.searchchain.Execution) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution)

Example 3 with Execution

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());
            }
        }
    }
}
Also used : Chain(com.yahoo.component.chain.Chain) Query(com.yahoo.search.Query) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) Searcher(com.yahoo.search.Searcher) ForkingSearcher(com.yahoo.search.searchchain.ForkingSearcher) ArrayList(java.util.ArrayList) Result(com.yahoo.search.Result) FutureResult(com.yahoo.search.searchchain.FutureResult) Entry(java.util.Map.Entry) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) AsyncExecution(com.yahoo.search.searchchain.AsyncExecution) FutureResult(com.yahoo.search.searchchain.FutureResult) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) CopyOnWriteHashMap(com.yahoo.concurrent.CopyOnWriteHashMap) Pair(com.yahoo.collections.Pair)

Example 4 with Execution

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());
}
Also used : Chain(com.yahoo.component.chain.Chain) Searcher(com.yahoo.search.Searcher) Fs4Config(com.yahoo.container.search.Fs4Config) MockBackend(com.yahoo.prelude.fastsearch.test.fs4mock.MockBackend) Execution(com.yahoo.search.searchchain.Execution) Ping(com.yahoo.prelude.Ping) Pong(com.yahoo.prelude.Pong) Test(org.junit.Test)

Example 5 with Execution

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());
    }
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result) Test(org.junit.Test)

Aggregations

Execution (com.yahoo.search.searchchain.Execution)232 Query (com.yahoo.search.Query)184 Result (com.yahoo.search.Result)127 Test (org.junit.Test)123 Searcher (com.yahoo.search.Searcher)88 Chain (com.yahoo.component.chain.Chain)59 IndexFacts (com.yahoo.prelude.IndexFacts)34 Hit (com.yahoo.search.result.Hit)25 FeedContext (com.yahoo.feedapi.FeedContext)20 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)20 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)20 ClusterList (com.yahoo.vespaclient.ClusterList)20 AndItem (com.yahoo.prelude.query.AndItem)18 WordItem (com.yahoo.prelude.query.WordItem)17 ComponentId (com.yahoo.component.ComponentId)13 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)13 FastHit (com.yahoo.prelude.fastsearch.FastHit)13 FederationSearcher (com.yahoo.search.federation.FederationSearcher)13 ArrayList (java.util.ArrayList)12 CompositeItem (com.yahoo.prelude.query.CompositeItem)11