diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-08-17 13:52:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-17 13:52:00 +0200 |
commit | 62c865e2b2a6862bbd8692ebcf373572a32f821f (patch) | |
tree | 867acb67a460969222a8cc9c55d2dc6e20b6f68d /container-search | |
parent | 52f25f90f06fc5adce9f8f3f092f7d2c3a78c289 (diff) | |
parent | 64943ba4aef65f3892063a5e1b6617841a53b970 (diff) |
Merge pull request #3136 from vespa-engine/balder/use-rank-profile-in-sessionid
Add rankprofile to the base sessionId.
Diffstat (limited to 'container-search')
9 files changed, 71 insertions, 48 deletions
diff --git a/container-search/src/main/java/com/yahoo/fs4/GetDocSumsPacket.java b/container-search/src/main/java/com/yahoo/fs4/GetDocSumsPacket.java index e85a74de611..a40f5d55317 100644 --- a/container-search/src/main/java/com/yahoo/fs4/GetDocSumsPacket.java +++ b/container-search/src/main/java/com/yahoo/fs4/GetDocSumsPacket.java @@ -77,7 +77,7 @@ public class GetDocSumsPacket extends Packet { boolean useQueryCache = query.getRanking().getQueryCache(); // If feature cache is used we need to include the sessionId as key. if (useQueryCache) { // TODO: Move this decision (and the key) to ranking - query.getRanking().getProperties().put(sessionIdKey, query.getSessionId(false).asUtf8String().toString()); + query.getRanking().getProperties().put(sessionIdKey, query.getSessionId(false).toString()); } // always allow slime docsums 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 3f852a6fc12..eb05bdc672c 100644 --- a/container-search/src/main/java/com/yahoo/fs4/QueryPacket.java +++ b/container-search/src/main/java/com/yahoo/fs4/QueryPacket.java @@ -9,10 +9,10 @@ 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; import java.nio.ByteBuffer; -import java.util.Collections; import java.util.List; @@ -148,8 +148,9 @@ public class QueryPacket extends Packet { } if (sendSessionKey) { - buffer.putInt(query.getSessionId(true).asUtf8String().getByteLength()); - buffer.put(query.getSessionId(true).asUtf8String().getBytes()); + Utf8String key = query.getSessionId(true).asUtf8String(); + buffer.putInt(key.getByteLength()); + buffer.put(key.getBytes()); } if ((featureFlag & QF_LOCATION) != 0) { 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 9f8228d2857..509a5f3d1de 100644 --- a/container-search/src/main/java/com/yahoo/search/Query.java +++ b/container-search/src/main/java/com/yahoo/search/Query.java @@ -12,15 +12,9 @@ import com.yahoo.prelude.query.Highlight; import com.yahoo.prelude.query.QueryException; import com.yahoo.prelude.query.textualrepresentation.TextualQueryRepresentation; import com.yahoo.processing.request.CompoundName; +import com.yahoo.search.query.*; import com.yahoo.search.query.profile.types.FieldType; import com.yahoo.search.query.properties.PropertyMap; -import com.yahoo.search.query.Model; -import com.yahoo.search.query.ParameterParser; -import com.yahoo.search.query.Presentation; -import com.yahoo.search.query.QueryTree; -import com.yahoo.search.query.Ranking; -import com.yahoo.search.query.SessionId; -import com.yahoo.search.query.Sorting; import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry; import com.yahoo.search.query.profile.types.FieldDescription; import com.yahoo.search.query.profile.types.QueryProfileFieldType; @@ -32,7 +26,6 @@ import com.yahoo.search.query.properties.QueryPropertyAliases; import com.yahoo.search.query.properties.RequestContextProperties; import com.yahoo.yolean.Exceptions; import com.yahoo.search.federation.FederationSearcher; -import com.yahoo.search.query.Properties; import com.yahoo.search.query.Sorting.AttributeSorter; import com.yahoo.search.query.Sorting.FieldOrder; import com.yahoo.search.query.Sorting.Order; @@ -40,7 +33,6 @@ import com.yahoo.search.query.context.QueryContext; import com.yahoo.search.query.profile.ModelObjectMap; import com.yahoo.search.query.profile.QueryProfileProperties; import com.yahoo.search.query.profile.compiled.CompiledQueryProfile; -import com.yahoo.search.result.ErrorMessage; import com.yahoo.search.yql.NullItemException; import com.yahoo.search.yql.VespaSerializer; import com.yahoo.search.yql.YqlParser; @@ -48,13 +40,12 @@ import com.yahoo.search.yql.YqlParser; import edu.umd.cs.findbugs.annotations.Nullable; import java.nio.ByteBuffer; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Logger; /** @@ -162,7 +153,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { private QueryContext context = null; /** Used for downstream session caches */ - private SessionId sessionId = null; + private final AtomicReference<UniqueRequestId> sessionId = new AtomicReference<>(); //--------------- Owned sub-objects containing query properties ---------------- @@ -971,9 +962,18 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { * @return the session id of this query, or null if not set and create is false */ public SessionId getSessionId(boolean create) { - if (sessionId == null && create) - this.sessionId = SessionId.next(); - return sessionId; + UniqueRequestId uniqId = sessionId.get(); + if (uniqId == null && ! create) return null; + + if (uniqId == null && create) { + uniqId = UniqueRequestId.next(); + sessionId.compareAndSet(null, uniqId); + uniqId = sessionId.get(); + } + + String rankProfile = getRanking().getProfile(); + + return new SessionId(uniqId, rankProfile); } public boolean hasEncodableProperties() { diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java b/container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java index 47558b131a0..003ba9a5261 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java @@ -21,6 +21,7 @@ import com.yahoo.slime.BinaryFormat; import com.yahoo.slime.Cursor; import com.yahoo.slime.Slime; import com.yahoo.data.access.Inspector; +import com.yahoo.text.Utf8String; import com.yahoo.vespa.config.search.DispatchConfig; import java.util.Iterator; @@ -117,7 +118,8 @@ public class Dispatcher extends AbstractComponent { } Query query = result.getQuery(); - byte[] serializedSlime = BinaryFormat.encode(toSlime(query.getRanking().getProfile(), summaryClass, query.getSessionId(false), hits)); + String rankProfile = query.getRanking().getProfile(); + byte[] serializedSlime = BinaryFormat.encode(toSlime(rankProfile, summaryClass, query.getSessionId(false), hits)); double timeoutSeconds = ((double)query.getTimeLeft()-3.0)/1000.0; Compressor.Compression compressionResult = compressor.compress(compression, serializedSlime); client.getDocsums(hits, node, compressionResult.type(), diff --git a/container-search/src/main/java/com/yahoo/search/grouping/vespa/GroupingExecutor.java b/container-search/src/main/java/com/yahoo/search/grouping/vespa/GroupingExecutor.java index 1661283f060..ae128e70f20 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/vespa/GroupingExecutor.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/vespa/GroupingExecutor.java @@ -29,7 +29,6 @@ import com.yahoo.search.result.ErrorMessage; import com.yahoo.search.result.Hit; import com.yahoo.search.searchchain.Execution; import com.yahoo.searchlib.aggregation.Grouping; -import com.yahoo.vespa.objects.Identifiable; import com.yahoo.vespa.objects.ObjectOperation; import com.yahoo.vespa.objects.ObjectPredicate; diff --git a/container-search/src/main/java/com/yahoo/search/query/SessionId.java b/container-search/src/main/java/com/yahoo/search/query/SessionId.java index 5831b10c88d..c6e34e7e430 100644 --- a/container-search/src/main/java/com/yahoo/search/query/SessionId.java +++ b/container-search/src/main/java/com/yahoo/search/query/SessionId.java @@ -1,36 +1,25 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.query; -import com.yahoo.container.Server; import com.yahoo.text.Utf8String; -import java.util.concurrent.atomic.AtomicLong; - /** - * A query id which is unique across this cluster - consisting of - * container runtime id + timestamp + serial. + * A id which is unique across this cluster + the extra differentiator. * - * @author bratseth + * @author baldersheim */ public class SessionId { - private static final String serverId = Server.get().getServerDiscriminator(); - private static final AtomicLong sequenceCounter = new AtomicLong(); - private final Utf8String id; - private SessionId(String serverId, long timestamp, long sequence) { - this.id = new Utf8String(serverId + "." + timestamp + "." + sequence); + public SessionId(UniqueRequestId requestId, String extraDifferentiator) { + this.id = new Utf8String(requestId.toString() + "." + extraDifferentiator); } - public Utf8String asUtf8String() { return id; } - - /** - * Creates a session id which is unique across the cluster this runtime is a member of each time this is called. - * Calling this causes synchronization. - */ - public static SessionId next() { - return new SessionId(serverId, System.currentTimeMillis(), sequenceCounter.getAndIncrement()); + @Override + public String toString() { + return id.toString(); } + public Utf8String asUtf8String() { return id; } } diff --git a/container-search/src/main/java/com/yahoo/search/query/UniqueRequestId.java b/container-search/src/main/java/com/yahoo/search/query/UniqueRequestId.java new file mode 100644 index 00000000000..11ed03a24d2 --- /dev/null +++ b/container-search/src/main/java/com/yahoo/search/query/UniqueRequestId.java @@ -0,0 +1,34 @@ +package com.yahoo.search.query; + +import com.yahoo.container.Server; + +import java.util.concurrent.atomic.AtomicLong; + +/** + * A query id which is unique across this cluster - consisting of + * container runtime id + timestamp + serial. + * + * @author bratseth + */ +public class UniqueRequestId { + + private static final String serverId = Server.get().getServerDiscriminator(); + private static final AtomicLong sequenceCounter = new AtomicLong(); + + private final String id; + + private UniqueRequestId(String serverId, long timestamp, long sequence) { + this.id = serverId + "." + timestamp + "." + sequence; + } + + @Override + public String toString() { return id; } + + /** + * Creates a session id which is unique across the cluster this runtime is a member of each time this is called. + * Calling this causes synchronization. + */ + public static UniqueRequestId next() { + return new UniqueRequestId(serverId, System.currentTimeMillis(), sequenceCounter.getAndIncrement()); + } +} diff --git a/container-search/src/test/java/com/yahoo/fs4/test/GetDocSumsPacketTestCase.java b/container-search/src/test/java/com/yahoo/fs4/test/GetDocSumsPacketTestCase.java index d572a835102..78bf14bae99 100644 --- a/container-search/src/test/java/com/yahoo/fs4/test/GetDocSumsPacketTestCase.java +++ b/container-search/src/test/java/com/yahoo/fs4/test/GetDocSumsPacketTestCase.java @@ -10,7 +10,6 @@ import com.yahoo.search.result.Hit; import org.junit.Test; import java.nio.ByteBuffer; -import java.util.Arrays; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -69,7 +68,7 @@ public class GetDocSumsPacketTestCase { result.getQuery().getRanking().setQueryCache(true); FastHit hit = new FastHit(); result.hits().add(hit); - assertPacket(false, result, new byte[] { 0, 0, 0, -123, 0, 0, 0, -37, 0, 0, 56, 17, 0, 0, 0, 0, + assertPacket(false, result, new byte[] { 0, 0, 0, -115, 0, 0, 0, -37, 0, 0, 56, 17, 0, 0, 0, 0, // query timeout IGNORE, IGNORE, IGNORE, IGNORE, // "default" - rank profile @@ -79,8 +78,8 @@ public class GetDocSumsPacketTestCase { // 2 property entries 0, 0, 0, 2, // rank: sessionId => qrserver.0.XXXXXXXXXXXXX.0 - 0, 0, 0, 4, 'r', 'a', 'n', 'k', 0, 0, 0, 1, 0, 0, 0, 9, 's', 'e', 's', 's', 'i', 'o', 'n', 'I', 'd', 0, 0, 0, 26, 'q', 'r', 's', 'e', 'r', 'v', 'e', 'r', '.', - IGNORE, '.', IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, '.', IGNORE, + 0, 0, 0, 4, 'r', 'a', 'n', 'k', 0, 0, 0, 1, 0, 0, 0, 9, 's', 'e', 's', 's', 'i', 'o', 'n', 'I', 'd', 0, 0, 0, 34, 'q', 'r', 's', 'e', 'r', 'v', 'e', 'r', '.', + IGNORE, '.', IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, '.', IGNORE, '.','d', 'e', 'f', 'a', 'u', 'l', 't', // caches: features => true 0, 0, 0, 6, 'c', 'a', 'c', 'h', 'e', 's', 0, 0, 0, 1, 0, 0, 0, 5, 'q', 'u', 'e', 'r', 'y', 0, 0, 0, 4, 't', 'r', 'u', 'e', // flags diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java index 2526e690868..5a5e7586a32 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java @@ -37,7 +37,6 @@ import org.junit.Test; import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicReference; @@ -297,7 +296,7 @@ public class FastSearcherTestCase { buf.get(actual); byte IGNORE = 69; - byte[] expected = new byte[] { 0, 0, 0, -85, 0, 0, 0, -37, 0, 0, 48, 17, 0, 0, 0, 0, + byte[] expected = new byte[] { 0, 0, 0, -77, 0, 0, 0, -37, 0, 0, 48, 17, 0, 0, 0, 0, // query timeout IGNORE, IGNORE, IGNORE, IGNORE, // "default" - rank profile @@ -305,8 +304,8 @@ public class FastSearcherTestCase { // 3 property entries (rank, match, caches) 0, 0, 0, 3, // rank: sessionId => qrserver.0.XXXXXXXXXXXXX.0 - 0, 0, 0, 4, 'r', 'a', 'n', 'k', 0, 0, 0, 1, 0, 0, 0, 9, 's', 'e', 's', 's', 'i', 'o', 'n', 'I', 'd', 0, 0, 0, 26, 'q', 'r', 's', 'e', 'r', 'v', 'e', 'r', '.', - IGNORE, '.', IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, '.', IGNORE, + 0, 0, 0, 4, 'r', 'a', 'n', 'k', 0, 0, 0, 1, 0, 0, 0, 9, 's', 'e', 's', 's', 'i', 'o', 'n', 'I', 'd', 0, 0, 0, 34, 'q', 'r', 's', 'e', 'r', 'v', 'e', 'r', '.', + IGNORE, '.', IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, IGNORE, '.', IGNORE, '.','d', 'e', 'f', 'a', 'u', 'l', 't', // match: documentdb.searchdoctype => test 0, 0, 0, 5, 'm', 'a', 't', 'c', 'h', 0, 0, 0, 1, 0, 0, 0, 24, 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 'd', 'b', '.', 's', 'e', 'a', 'r', 'c', 'h', 'd', 'o', 'c', 't', 'y', 'p', 'e', 0, 0, 0, 4, 't', 'e', 's', 't', // sessionId => qrserver.0.XXXXXXXXXXXXX.0 |