summaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-08-28 20:38:35 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2017-08-28 20:38:35 +0200
commit2a0a35a68edc3f604aa1747ffbbdefbd821c5470 (patch)
treea9c618276b5febbad477bffe68f942237c24abeb /container-search
parenta88fd8184a3b232d4c0f238e675f10a80724ca93 (diff)
Restore old beahvior on clone.
- If getSessionId(true) has been called prior to clone, allcones will share sessionid with parent. - If not, they will all get their own.
Diffstat (limited to 'container-search')
-rw-r--r--container-search/src/main/java/com/yahoo/search/Query.java15
-rw-r--r--container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java14
2 files changed, 19 insertions, 10 deletions
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 509a5f3d1de..23da30120da 100644
--- a/container-search/src/main/java/com/yahoo/search/Query.java
+++ b/container-search/src/main/java/com/yahoo/search/Query.java
@@ -153,7 +153,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
private QueryContext context = null;
/** Used for downstream session caches */
- private final AtomicReference<UniqueRequestId> sessionId = new AtomicReference<>();
+ private UniqueRequestId requestId = null;
//--------------- Owned sub-objects containing query properties ----------------
@@ -962,18 +962,13 @@ 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) {
- UniqueRequestId uniqId = sessionId.get();
- if (uniqId == null && ! create) return null;
+ if (requestId == null && ! create) return null;
- if (uniqId == null && create) {
- uniqId = UniqueRequestId.next();
- sessionId.compareAndSet(null, uniqId);
- uniqId = sessionId.get();
+ if (requestId == null && create) {
+ requestId = UniqueRequestId.next();
}
- String rankProfile = getRanking().getProfile();
-
- return new SessionId(uniqId, rankProfile);
+ return new SessionId(requestId, getRanking().getProfile());
}
public boolean hasEncodableProperties() {
diff --git a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java
index 3ffc5dbcf78..0e9451685cb 100644
--- a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java
@@ -670,6 +670,20 @@ public class QueryTestCase {
}
@Test
+ public void testThatSessionIdIsNotSharedIfCreatedAfterClone() {
+ Query q = new Query();
+ Query q2 = q.clone();
+ assertNull(q.getSessionId(false));
+ assertNull(q2.getSessionId(false));
+
+ assertNotNull(q.getSessionId(true));
+ assertNull(q2.getSessionId(false));
+
+ assertNotNull(q2.getSessionId(true));
+ assertNotEquals(q.getSessionId(false), q2.getSessionId(false));
+ }
+
+ @Test
public void testPositiveTerms() {
Query q = new Query(httpEncode("/?query=-a \"b c\" d e"));
Item i = q.getModel().getQueryTree().getRoot();