diff options
Diffstat (limited to 'container-search/src/main')
4 files changed, 38 insertions, 55 deletions
diff --git a/container-search/src/main/java/com/yahoo/fs4/QueryPacket.java b/container-search/src/main/java/com/yahoo/fs4/QueryPacket.java index 028b0176c85..60bd5314cff 100644 --- a/container-search/src/main/java/com/yahoo/fs4/QueryPacket.java +++ b/container-search/src/main/java/com/yahoo/fs4/QueryPacket.java @@ -8,7 +8,6 @@ import com.yahoo.search.Query; import com.yahoo.search.grouping.vespa.GroupingExecutor; import com.yahoo.search.query.Ranking; import com.yahoo.searchlib.aggregation.Grouping; -import com.yahoo.text.Utf8; import com.yahoo.text.Utf8String; import com.yahoo.vespa.objects.BufferSerializer; @@ -29,10 +28,6 @@ public class QueryPacket extends Packet { private final Query query; private QueryPacketData queryPacketData; - private int sessionOffset = 0; // Start of sessionKey ignore section for cache key - private int sessionSize = 0; // Length of sessionKey ignore section for cache key - private int ignoreableOffset = 0; // Start of (hits/offset/timestamp) ignore section for cache key - private int ignoreableSize = 0; // Length of (hits/offset/timestamp) ignore section for cache key private QueryPacket(String serverId, Query query) { this.serverId = serverId; @@ -72,62 +67,16 @@ public class QueryPacket extends Packet { return query.getHits(); } - private byte[] getSummaryClassAsUtf8() { - if (query.getPresentation().getSummary() != null) { - return Utf8.toBytes(query.getPresentation().getSummary()); - } - return new byte[0]; - } - - private int getSessionKeySkipLength() { - return (sessionSize > 0) ? sessionSize + 4 : 0; - } - - /** - * Returns an opaque cache key for the query represented by this - * (pre-serialized) packet. - */ - public byte[] getOpaqueCacheKey() { - - // the cache key is generated by taking the serialized packet - // body and switching out the offset/hits/timeout fields with - // the requested summary class. We add a single '\0' byte in - // addition to the utf8 encoded summaryclass name to avoid the - // need to fiddle with feature flags to handle a non-existing - // summary class. - - byte[] utf8Summary = getSummaryClassAsUtf8(); - byte[] stripped = new byte[encodedBody.length - (ignoreableSize + getSessionKeySkipLength()) + utf8Summary.length + 1]; - - System.arraycopy(encodedBody, 0, stripped, 0, ignoreableOffset); - stripped[1] = (byte)(stripped[1] & 0x7f); // Ignore sessionKey feature flag - System.arraycopy(utf8Summary, 0, stripped, ignoreableOffset, utf8Summary.length); - stripped[ignoreableOffset + utf8Summary.length] = 0; - - // Copy part up to sessionKey - System.arraycopy(encodedBody, ignoreableOffset + ignoreableSize, - stripped, ignoreableOffset + utf8Summary.length + 1, - sessionOffset - (ignoreableOffset + ignoreableSize)); - // Copy part after sessionKey - System.arraycopy(encodedBody, sessionOffset + getSessionKeySkipLength(), - stripped, utf8Summary.length + 1 + (sessionOffset - ignoreableSize), - encodedBody.length - (sessionOffset + getSessionKeySkipLength())); - return stripped; - } - public void encodeBody(ByteBuffer buffer) { queryPacketData = new QueryPacketData(); - final int relativeZero = buffer.position(); boolean sendSessionKey = query.getGroupingSessionCache() || query.getRanking().getQueryCache(); int featureFlag = getFeatureInt(sendSessionKey); buffer.putInt(featureFlag); - ignoreableOffset = buffer.position() - relativeZero; IntegerCompressor.putCompressedPositiveNumber(getOffset(), buffer); IntegerCompressor.putCompressedPositiveNumber(getHits(), buffer); buffer.putInt(Math.max(1, (int)query.getTimeLeft())); // Safety to avoid sending down 0 or negative number - ignoreableSize = buffer.position() - relativeZero - ignoreableOffset; buffer.putInt(getFlagInt()); int startOfFieldToSave = buffer.position(); Item.putString(query.getRanking().getProfile(), buffer); @@ -162,10 +111,8 @@ public class QueryPacket extends Packet { buffer.put(blob); } - sessionOffset = buffer.position() - relativeZero; if (sendSessionKey) { Utf8String key = query.getSessionId(serverId).asUtf8String(); - sessionSize = key.getByteLength(); buffer.putInt(key.getByteLength()); buffer.put(key.getBytes()); } diff --git a/container-search/src/main/java/com/yahoo/search/Query.java b/container-search/src/main/java/com/yahoo/search/Query.java index 97a8c35bfa3..b292dec4bfc 100644 --- a/container-search/src/main/java/com/yahoo/search/Query.java +++ b/container-search/src/main/java/com/yahoo/search/Query.java @@ -137,6 +137,9 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { /** The query context level, 0 means no tracing */ private int traceLevel = 0; + /** The query explain level, 0 means no explaining */ + private int explainLevel = 0; + // The timeout to be used when dumping rank features private static final long dumpTimeout = (6 * 60 * 1000); // 6 minutes private static final long defaultTimeout = 500; @@ -190,6 +193,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { public static final CompoundName QUERY_PROFILE = new CompoundName("queryProfile"); public static final CompoundName SEARCH_CHAIN = new CompoundName("searchChain"); public static final CompoundName TRACE_LEVEL = new CompoundName("traceLevel"); + public static final CompoundName EXPLAIN_LEVEL = new CompoundName("explainLevel"); public static final CompoundName NO_CACHE = new CompoundName("noCache"); public static final CompoundName GROUPING_SESSION_CACHE = new CompoundName("groupingSessionCache"); public static final CompoundName TIMEOUT = new CompoundName("timeout"); @@ -205,6 +209,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { argumentType.addField(new FieldDescription(QUERY_PROFILE.toString(), "string")); argumentType.addField(new FieldDescription(SEARCH_CHAIN.toString(), "string")); argumentType.addField(new FieldDescription(TRACE_LEVEL.toString(), "integer", "tracelevel")); + argumentType.addField(new FieldDescription(EXPLAIN_LEVEL.toString(), "integer", "explainlevel")); argumentType.addField(new FieldDescription(NO_CACHE.toString(), "boolean", "nocache")); argumentType.addField(new FieldDescription(GROUPING_SESSION_CACHE.toString(), "boolean", "groupingSessionCache")); argumentType.addField(new FieldDescription(TIMEOUT.toString(), "string", "timeout")); @@ -565,6 +570,11 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { * Higher numbers means increasingly more tracing */ public void setTraceLevel(int traceLevel) { this.traceLevel = traceLevel; } + /** + * Sets the explain level of this query, 0 means no tracing + * Higher numbers means increasingly more explaining + */ + public void setExplainLevel(int explainLevel) { this.explainLevel = explainLevel; } /** * Returns the context level of this query, 0 means no tracing @@ -573,6 +583,12 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { public int getTraceLevel() { return traceLevel; } /** + * Returns the explain level of this query, 0 means no tracing + * Higher numbers means increasingly more explaining + */ + public int getExplainLevel() { return explainLevel; } + + /** * Returns the context level of this query, 0 means no tracing * Higher numbers means increasingly more tracing */ @@ -747,6 +763,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { */ public void attachContext(Query query) throws IllegalStateException { query.setTraceLevel(getTraceLevel()); + query.setExplainLevel(getExplainLevel()); if (context == null) { // Nothing to attach to. This is about the same as // getTraceLevel() == 0, @@ -962,6 +979,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { assert (clone.properties().getParentQuery() == clone); clone.setTraceLevel(getTraceLevel()); + clone.setExplainLevel(getExplainLevel()); clone.setHits(getHits()); clone.setOffset(getOffset()); clone.setNoCache(getNoCache()); @@ -1066,10 +1084,24 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { return Collections.<String,Boolean>emptyMap(); } + private int computeTraceLevelForBackend() { + int traceLevel = getTraceLevel(); + if (model.getExecution().trace().getForceTimestamps()) { + traceLevel = Math.max(traceLevel, 5); // Backend produces timing information on level 4 and 5 + } + if (getExplainLevel() > 0) { + traceLevel = Math.max(traceLevel, getExplainLevel() + 5); + } + return traceLevel; + } + private Map<String, String> createModelMap() { Map<String, String> m = new HashMap<>(); if (model.getSearchPath() != null) m.put("searchpath", model.getSearchPath()); - if (getTraceLevel() > 0) m.put("tracelevel", String.valueOf(getTraceLevel())); + + int traceLevel = computeTraceLevelForBackend(); + if (traceLevel > 0) m.put("tracelevel", String.valueOf(traceLevel)); + return m; } diff --git a/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java b/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java index 14a15e71bf7..cb69f2abd07 100644 --- a/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java +++ b/container-search/src/main/java/com/yahoo/search/handler/SearchHandler.java @@ -81,6 +81,8 @@ public class SearchHandler extends LoggingRequestHandler { private final int maxThreads; private static final CompoundName DETAILED_TIMING_LOGGING = new CompoundName("trace.timingDetails"); + private static final CompoundName FORCE_TIMESTAMPS = new CompoundName("trace.timestamps"); + /** Event name for number of connections to the search subsystem */ private static final String SEARCH_CONNECTIONS = "search_connections"; @@ -101,7 +103,6 @@ public class SearchHandler extends LoggingRequestHandler { public static final String defaultSearchChainName = "default"; private static final String fallbackSearchChain = "vespa"; - private static final CompoundName FORCE_TIMESTAMPS = new CompoundName("trace.timestamps");; private final Linguistics linguistics; diff --git a/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java b/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java index ac0e715abd2..a510c5f9564 100644 --- a/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java +++ b/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java @@ -126,6 +126,7 @@ public class QueryProperties extends Properties { if (key.equals(Query.HITS)) return query.getHits(); if (key.equals(Query.OFFSET)) return query.getOffset(); if (key.equals(Query.TRACE_LEVEL)) return query.getTraceLevel(); + if (key.equals(Query.EXPLAIN_LEVEL)) return query.getExplainLevel(); if (key.equals(Query.TIMEOUT)) return query.getTimeout(); if (key.equals(Query.NO_CACHE)) return query.getNoCache(); if (key.equals(Query.GROUPING_SESSION_CACHE)) return query.getGroupingSessionCache(); @@ -266,6 +267,8 @@ public class QueryProperties extends Properties { query.setOffset(asInteger(value,0)); else if (key.equals(Query.TRACE_LEVEL)) query.setTraceLevel(asInteger(value,0)); + else if (key.equals(Query.EXPLAIN_LEVEL)) + query.setExplainLevel(asInteger(value,0)); else if (key.equals(Query.TIMEOUT)) query.setTimeout(value.toString()); else if (key.equals(Query.NO_CACHE)) |