Search in sources :

Example 16 with QueryResultPacket

use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.

the class QueryResultTestCase method testDecodeQueryResultMoreHits.

@Test
public void testDecodeQueryResultMoreHits() {
    byte[] packetData = new byte[] { 0, 0, 0, 100, 0, 0, 0, 217 - 256, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 5, 0x40, 0x39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 111, 0, 6, 0, 5, 0, 0, 0, 0, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 90, 0, 0, 0, 0, 0, 0, 0, 91, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0x40, 0x37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0x40, 0x35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 37 };
    ByteBuffer buffer = ByteBuffer.allocate(200);
    buffer.put(packetData);
    buffer.flip();
    BasicPacket packet = PacketDecoder.decode(buffer);
    assertTrue(packet instanceof QueryResultPacket);
    QueryResultPacket result = (QueryResultPacket) packet;
    assertEquals(2, result.getDocuments().size());
    DocumentInfo document1 = result.getDocuments().get(0);
    assertEquals(gid1, document1.getGlobalId());
    DocumentInfo document2 = result.getDocuments().get(1);
    assertEquals(gid2, document2.getGlobalId());
    assertEquals(6, result.getNodesQueried());
    assertEquals(5, result.getNodesReplied());
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) BasicPacket(com.yahoo.fs4.BasicPacket) ByteBuffer(java.nio.ByteBuffer) DocumentInfo(com.yahoo.fs4.DocumentInfo) Test(org.junit.Test)

Example 17 with QueryResultPacket

use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.

the class QueryResultTestCase method testDecodeQueryResultX.

@Test
public void testDecodeQueryResultX() {
    byte[] packetData = new byte[] { 0, 0, 0, 100, 0, 0, 0, 217 - 256, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 5, 0x40, 0x39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 111, 0, 0, 0, 0, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 90, 0, 0, 0, 0, 0, 0, 0, 91, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0x40, 0x37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0x40, 0x35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 37 };
    ByteBuffer buffer = ByteBuffer.allocate(200);
    buffer.put(packetData);
    buffer.flip();
    BasicPacket packet = PacketDecoder.decode(buffer);
    assertTrue(packet instanceof QueryResultPacket);
    QueryResultPacket result = (QueryResultPacket) packet;
    assertTrue(result.getMldFeature());
    assertEquals(5, result.getTotalDocumentCount());
    assertEquals(25, result.getMaxRank());
    assertEquals(111, result.getDocstamp());
    assertEquals(89, result.getCoverageDocs());
    assertEquals(90, result.getActiveDocs());
    assertEquals(91, result.getSoonActiveDocs());
    assertEquals(1, result.getDegradedReason());
    assertEquals(2, result.getDocuments().size());
    DocumentInfo document1 = result.getDocuments().get(0);
    assertEquals(gid1, document1.getGlobalId());
    assertEquals(23.0, document1.getMetric(), delta);
    assertEquals(7, document1.getPartId());
    assertEquals(36, document1.getDistributionKey());
    DocumentInfo document2 = result.getDocuments().get(1);
    assertEquals(gid2, document2.getGlobalId());
    assertEquals(21.0, document2.getMetric(), delta);
    assertEquals(8, document2.getPartId());
    assertEquals(37, document2.getDistributionKey());
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) BasicPacket(com.yahoo.fs4.BasicPacket) ByteBuffer(java.nio.ByteBuffer) DocumentInfo(com.yahoo.fs4.DocumentInfo) Test(org.junit.Test)

Example 18 with QueryResultPacket

use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.

the class FastSearcher method searchTwoPhase.

private Result searchTwoPhase(FS4Channel channel, Query query, QueryPacket queryPacket, CacheKey cacheKey) throws IOException {
    if (isLoggingFine())
        getLogger().finest("sending query packet");
    try {
        boolean couldSend = channel.sendPacket(queryPacket);
        if (!couldSend)
            return new Result(query, ErrorMessage.createBackendCommunicationError("Could not reach '" + getName() + "'"));
    } catch (InvalidChannelException e) {
        return new Result(query, ErrorMessage.createBackendCommunicationError("Invalid channel " + getName()));
    } catch (IllegalStateException e) {
        return new Result(query, ErrorMessage.createBackendCommunicationError("Illegal state in FS4: " + e.getMessage()));
    }
    BasicPacket[] basicPackets;
    try {
        basicPackets = channel.receivePackets(query.getTimeLeft(), 1);
    } catch (ChannelTimeoutException e) {
        return new Result(query, ErrorMessage.createTimeout("Timeout while waiting for " + getName()));
    } catch (InvalidChannelException e) {
        return new Result(query, ErrorMessage.createBackendCommunicationError("Invalid channel for " + getName()));
    }
    if (basicPackets.length == 0) {
        return new Result(query, ErrorMessage.createBackendCommunicationError(getName() + " got no packets back"));
    }
    if (isLoggingFine())
        getLogger().finest("got packets " + basicPackets.length + " packets");
    ensureInstanceOf(QueryResultPacket.class, basicPackets[0], getName());
    QueryResultPacket resultPacket = (QueryResultPacket) basicPackets[0];
    if (isLoggingFine())
        getLogger().finest("got query packet. " + "docsumClass=" + query.getPresentation().getSummary());
    if (query.getPresentation().getSummary() == null)
        query.getPresentation().setSummary(getDefaultDocsumClass());
    Result result = new Result(query);
    addMetaInfo(query, queryPacket.getQueryPacketData(), resultPacket, result, false);
    addUnfilledHits(result, resultPacket.getDocuments(), false, queryPacket.getQueryPacketData(), cacheKey);
    Packet[] packets;
    PacketWrapper packetWrapper = cacheControl.lookup(cacheKey, query);
    if (packetWrapper != null) {
        cacheControl.updateCacheEntry(cacheKey, query, resultPacket);
    } else {
        if (resultPacket.getCoverageFeature() && !resultPacket.getCoverageFull()) {
        // Don't add error here, it was done in first phase
        // No check if packetWrapper already exists, since incomplete
        // first phase data won't be cached anyway.
        } else {
            packets = new Packet[1];
            packets[0] = resultPacket;
            cacheControl.cache(cacheKey, query, new DocsumPacketKey[0], packets);
        }
    }
    return result;
}
Also used : InvalidChannelException(com.yahoo.fs4.mplex.InvalidChannelException) QueryResultPacket(com.yahoo.fs4.QueryResultPacket) QueryResultPacket(com.yahoo.fs4.QueryResultPacket) QueryPacket(com.yahoo.fs4.QueryPacket) PongPacket(com.yahoo.fs4.PongPacket) BasicPacket(com.yahoo.fs4.BasicPacket) GetDocSumsPacket(com.yahoo.fs4.GetDocSumsPacket) Packet(com.yahoo.fs4.Packet) PingPacket(com.yahoo.fs4.PingPacket) BasicPacket(com.yahoo.fs4.BasicPacket) ChannelTimeoutException(com.yahoo.fs4.ChannelTimeoutException) Result(com.yahoo.search.Result)

Example 19 with QueryResultPacket

use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.

the class PacketWrapper method getDocuments.

/**
 * @return list of documents, null if not all are available
 */
public List<DocumentInfo> getDocuments(int offset, int hits) {
    // speculatively allocate list for the hits
    List<DocumentInfo> docs = new ArrayList<>(hits);
    int currentOffset = 0;
    QueryResultPacket r = getFirstResultPacket();
    if (offset >= r.getTotalDocumentCount()) {
        // offset == 0 && totalDocumentCount == 0
        return docs;
    }
    for (Iterator<BasicPacket> i = resultPackets.iterator(); i.hasNext(); ) {
        QueryResultPacket result = (QueryResultPacket) i.next();
        if (result.getOffset() > offset + currentOffset) {
            // we haven't got all the requested document info objects
            return null;
        }
        if (result.getOffset() + result.getDocumentCount() <= currentOffset + offset) {
            // no new hits available
            continue;
        }
        List<DocumentInfo> documents = result.getDocuments();
        int packetOffset = (offset + currentOffset) - result.getOffset();
        int afterLastDoc = Math.min(documents.size(), packetOffset + hits);
        for (Iterator<DocumentInfo> j = documents.subList(packetOffset, afterLastDoc).iterator(); docs.size() < hits && j.hasNext(); ++currentOffset) {
            docs.add(j.next());
        }
        if (hits == docs.size() || offset + docs.size() >= result.getTotalDocumentCount()) {
            // We have the hits we need, or there are no more hits available
            return docs;
        }
    }
    return null;
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) BasicPacket(com.yahoo.fs4.BasicPacket) DocumentInfo(com.yahoo.fs4.DocumentInfo)

Example 20 with QueryResultPacket

use of com.yahoo.fs4.QueryResultPacket in project vespa by vespa-engine.

the class PacketWrapper method cleanResultPackets.

private void cleanResultPackets() {
    int marker;
    QueryResultPacket previous;
    if (resultPackets.size() == 1) {
        return;
    }
    // we know the list is sorted with regard to offset
    // First ensure the list grows in regards to lastOffset as well.
    // Could have done this addResultPacket, but this makes the code
    // simpler.
    previous = (QueryResultPacket) resultPackets.get(0);
    for (int i = 1; i < resultPackets.size(); ++i) {
        QueryResultPacket r = (QueryResultPacket) resultPackets.get(i);
        if (r.getOffset() + r.getDocumentCount() <= previous.getOffset() + previous.getDocumentCount()) {
            resultPackets.remove(i--);
        } else {
            previous = r;
        }
    }
    marker = 0;
    while (marker < (resultPackets.size() - 2)) {
        QueryResultPacket r0 = (QueryResultPacket) resultPackets.get(marker);
        QueryResultPacket r1 = (QueryResultPacket) resultPackets.get(marker + 1);
        QueryResultPacket r2 = (QueryResultPacket) resultPackets.get(marker + 2);
        int nextOffset = r0.getOffset() + r0.getDocumentCount();
        if (r1.getOffset() < nextOffset && r2.getOffset() <= nextOffset) {
            resultPackets.remove(marker + 1);
        }
        ++marker;
    }
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket)

Aggregations

QueryResultPacket (com.yahoo.fs4.QueryResultPacket)28 Test (org.junit.Test)20 CacheKey (com.yahoo.prelude.fastsearch.CacheKey)16 PacketWrapper (com.yahoo.prelude.fastsearch.PacketWrapper)16 Query (com.yahoo.search.Query)16 BasicPacket (com.yahoo.fs4.BasicPacket)7 DocumentInfo (com.yahoo.fs4.DocumentInfo)7 ByteBuffer (java.nio.ByteBuffer)4 GetDocSumsPacket (com.yahoo.fs4.GetDocSumsPacket)2 PacketDecoder (com.yahoo.fs4.PacketDecoder)2 DecodedPacket (com.yahoo.fs4.PacketDecoder.DecodedPacket)2 PingPacket (com.yahoo.fs4.PingPacket)2 PongPacket (com.yahoo.fs4.PongPacket)2 QueryPacket (com.yahoo.fs4.QueryPacket)2 Result (com.yahoo.search.Result)2 ChannelTimeoutException (com.yahoo.fs4.ChannelTimeoutException)1 Packet (com.yahoo.fs4.Packet)1 InvalidChannelException (com.yahoo.fs4.mplex.InvalidChannelException)1