use of com.yahoo.fs4.GetDocSumsPacket 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.GetDocSumsPacket in project vespa by vespa-engine.
the class MockFSChannel method addDocsums.
/**
* Adds the number of docsums requested in queryPacket.getHits()
*/
private void addDocsums(List packets, QueryPacket queryPacket) {
int numHits = queryPacket.getHits();
if (lastReceived instanceof GetDocSumsPacket) {
numHits = ((GetDocSumsPacket) lastReceived).getNumDocsums();
}
for (int i = 0; i < numHits; i++) {
ByteBuffer buffer;
if (emptyDocsums) {
buffer = createEmptyDocsumPacketData();
} else {
int[] docids = { 123, 456, 789, 789, 789, 789, 789, 789, 789, 789, 789, 789 };
buffer = createDocsumPacketData(docids[i], DocsumDefinitionTestCase.makeDocsum());
}
buffer.position(0);
packets.add(PacketDecoder.decode(buffer));
}
packets.add(EolPacket.create());
}
use of com.yahoo.fs4.GetDocSumsPacket 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);
}
use of com.yahoo.fs4.GetDocSumsPacket 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()]);
}
Aggregations