Search in sources :

Example 6 with Packet

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

the class FastSearcher method fetchSummaries.

private Packet[] fetchSummaries(FS4Channel channel, Result result, String summaryClass) throws InvalidChannelException, ChannelTimeoutException, ClassCastException, IOException {
    BasicPacket[] receivedPackets;
    boolean summaryNeedsQuery = summaryNeedsQuery(result.getQuery());
    if (result.getQuery().getTraceLevel() >= 3)
        result.getQuery().trace((summaryNeedsQuery ? "Resending " : "Not resending ") + "query during document summary fetching", 3);
    GetDocSumsPacket docsumsPacket = GetDocSumsPacket.create(result, summaryClass, summaryNeedsQuery);
    int compressionLimit = result.getQuery().properties().getInteger(PACKET_COMPRESSION_LIMIT, 0);
    docsumsPacket.setCompressionLimit(compressionLimit);
    if (compressionLimit != 0) {
        docsumsPacket.setCompressionType(result.getQuery().properties().getString(PACKET_COMPRESSION_TYPE, "lz4"));
    }
    boolean couldSend = channel.sendPacket(docsumsPacket);
    if (isLoggingFine())
        getLogger().finest("Sent " + docsumsPacket + " on " + channel);
    if (!couldSend)
        throw new IOException("Could not successfully send GetDocSumsPacket.");
    receivedPackets = channel.receivePackets(result.getQuery().getTimeLeft(), docsumsPacket.getNumDocsums() + 1);
    if (isLoggingFine())
        getLogger().finest("got " + receivedPackets.length + "docsumPackets");
    return convertBasicPackets(receivedPackets);
}
Also used : BasicPacket(com.yahoo.fs4.BasicPacket) GetDocSumsPacket(com.yahoo.fs4.GetDocSumsPacket) IOException(java.io.IOException)

Example 7 with Packet

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

the class FastSearcher method doPartialFill.

/**
 * Perform a partial docsum fill for a temporary result
 * representing a partition of the complete fill request.
 *
 * @param result result containing a partition of the unfilled hits
 * @param summaryClass the summary class we want to fill with
 */
protected void doPartialFill(Result result, String summaryClass) {
    if (result.isFilled(summaryClass))
        return;
    Query query = result.getQuery();
    traceQuery(getName(), "fill", query, query.getOffset(), query.getHits(), 2, quotedSummaryClass(summaryClass));
    if (wantsRPCSummaryFill(query)) {
        CompressionType compression = CompressionType.valueOf(query.properties().getString(dispatchCompression, "LZ4").toUpperCase());
        fillSDDocName(result);
        dispatcher.fill(result, summaryClass, compression);
        return;
    }
    CacheKey cacheKey = null;
    PacketWrapper packetWrapper = null;
    if (getCacheControl().useCache(query)) {
        cacheKey = fetchCacheKeyFromHits(result.hits(), summaryClass);
        if (cacheKey == null) {
            QueryPacket queryPacket = QueryPacket.create(query);
            cacheKey = new CacheKey(queryPacket);
        }
        packetWrapper = cacheLookupTwoPhase(cacheKey, result, summaryClass);
    }
    FS4Channel channel = chooseBackend(query).openChannel();
    channel.setQuery(query);
    Packet[] receivedPackets;
    try {
        DocsumPacketKey[] packetKeys;
        if (countFastHits(result) > 0) {
            packetKeys = getPacketKeys(result, summaryClass, false);
            if (packetKeys.length == 0) {
                receivedPackets = new Packet[0];
            } else {
                try {
                    receivedPackets = fetchSummaries(channel, result, summaryClass);
                } catch (InvalidChannelException e) {
                    result.hits().addError(ErrorMessage.createBackendCommunicationError("Invalid channel " + getName() + " (summary fetch)"));
                    return;
                } catch (ChannelTimeoutException e) {
                    result.hits().addError(ErrorMessage.createTimeout("timeout waiting for summaries from " + getName()));
                    return;
                } catch (IOException e) {
                    result.hits().addError(ErrorMessage.createBackendCommunicationError("IO error while talking on channel " + getName() + " (summary fetch): " + e.getMessage()));
                    return;
                }
                if (receivedPackets.length == 0) {
                    result.hits().addError(ErrorMessage.createBackendCommunicationError(getName() + " got no packets back (summary fetch)"));
                    return;
                }
            }
        } else {
            packetKeys = new DocsumPacketKey[0];
            receivedPackets = new Packet[0];
        }
        int skippedHits;
        try {
            FillHitsResult fillHitsResult = fillHits(result, receivedPackets, summaryClass);
            skippedHits = fillHitsResult.skippedHits;
            if (fillHitsResult.error != null) {
                result.hits().addError(ErrorMessage.createTimeout(fillHitsResult.error));
                return;
            }
        } catch (TimeoutException e) {
            result.hits().addError(ErrorMessage.createTimeout(e.getMessage()));
            return;
        } catch (IOException e) {
            result.hits().addError(ErrorMessage.createBackendCommunicationError("Error filling hits with summary fields, source: " + getName() + " Exception thrown: " + e.getMessage()));
            return;
        }
        if (skippedHits == 0 && packetWrapper != null) {
            cacheControl.updateCacheEntry(cacheKey, query, packetKeys, receivedPackets);
        }
        if (skippedHits > 0)
            result.hits().addError(com.yahoo.search.result.ErrorMessage.createEmptyDocsums("Missing hit data for summary '" + summaryClass + "' for " + skippedHits + " hits"));
        result.analyzeHits();
        if (query.getTraceLevel() >= 3) {
            int hitNumber = 0;
            for (Iterator<com.yahoo.search.result.Hit> i = hitIterator(result); i.hasNext(); ) {
                com.yahoo.search.result.Hit hit = i.next();
                if (!(hit instanceof FastHit))
                    continue;
                FastHit fastHit = (FastHit) hit;
                String traceMsg = "Hit: " + (hitNumber++) + " from " + (fastHit.isCached() ? "cache" : "backend");
                if (!fastHit.isFilled(summaryClass))
                    traceMsg += ". Error, hit, not filled";
                query.trace(traceMsg, false, 3);
            }
        }
    } finally {
        channel.close();
    }
}
Also used : Query(com.yahoo.search.Query) QueryPacket(com.yahoo.fs4.QueryPacket) ChannelTimeoutException(com.yahoo.fs4.ChannelTimeoutException) 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) IOException(java.io.IOException) InvalidChannelException(com.yahoo.fs4.mplex.InvalidChannelException) Hit(com.yahoo.search.result.Hit) Hit(com.yahoo.search.result.Hit) FS4Channel(com.yahoo.fs4.mplex.FS4Channel) ChannelTimeoutException(com.yahoo.fs4.ChannelTimeoutException) CompressionType(com.yahoo.compress.CompressionType)

Example 8 with Packet

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

the class FastSearcher method ping.

public static Pong ping(Ping ping, Backend backend, String name) {
    FS4Channel channel = backend.openPingChannel();
    // com.yahoo.prelude.cluster.TrafficNodeMonitor.failed(ErrorMessage)
    try {
        PingPacket pingPacket = new PingPacket();
        try {
            boolean couldSend = channel.sendPacket(pingPacket);
            if (!couldSend) {
                return new Pong(ErrorMessage.createBackendCommunicationError("Could not ping " + name));
            }
        } catch (InvalidChannelException e) {
            return new Pong(ErrorMessage.createBackendCommunicationError("Invalid channel " + name));
        } catch (IllegalStateException e) {
            return new Pong(ErrorMessage.createBackendCommunicationError("Illegal state in FS4: " + e.getMessage()));
        } catch (IOException e) {
            return new Pong(ErrorMessage.createBackendCommunicationError("IO error while sending ping: " + e.getMessage()));
        }
        // We should only get a single packet
        BasicPacket[] packets;
        try {
            packets = channel.receivePackets(ping.getTimeout(), 1);
        } catch (ChannelTimeoutException e) {
            return new Pong(ErrorMessage.createNoAnswerWhenPingingNode("timeout while waiting for fdispatch for " + name));
        } catch (InvalidChannelException e) {
            return new Pong(ErrorMessage.createBackendCommunicationError("Invalid channel for " + name));
        }
        if (packets.length == 0) {
            return new Pong(ErrorMessage.createBackendCommunicationError(name + " got no packets back"));
        }
        try {
            ensureInstanceOf(PongPacket.class, packets[0], name);
        } catch (TimeoutException e) {
            return new Pong(ErrorMessage.createTimeout(e.getMessage()));
        } catch (IOException e) {
            return new Pong(ErrorMessage.createBackendCommunicationError("Unexpected packet class returned after ping: " + e.getMessage()));
        }
        return new Pong((PongPacket) packets[0]);
    } finally {
        if (channel != null) {
            channel.close();
        }
    }
}
Also used : InvalidChannelException(com.yahoo.fs4.mplex.InvalidChannelException) BasicPacket(com.yahoo.fs4.BasicPacket) FS4Channel(com.yahoo.fs4.mplex.FS4Channel) PingPacket(com.yahoo.fs4.PingPacket) IOException(java.io.IOException) ChannelTimeoutException(com.yahoo.fs4.ChannelTimeoutException) Pong(com.yahoo.prelude.Pong) ChannelTimeoutException(com.yahoo.fs4.ChannelTimeoutException)

Example 9 with Packet

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

the class GetDocSumsPacketTestCase method assertPacket.

private static void assertPacket(boolean sendQuery, Result result, byte[] expected) throws BufferTooSmallException {
    GetDocSumsPacket packet = GetDocSumsPacket.create(result, "default", sendQuery);
    ByteBuffer buf = ByteBuffer.allocate(1024);
    packet.encode(buf);
    buf.flip();
    byte[] actual = new byte[buf.remaining()];
    buf.get(actual);
    // assertEquals(Arrays.toString(expected), Arrays.toString(actual));
    assertEquals("Equal length", expected.length, actual.length);
    for (int i = 0; i < expected.length; ++i) {
        if (expected[i] == IGNORE) {
            actual[i] = IGNORE;
        }
    }
    assertArrayEquals(expected, actual);
}
Also used : GetDocSumsPacket(com.yahoo.fs4.GetDocSumsPacket) ByteBuffer(java.nio.ByteBuffer)

Example 10 with Packet

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

the class PacketDecoderTestCase method testPartialWithMoreRoom.

/**
 * In this testcase we have a partial packet and room for
 * more data
 */
@Test
public void testPartialWithMoreRoom() throws BufferTooSmallException {
    ByteBuffer data = ByteBuffer.allocate(len);
    data.put(queryResultPacketData, 0, 10);
    data.flip();
    PacketDecoder.DecodedPacket p = PacketDecoder.extractPacket(data);
    assertTrue(p == null);
}
Also used : DecodedPacket(com.yahoo.fs4.PacketDecoder.DecodedPacket) PacketDecoder(com.yahoo.fs4.PacketDecoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 ByteBuffer (java.nio.ByteBuffer)12 BasicPacket (com.yahoo.fs4.BasicPacket)10 QueryPacket (com.yahoo.fs4.QueryPacket)10 Query (com.yahoo.search.Query)9 QueryResultPacket (com.yahoo.fs4.QueryResultPacket)8 IOException (java.io.IOException)5 ChannelTimeoutException (com.yahoo.fs4.ChannelTimeoutException)4 GetDocSumsPacket (com.yahoo.fs4.GetDocSumsPacket)4 Packet (com.yahoo.fs4.Packet)4 PacketDecoder (com.yahoo.fs4.PacketDecoder)4 DecodedPacket (com.yahoo.fs4.PacketDecoder.DecodedPacket)4 Location (org.bukkit.Location)4 DocumentInfo (com.yahoo.fs4.DocumentInfo)3 PingPacket (com.yahoo.fs4.PingPacket)3 InvalidChannelException (com.yahoo.fs4.mplex.InvalidChannelException)3 Packet (ejip123.Packet)3 BufferTooSmallException (com.yahoo.fs4.BufferTooSmallException)2 DocsumPacket (com.yahoo.fs4.DocsumPacket)2 PongPacket (com.yahoo.fs4.PongPacket)2