Search in sources :

Example 1 with CompressionType

use of com.yahoo.compress.CompressionType 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 2 with CompressionType

use of com.yahoo.compress.CompressionType in project vespa by vespa-engine.

the class BaseStructDataType method setCompressionConfig.

/**
 * Set the config to the compressor used to compress data of this type
 */
public void setCompressionConfig(CompressionConfig config) {
    CompressionType type = config.type;
    compressor = new Compressor(type, config.compressionLevel, config.thresholdFactor(), (int) config.minsize);
}
Also used : Compressor(com.yahoo.compress.Compressor) CompressionType(com.yahoo.compress.CompressionType)

Example 3 with CompressionType

use of com.yahoo.compress.CompressionType in project vespa by vespa-engine.

the class RPCUtil method decodeStateBundleFromSetDistributionStatesRequest.

public static ClusterStateBundle decodeStateBundleFromSetDistributionStatesRequest(Request req) {
    final CompressionType type = CompressionType.valueOf(req.parameters().get(0).asInt8());
    final int uncompressedSize = req.parameters().get(1).asInt32();
    final byte[] compressedPayload = req.parameters().get(2).asData();
    SlimeClusterStateBundleCodec codec = new SlimeClusterStateBundleCodec();
    Compressor.Compression compression = new Compressor.Compression(type, uncompressedSize, compressedPayload);
    return codec.decode(EncodedClusterStateBundle.fromCompressionBuffer(compression));
}
Also used : Compressor(com.yahoo.compress.Compressor) CompressionType(com.yahoo.compress.CompressionType)

Example 4 with CompressionType

use of com.yahoo.compress.CompressionType in project vespa by vespa-engine.

the class MockClient method getDocsums.

@Override
public void getDocsums(List<FastHit> hitsContext, NodeConnection node, CompressionType compression, int uncompressedSize, byte[] compressedSlime, Dispatcher.GetDocsumsResponseReceiver responseReceiver, double timeoutSeconds) {
    if (malfunctioning) {
        responseReceiver.receive(GetDocsumsResponseOrError.fromError("Malfunctioning"));
        return;
    }
    Inspector request = BinaryFormat.decode(compressor.decompress(compressedSlime, compression, uncompressedSize)).get();
    String docsumClass = request.field("class").asString();
    List<Map<String, Object>> docsumsToReturn = new ArrayList<>();
    request.field("gids").traverse((ArrayTraverser) (index, gid) -> {
        GlobalId docId = new GlobalId(gid.asData());
        docsumsToReturn.add(docsums.get(new DocsumKey(node.toString(), docId, docsumClass)));
    });
    Slime responseSlime = new Slime();
    Cursor root = responseSlime.setObject();
    Cursor docsums = root.setArray("docsums");
    for (Map<String, Object> docsumFields : docsumsToReturn) {
        Cursor docsumItem = docsums.addObject();
        Cursor docsum = docsumItem.setObject("docsum");
        for (Map.Entry<String, Object> field : docsumFields.entrySet()) {
            if (field.getValue() instanceof Integer)
                docsum.setLong(field.getKey(), (Integer) field.getValue());
            else if (field.getValue() instanceof String)
                docsum.setString(field.getKey(), (String) field.getValue());
            else
                throw new RuntimeException();
        }
    }
    byte[] slimeBytes = BinaryFormat.encode(responseSlime);
    Compressor.Compression compressionResult = compressor.compress(compression, slimeBytes);
    GetDocsumsResponse response = new GetDocsumsResponse(compressionResult.type().getCode(), slimeBytes.length, compressionResult.data(), hitsContext);
    responseReceiver.receive(GetDocsumsResponseOrError.fromResponse(response));
}
Also used : Cursor(com.yahoo.slime.Cursor) BinaryFormat(com.yahoo.slime.BinaryFormat) Inspector(com.yahoo.slime.Inspector) ArrayTraverser(com.yahoo.slime.ArrayTraverser) IdIdString(com.yahoo.document.idstring.IdIdString) Slime(com.yahoo.slime.Slime) HashMap(java.util.HashMap) Compressor(com.yahoo.compress.Compressor) FastHit(com.yahoo.prelude.fastsearch.FastHit) ArrayList(java.util.ArrayList) List(java.util.List) CompressionType(com.yahoo.compress.CompressionType) Map(java.util.Map) GlobalId(com.yahoo.document.GlobalId) ArrayList(java.util.ArrayList) Compressor(com.yahoo.compress.Compressor) IdIdString(com.yahoo.document.idstring.IdIdString) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) GlobalId(com.yahoo.document.GlobalId) Inspector(com.yahoo.slime.Inspector) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with CompressionType

use of com.yahoo.compress.CompressionType in project vespa by vespa-engine.

the class RPCSendV2 method createReply.

@Override
protected Reply createReply(Values ret, String serviceName, Trace trace) {
    CompressionType compression = CompressionType.valueOf(ret.get(3).asInt8());
    byte[] slimeBytes = compressor.decompress(ret.get(5).asData(), compression, ret.get(4).asInt32());
    Slime slime = BinaryFormat.decode(slimeBytes);
    Inspector root = slime.get();
    Version version = new Version(root.field(VERSION_F).asString());
    byte[] payload = root.field(BLOB_F).asData();
    // Make sure that the owner understands the protocol.
    Reply reply = null;
    Error error = null;
    if (payload.length > 0) {
        Object retval = decode(new Utf8Array(root.field(PROTOCOL_F).asUtf8()), version, payload);
        if (retval instanceof Reply) {
            reply = (Reply) retval;
        } else {
            error = (Error) retval;
        }
    }
    if (reply == null) {
        reply = new EmptyReply();
    }
    if (error != null) {
        reply.addError(error);
    }
    reply.setRetryDelay(root.field(RETRYDELAY_F).asDouble());
    Inspector errors = root.field(ERRORS_F);
    for (int i = 0; i < errors.entries(); i++) {
        Inspector e = errors.entry(i);
        String service = e.field(SERVICE_F).asString();
        reply.addError(new Error((int) e.field(CODE_F).asLong(), e.field(MSG_F).asString(), (service != null && service.length() > 0) ? service : serviceName));
    }
    if (trace.getLevel() > 0) {
        trace.getRoot().addChild(TraceNode.decode(root.field(TRACE_F).asString()));
    }
    return reply;
}
Also used : Version(com.yahoo.component.Version) Inspector(com.yahoo.slime.Inspector) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) Slime(com.yahoo.slime.Slime) CompressionType(com.yahoo.compress.CompressionType) Utf8Array(com.yahoo.text.Utf8Array) EmptyReply(com.yahoo.messagebus.EmptyReply)

Aggregations

CompressionType (com.yahoo.compress.CompressionType)7 Compressor (com.yahoo.compress.Compressor)3 Inspector (com.yahoo.slime.Inspector)3 Slime (com.yahoo.slime.Slime)3 Version (com.yahoo.component.Version)2 Utf8Array (com.yahoo.text.Utf8Array)2 ArrayList (java.util.ArrayList)2 Tuple2 (com.yahoo.collections.Tuple2)1 Field (com.yahoo.document.Field)1 GlobalId (com.yahoo.document.GlobalId)1 StructDataType (com.yahoo.document.StructDataType)1 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)1 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)1 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)1 FieldValue (com.yahoo.document.datatypes.FieldValue)1 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)1 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)1 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)1 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)1 PredicateFieldValue (com.yahoo.document.datatypes.PredicateFieldValue)1