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;
}
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);
}
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();
}
}
}
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());
}
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());
}
Aggregations