Search in sources :

Example 1 with BasicPacket

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

the class PacketWrapper method getPacketsSize.

public int getPacketsSize() {
    int size = 0;
    for (Iterator<BasicPacket> i = resultPackets.iterator(); i.hasNext(); ) {
        QueryResultPacket r = (QueryResultPacket) i.next();
        int l = r.getLength();
        if (l < 0) {
            log.warning("resultpacket length " + l);
            l = 10240;
        }
        size += l;
    }
    for (Iterator<BasicPacket> i = packets.values().iterator(); i.hasNext(); ) {
        BasicPacket packet = i.next();
        int l = packet.getLength();
        if (l < 0) {
            log.warning("BasicPacket length " + l);
            l = 10240;
        }
        size += l;
    }
    size += keySize;
    return size;
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) BasicPacket(com.yahoo.fs4.BasicPacket)

Example 2 with BasicPacket

use of com.yahoo.fs4.BasicPacket 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 3 with BasicPacket

use of com.yahoo.fs4.BasicPacket 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 4 with BasicPacket

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

the class PacketDecoderTestCase method testOneAndAHalfPackets.

/**
 * In this testcase we have one and a half packet
 */
@Test
public void testOneAndAHalfPackets() throws BufferTooSmallException {
    int half = len / 2;
    ByteBuffer data = ByteBuffer.allocate(len + half);
    data.put(queryResultPacketData);
    data.put(queryResultPacketData, 0, half);
    assertEquals((len + half), data.position());
    data.flip();
    // the first packet we should be able to extract just fine
    BasicPacket p1 = PacketDecoder.extractPacket(data).packet;
    assertTrue(p1 instanceof QueryResultPacket);
    PacketDecoder.DecodedPacket p2 = PacketDecoder.extractPacket(data);
    assertTrue(p2 == null);
    // at this point the buffer should be ready for more
    // reading so position should be at the end and limit
    // should be at capacity
    assertEquals(half, data.position());
    assertEquals(data.capacity(), data.limit());
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) BasicPacket(com.yahoo.fs4.BasicPacket) DecodedPacket(com.yahoo.fs4.PacketDecoder.DecodedPacket) PacketDecoder(com.yahoo.fs4.PacketDecoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 5 with BasicPacket

use of com.yahoo.fs4.BasicPacket 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)

Aggregations

BasicPacket (com.yahoo.fs4.BasicPacket)12 QueryResultPacket (com.yahoo.fs4.QueryResultPacket)7 ChannelTimeoutException (com.yahoo.fs4.ChannelTimeoutException)4 DocumentInfo (com.yahoo.fs4.DocumentInfo)4 ByteBuffer (java.nio.ByteBuffer)4 Test (org.junit.Test)4 GetDocSumsPacket (com.yahoo.fs4.GetDocSumsPacket)3 PingPacket (com.yahoo.fs4.PingPacket)3 Packet (com.yahoo.fs4.Packet)2 PongPacket (com.yahoo.fs4.PongPacket)2 QueryPacket (com.yahoo.fs4.QueryPacket)2 InvalidChannelException (com.yahoo.fs4.mplex.InvalidChannelException)2 IOException (java.io.IOException)2 PacketDecoder (com.yahoo.fs4.PacketDecoder)1 DecodedPacket (com.yahoo.fs4.PacketDecoder.DecodedPacket)1 FS4Channel (com.yahoo.fs4.mplex.FS4Channel)1 Pong (com.yahoo.prelude.Pong)1 PacketWrapper (com.yahoo.prelude.fastsearch.PacketWrapper)1 Query (com.yahoo.search.Query)1 Result (com.yahoo.search.Result)1