From b743451d1ff4d3cc2846fccc819c1fa82156db97 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Wed, 19 Dec 2018 15:54:00 +0100 Subject: Revert "Bratseth/search container deprecations" --- configdefinitions/src/vespa/slobroks.def | 3 +- .../main/java/com/yahoo/container/Container.java | 18 ++++++++++++ .../src/main/resources/configdefinitions/qr.def | 3 +- .../container/jdisc/ConfiguredApplication.java | 4 +++ .../main/java/com/yahoo/fs4/GetDocSumsPacket.java | 2 +- .../prelude/fastsearch/VespaBackEndSearcher.java | 2 +- .../prelude/statistics/StatisticsSearcher.java | 3 ++ .../src/main/java/com/yahoo/search/Query.java | 16 ++++++++++ .../com/yahoo/search/dispatch/RpcFillInvoker.java | 2 +- .../search/grouping/vespa/GroupingExecutor.java | 2 +- .../com/yahoo/search/query/UniqueRequestId.java | 13 +++++++++ .../yahoo/fs4/test/GetDocSumsPacketTestCase.java | 2 +- .../fastsearch/test/FastSearcherTestCase.java | 2 +- .../java/com/yahoo/search/test/QueryTestCase.java | 34 +++++++++++----------- 14 files changed, 81 insertions(+), 25 deletions(-) diff --git a/configdefinitions/src/vespa/slobroks.def b/configdefinitions/src/vespa/slobroks.def index b4e5536d2df..2dd17b307e1 100644 --- a/configdefinitions/src/vespa/slobroks.def +++ b/configdefinitions/src/vespa/slobroks.def @@ -2,7 +2,8 @@ namespace=cloud.config ### All params must be flagged as 'restart' because this config is manually -### retrieved by ConfiguredApplication.start to init the rpc server +### retrieved by ConfiguredApplication.start to init the rpc server in +### com.yahoo.container.Server. ## The connectionspec for a slobrok is used for connecting to it using ## the FNET Remote Tools framework. It is normally on the form diff --git a/container-core/src/main/java/com/yahoo/container/Container.java b/container-core/src/main/java/com/yahoo/container/Container.java index 031d4a26d05..e84c8b340a4 100755 --- a/container-core/src/main/java/com/yahoo/container/Container.java +++ b/container-core/src/main/java/com/yahoo/container/Container.java @@ -3,11 +3,13 @@ package com.yahoo.container; import com.yahoo.component.AbstractComponent; import com.yahoo.component.provider.ComponentRegistry; +import com.yahoo.container.core.config.BundleLoader; import com.yahoo.filedistribution.fileacquirer.FileAcquirer; import com.yahoo.filedistribution.fileacquirer.FileAcquirerFactory; import com.yahoo.jdisc.handler.RequestHandler; import com.yahoo.jdisc.service.ClientProvider; import com.yahoo.jdisc.service.ServerProvider; +import com.yahoo.osgi.Osgi; import com.yahoo.vespa.config.ConfigTransformer; import com.yahoo.vespa.config.UrlDownloader; @@ -32,6 +34,8 @@ public class Container { private volatile FileAcquirer fileAcquirer; private volatile UrlDownloader urlDownloader; + private volatile BundleLoader bundleLoader; + private static Logger logger = Logger.getLogger(Container.class.getName()); // TODO: Make this final again. @@ -39,6 +43,12 @@ public class Container { public static Container get() { return instance; } + /** @deprecated do not use */ + @Deprecated // TODO: Remove + public void setOsgi(Osgi osgi) { + bundleLoader = new BundleLoader(osgi); + } + public void shutdown() { if (fileAcquirer != null) fileAcquirer.shutdown(); @@ -51,6 +61,14 @@ public class Container { return fileAcquirer; } + /** @deprecated do not use */ + @Deprecated // TODO: Remove + public BundleLoader getBundleLoader() { + if (bundleLoader == null) + bundleLoader = new BundleLoader(null); + return bundleLoader; + } + /** * Hack. For internal use only, will be removed later * diff --git a/container-core/src/main/resources/configdefinitions/qr.def b/container-core/src/main/resources/configdefinitions/qr.def index fe44b04e9d5..ddf12fd32f5 100644 --- a/container-core/src/main/resources/configdefinitions/qr.def +++ b/container-core/src/main/resources/configdefinitions/qr.def @@ -2,7 +2,8 @@ namespace=container ### All params must be flagged as 'restart' because this config is manually -### retrieved by ConfiguredApplication.start to init the rpc server +### retrieved by ConfiguredApplication.start to init the rpc server in +### com.yahoo.container.Server. ## filedistributor rpc configuration filedistributor.configid reference default="" restart diff --git a/container-disc/src/main/java/com/yahoo/container/jdisc/ConfiguredApplication.java b/container-disc/src/main/java/com/yahoo/container/jdisc/ConfiguredApplication.java index eae121604e4..1cb4e1d4555 100644 --- a/container-disc/src/main/java/com/yahoo/container/jdisc/ConfiguredApplication.java +++ b/container-disc/src/main/java/com/yahoo/container/jdisc/ConfiguredApplication.java @@ -39,6 +39,7 @@ import com.yahoo.jrt.slobrok.api.SlobrokList; import com.yahoo.log.LogLevel; import com.yahoo.log.LogSetup; import com.yahoo.net.HostName; +import com.yahoo.osgi.OsgiImpl; import com.yahoo.vespa.config.ConfigKey; import com.yahoo.yolean.Exceptions; @@ -114,6 +115,7 @@ public final class ConfiguredApplication implements Application { } + @SuppressWarnings("deprecation") // TODO: Remove when the Container line below is removed @Inject public ConfiguredApplication(ContainerActivator activator, OsgiFramework osgiFramework, @@ -125,6 +127,7 @@ public final class ConfiguredApplication implements Application { this.subscriberFactory = subscriberFactory; this.configId = System.getProperty("config.id"); this.restrictedOsgiFramework = new DisableOsgiFramework(new RestrictedBundleContext(osgiFramework.bundleContext())); + Container.get().setOsgi(new OsgiImpl(osgiFramework)); // TODO: Remove, not necessary applicationWithLegacySetup = new ContainerDiscApplication(configId); } @@ -189,6 +192,7 @@ public final class ConfiguredApplication implements Application { try { Container.get().setupFileAcquirer(config.filedistributor()); Container.get().setupUrlDownloader(); + com.yahoo.container.Server.get().initialize(config); } catch (Exception e) { log.log(LogLevel.ERROR, "Caught exception when initializing server. Exiting.", e); Runtime.getRuntime().halt(1); 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 7dabb52a233..a3b8e4f29a2 100644 --- a/container-search/src/main/java/com/yahoo/fs4/GetDocSumsPacket.java +++ b/container-search/src/main/java/com/yahoo/fs4/GetDocSumsPacket.java @@ -76,7 +76,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().toString()); + query.getRanking().getProperties().put(sessionIdKey, query.getSessionId(false).toString()); } // set the default features diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java index d6e87e58fd8..7def8e744a6 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java @@ -372,7 +372,7 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { s.append(" ranking.queryCache=true"); } if (query.getGroupingSessionCache() || query.getRanking().getQueryCache()) { - s.append(" sessionId=").append(query.getSessionId()); + s.append(" sessionId=").append(query.getSessionId(false)); } List grouping = GroupingExecutor.getGroupingList(query); diff --git a/container-search/src/main/java/com/yahoo/prelude/statistics/StatisticsSearcher.java b/container-search/src/main/java/com/yahoo/prelude/statistics/StatisticsSearcher.java index 3606e01ffe5..beb79acb893 100644 --- a/container-search/src/main/java/com/yahoo/prelude/statistics/StatisticsSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/statistics/StatisticsSearcher.java @@ -3,6 +3,7 @@ package com.yahoo.prelude.statistics; import com.yahoo.component.chain.dependencies.Before; import com.yahoo.concurrent.CopyOnWriteHashMap; +import com.yahoo.container.Server; import com.yahoo.container.protect.Error; import com.yahoo.jdisc.Metric; import com.yahoo.log.LogLevel; @@ -17,7 +18,9 @@ import com.yahoo.search.result.ErrorHit; import com.yahoo.search.result.ErrorMessage; import com.yahoo.search.searchchain.Execution; import com.yahoo.search.searchchain.PhaseNames; +import com.yahoo.statistics.Callback; import com.yahoo.statistics.Counter; +import com.yahoo.statistics.Handle; import com.yahoo.statistics.Value; import java.util.HashMap; 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 73335037b94..b4adca2cef1 100644 --- a/container-search/src/main/java/com/yahoo/search/Query.java +++ b/container-search/src/main/java/com/yahoo/search/Query.java @@ -982,6 +982,22 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { */ public HttpRequest getHttpRequest() { return httpRequest; } + /** + * Returns the unique and stable session id of this query. + * + * @param create if true this is created if not already set + * @return the session id of this query, or null if not set and create is false + * @deprecated use getSessionId() or getSessionId(serverId) instead + */ + @Deprecated + public SessionId getSessionId(boolean create) { + if ( ! create) return getSessionId(); + + if (requestId == null) + requestId = UniqueRequestId.next(); + return new SessionId(requestId, getRanking().getProfile()); + } + /** Returns the session id of this query, or null if none is assigned */ public SessionId getSessionId() { if (requestId == null) return null; diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/RpcFillInvoker.java b/container-search/src/main/java/com/yahoo/search/dispatch/RpcFillInvoker.java index 578c447dfbe..fb72e8c77c9 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/RpcFillInvoker.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/RpcFillInvoker.java @@ -110,7 +110,7 @@ public class RpcFillInvoker extends FillInvoker { Query query = result.getQuery(); String rankProfile = query.getRanking().getProfile(); byte[] serializedSlime = BinaryFormat - .encode(toSlime(rankProfile, summaryClass, query.getModel().getDocumentDb(), query.getSessionId(), hits)); + .encode(toSlime(rankProfile, summaryClass, query.getModel().getDocumentDb(), query.getSessionId(false), hits)); double timeoutSeconds = ((double) query.getTimeLeft() - 3.0) / 1000.0; Compressor.Compression compressionResult = resourcePool.compressor().compress(compression, serializedSlime); resourcePool.client().getDocsums(hits, node, compressionResult.type(), serializedSlime.length, compressionResult.data(), 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 7c2e774f68b..b28e648be78 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 @@ -217,7 +217,7 @@ public class GroupingExecutor extends Searcher { baseRoot = origRoot.clone(); } if (query.isTraceable(3) && query.getGroupingSessionCache()) { - query.trace("Grouping in " + (lastPass + 1) + " passes. SessionId='" + query.getSessionId() + "'.", 3); + query.trace("Grouping in " + (lastPass + 1) + " passes. SessionId='" + query.getSessionId(false) + "'.", 3); } for (int pass = 0; pass <= lastPass; ++pass) { boolean firstPass = (pass == 0); 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 index f57a5f4ab1e..49529936901 100644 --- a/container-search/src/main/java/com/yahoo/search/query/UniqueRequestId.java +++ b/container-search/src/main/java/com/yahoo/search/query/UniqueRequestId.java @@ -1,6 +1,8 @@ // 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 java.util.concurrent.atomic.AtomicLong; /** @@ -22,6 +24,17 @@ public class UniqueRequestId { @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. + * + * @deprecated use nextId(serverId) instead + */ + @Deprecated + public static UniqueRequestId next() { + return new UniqueRequestId(Server.get().getServerDiscriminator(), System.currentTimeMillis(), sequenceCounter.getAndIncrement()); + } + /** * 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. 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 54512e727c2..9b1517454a9 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 @@ -50,7 +50,7 @@ public class GetDocSumsPacketTestCase { @Test public void requireThatSessionIdIsEncodedAsPropertyWhenUsingSearchSession() throws BufferTooSmallException { Result result = new Result(new Query("?query=foo")); - SessionId sessionId = result.getQuery().getSessionId("node-0"); + SessionId sessionId = result.getQuery().getSessionId(true); // create session id. result.getQuery().getRanking().setQueryCache(true); FastHit hit = new FastHit(); result.hits().add(hit); 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 fd01fb9a740..4b827b2942f 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 @@ -331,7 +331,7 @@ public class FastSearcherTestCase { byte[] actual = new byte[buf.remaining()]; buf.get(actual); - SessionId sessionId = query.getSessionId(); + SessionId sessionId = query.getSessionId(false); byte IGNORE = 69; ByteBuffer answer = ByteBuffer.allocate(1024); answer.put(new byte[] { 0, 0, 0, (byte)(141+sessionId.asUtf8String().getByteLength()), 0, 0, 0, -37, 0, 0, 16, 17, 0, 0, 0, 0, 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 a5c46fc7887..ed80c0bf256 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 @@ -684,34 +684,34 @@ public class QueryTestCase { @Test public void testThatSessionIdIsUniquePerQuery() { Query q = new Query(); - assertNull(q.getSessionId()); - assertNull(q.getSessionId()); - SessionId s1 = q.getSessionId("node-0"); + assertNull(q.getSessionId(false)); + assertNull(q.getSessionId(false)); + SessionId s1 = q.getSessionId(true); assertNotNull(s1); - SessionId s2 = q.getSessionId("node-0"); + SessionId s2 = q.getSessionId(true); assertNotSame(s1, s2); assertEquals(s1, s2); assertEquals(s1.toString(), s2.toString()); Query q2 = new Query(); - assertNotEquals(q.getSessionId(), q2.getSessionId("node-0")); - assertNotEquals(q.getSessionId().toString(), q2.getSessionId("node-0").toString()); + assertNotEquals(q.getSessionId(false), q2.getSessionId(true)); + assertNotEquals(q.getSessionId(false).toString(), q2.getSessionId(true).toString()); } @Test public void testThatCloneGetANewSessionId() { Query q = new Query(); - q.getSessionId("node-0"); + q.getSessionId(true); Query clonedQ = q.clone(); - assertNull(clonedQ.getSessionId()); - assertNotEquals(q.getSessionId(), clonedQ.getSessionId("node-0")); + assertNull(clonedQ.getSessionId(false)); + assertNotEquals(q.getSessionId(false), clonedQ.getSessionId(true)); } @Test public void testThatSessionIdIsUniquePerRankProfilePerQuery() { Query q = new Query(); - SessionId s1 = q.getSessionId("node-0"); + SessionId s1 = q.getSessionId(true); q.getRanking().setProfile("my-profile"); - SessionId s2 = q.getSessionId(); + SessionId s2 = q.getSessionId(false); assertNotEquals(s1, s2); } @@ -719,14 +719,14 @@ public class QueryTestCase { public void testThatSessionIdIsNotSharedIfCreatedAfterClone() { Query q = new Query(); Query q2 = q.clone(); - assertNull(q.getSessionId()); - assertNull(q2.getSessionId()); + assertNull(q.getSessionId(false)); + assertNull(q2.getSessionId(false)); - assertNotNull(q.getSessionId("node-0")); - assertNull(q2.getSessionId()); + assertNotNull(q.getSessionId(true)); + assertNull(q2.getSessionId(false)); - assertNotNull(q2.getSessionId("node-0")); - assertNotEquals(q.getSessionId(), q2.getSessionId()); + assertNotNull(q2.getSessionId(true)); + assertNotEquals(q.getSessionId(false), q2.getSessionId(false)); } @Test -- cgit v1.2.3