Search in sources :

Example 1 with PongPacket

use of com.yahoo.fs4.PongPacket 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 2 with PongPacket

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

the class MockFSChannel method receivePackets.

public BasicPacket[] receivePackets(long timeout, int packetCount) {
    List<BasicPacket> packets = new java.util.ArrayList<>();
    if (lastReceived instanceof QueryPacket) {
        lastQueryPacket = (QueryPacket) lastReceived;
        QueryResultPacket result = QueryResultPacket.create();
        result.setDocstamp(docstamp);
        result.setChannel(0);
        result.setTotalDocumentCount(2);
        result.setOffset(lastQueryPacket.getOffset());
        if (lastQueryPacket.getOffset() == 0 && lastQueryPacket.getLastOffset() >= 1) {
            result.addDocument(new DocumentInfo(DocsumDefinitionTestCase.createGlobalId(123), 2003, 234, 1000));
        }
        if (lastQueryPacket.getOffset() <= 1 && lastQueryPacket.getLastOffset() >= 2) {
            result.addDocument(new DocumentInfo(DocsumDefinitionTestCase.createGlobalId(456), 1855, 234, 1001));
        }
        packets.add(result);
    } else if (lastReceived instanceof GetDocSumsPacket) {
        addDocsums(packets, lastQueryPacket);
    } else if (lastReceived instanceof PingPacket) {
        packets.add(new PongPacket(activeDocuments));
    }
    while (packetCount >= 0 && packets.size() > packetCount) {
        packets.remove(packets.size() - 1);
    }
    return packets.toArray(new BasicPacket[packets.size()]);
}
Also used : QueryResultPacket(com.yahoo.fs4.QueryResultPacket) BasicPacket(com.yahoo.fs4.BasicPacket) GetDocSumsPacket(com.yahoo.fs4.GetDocSumsPacket) PingPacket(com.yahoo.fs4.PingPacket) PongPacket(com.yahoo.fs4.PongPacket) QueryPacket(com.yahoo.fs4.QueryPacket) DocumentInfo(com.yahoo.fs4.DocumentInfo)

Aggregations

BasicPacket (com.yahoo.fs4.BasicPacket)2 PingPacket (com.yahoo.fs4.PingPacket)2 ChannelTimeoutException (com.yahoo.fs4.ChannelTimeoutException)1 DocumentInfo (com.yahoo.fs4.DocumentInfo)1 GetDocSumsPacket (com.yahoo.fs4.GetDocSumsPacket)1 PongPacket (com.yahoo.fs4.PongPacket)1 QueryPacket (com.yahoo.fs4.QueryPacket)1 QueryResultPacket (com.yahoo.fs4.QueryResultPacket)1 FS4Channel (com.yahoo.fs4.mplex.FS4Channel)1 InvalidChannelException (com.yahoo.fs4.mplex.InvalidChannelException)1 Pong (com.yahoo.prelude.Pong)1 IOException (java.io.IOException)1