diff options
author | Jon Bratseth <bratseth@gmail.com> | 2021-10-08 12:24:06 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2021-10-08 12:24:06 +0200 |
commit | 9794b7ddbdeaa980970c2c0b54721d7a6f27a22a (patch) | |
tree | 9883013307da09f11c5cf45ee1b8fdfad75ba2f3 /container-search/src/main | |
parent | 1b93fc98129d77ada97b88d45ce6499cacecac61 (diff) |
Add Executor to Execution.Context
Diffstat (limited to 'container-search/src/main')
6 files changed, 87 insertions, 51 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/federation/package-info.java b/container-search/src/main/java/com/yahoo/search/federation/package-info.java index 658f3cd22d5..935282ec15e 100644 --- a/container-search/src/main/java/com/yahoo/search/federation/package-info.java +++ b/container-search/src/main/java/com/yahoo/search/federation/package-info.java @@ -13,5 +13,4 @@ @ExportPackage package com.yahoo.search.federation; -import com.yahoo.api.annotations.PublicApi; import com.yahoo.osgi.annotation.ExportPackage; 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 8851977d28c..057b607460c 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 @@ -215,13 +215,13 @@ public class SearchHandler extends LoggingRequestHandler { } private SearchHandler(Statistics statistics, - Metric metric, - Executor executor, - CompiledQueryProfileRegistry queryProfileRegistry, - Embedder embedder, - ExecutionFactory executionFactory, - long numQueriesToTraceOnDebugAfterStartup, - Optional<String> hostResponseHeaderKey) { + Metric metric, + Executor executor, + CompiledQueryProfileRegistry queryProfileRegistry, + Embedder embedder, + ExecutionFactory executionFactory, + long numQueriesToTraceOnDebugAfterStartup, + Optional<String> hostResponseHeaderKey) { super(executor, metric, true); log.log(Level.FINE, () -> "SearchHandler.init " + System.identityHashCode(this)); this.queryProfileRegistry = queryProfileRegistry; @@ -261,7 +261,7 @@ public class SearchHandler extends LoggingRequestHandler { accessLog, queryProfileConfig, containerHttpConfig, - new ExecutionFactory(chainsConfig, indexInfo, clusters, searchers, specialtokens, linguistics, renderers)); + new ExecutionFactory(chainsConfig, indexInfo, clusters, searchers, specialtokens, linguistics, renderers, executor)); } Metric metric() { return metric; } diff --git a/container-search/src/main/java/com/yahoo/search/query/Model.java b/container-search/src/main/java/com/yahoo/search/query/Model.java index dc08e689ff2..2dd4d5c86b1 100644 --- a/container-search/src/main/java/com/yahoo/search/query/Model.java +++ b/container-search/src/main/java/com/yahoo/search/query/Model.java @@ -90,7 +90,7 @@ public class Model implements Cloneable { private Set<String> restrict = new LinkedHashSet<>(); private String searchPath; private String documentDbName = null; - private Execution execution = new Execution(new Execution.Context(null, null, null, null, null)); + private Execution execution = new Execution(new Execution.Context(null, null, null, null, null, null)); public Model(Query query) { setParent(query); diff --git a/container-search/src/main/java/com/yahoo/search/result/Hit.java b/container-search/src/main/java/com/yahoo/search/result/Hit.java index cf9fe33ee88..d7acccc75a7 100644 --- a/container-search/src/main/java/com/yahoo/search/result/Hit.java +++ b/container-search/src/main/java/com/yahoo/search/result/Hit.java @@ -366,7 +366,7 @@ public class Hit extends ListenableFreezableClass implements Data, Comparable<Hi /** * Returns the set of summary classes for which this hit is * filled as an unmodifiable set. If this set is 'null', it means that this hit is - * unfillable, which is equivalent with a hit where all summary + * unfillable, which is equivalent to a hit where all summary * classes have already been used for filling, or a hit where * further filling will yield no extra information, if you prefer * to look at it that way. diff --git a/container-search/src/main/java/com/yahoo/search/searchchain/Execution.java b/container-search/src/main/java/com/yahoo/search/searchchain/Execution.java index 5d04f0aa2e7..331dd7ca165 100644 --- a/container-search/src/main/java/com/yahoo/search/searchchain/Execution.java +++ b/container-search/src/main/java/com/yahoo/search/searchchain/Execution.java @@ -17,6 +17,8 @@ import com.yahoo.search.cluster.PingableSearcher; import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.search.statistics.TimeTracker; +import java.util.concurrent.Executor; + /** * <p>An execution of a search chain. This keeps track of the call state for an execution (in the calling thread) * of the searchers of a search chain.</p> @@ -79,6 +81,8 @@ public class Execution extends com.yahoo.processing.execution.Execution { /** The current linguistics */ private Linguistics linguistics = null; + private Executor executor; + /** Always set if this context belongs to an execution, never set if it does not. */ private final Execution owner; @@ -89,10 +93,10 @@ public class Execution extends com.yahoo.processing.execution.Execution { // package private. /** Create a context used to carry state into another context */ - Context() { this.owner=null; } + Context() { this.owner = null; } /** Create a context which belongs to an execution */ - Context(Execution owner) { this.owner=owner; } + Context(Execution owner) { this.owner = owner; } /** * Creates a context from arguments, all of which may be null, though @@ -107,11 +111,9 @@ public class Execution extends com.yahoo.processing.execution.Execution { * another context. */ public Context(SearchChainRegistry searchChainRegistry, IndexFacts indexFacts, - SpecialTokenRegistry tokenRegistry, RendererRegistry rendererRegistry, Linguistics linguistics) - { + SpecialTokenRegistry tokenRegistry, RendererRegistry rendererRegistry, Linguistics linguistics, + Executor executor) { owner = null; - // The next time something is added here, compose into wrapper objects. Many arguments... - // Four methods need to be updated when adding something: // fill(Context), populateFrom(Context), equals(Context) and, // obviously, the most complete constructor. @@ -120,11 +122,19 @@ public class Execution extends com.yahoo.processing.execution.Execution { this.tokenRegistry = tokenRegistry; this.rendererRegistry = rendererRegistry; this.linguistics = linguistics; + this.executor = executor; + } + + /** @deprecated pass an executor */ + @Deprecated // TODO: Remove on Vespa 8 + public Context(SearchChainRegistry searchChainRegistry, IndexFacts indexFacts, + SpecialTokenRegistry tokenRegistry, RendererRegistry rendererRegistry, Linguistics linguistics) { + this(searchChainRegistry, indexFacts, tokenRegistry, rendererRegistry, linguistics, null); } /** Creates a context stub with no information. This is for unit testing. */ public static Context createContextStub() { - return new Context(null, null, null, null, null); + return new Context(null, null, null, null, null, null); } /** @@ -132,7 +142,7 @@ public class Execution extends com.yahoo.processing.execution.Execution { * initialized. This is for unit testing. */ public static Context createContextStub(IndexFacts indexFacts) { - return new Context(null, indexFacts, null, null, null); + return new Context(null, indexFacts, null, null, null, null); } /** @@ -140,7 +150,7 @@ public class Execution extends com.yahoo.processing.execution.Execution { * initialized. This is for unit testing. */ public static Context createContextStub(SearchChainRegistry searchChainRegistry, IndexFacts indexFacts) { - return new Context(searchChainRegistry, indexFacts, null, null, null); + return new Context(searchChainRegistry, indexFacts, null, null, null, null); } /** @@ -148,7 +158,7 @@ public class Execution extends com.yahoo.processing.execution.Execution { * initialized. This is for unit testing. */ public static Context createContextStub(SearchChainRegistry searchChainRegistry, IndexFacts indexFacts, Linguistics linguistics) { - return new Context(searchChainRegistry, indexFacts, null, null, linguistics); + return new Context(searchChainRegistry, indexFacts, null, null, linguistics, null); } /** @@ -161,21 +171,19 @@ public class Execution extends com.yahoo.processing.execution.Execution { // breakdown and detailedDiagnostics has no unset state, so they are always copied detailedDiagnostics = sourceContext.detailedDiagnostics; breakdown = sourceContext.breakdown; - if (indexFacts == null) { + if (indexFacts == null) indexFacts = sourceContext.indexFacts; - } - if (tokenRegistry == null) { + if (tokenRegistry == null) tokenRegistry = sourceContext.tokenRegistry; - } - if (searchChainRegistry == null) { + if (searchChainRegistry == null) searchChainRegistry = sourceContext.searchChainRegistry; - } - if (rendererRegistry == null) { + if (rendererRegistry == null) rendererRegistry = sourceContext.rendererRegistry; - } - if (linguistics == null) { + if (linguistics == null) linguistics = sourceContext.linguistics; - } + if (executor == null) + executor = sourceContext.executor; + } /** @@ -191,6 +199,7 @@ public class Execution extends com.yahoo.processing.execution.Execution { detailedDiagnostics = other.detailedDiagnostics; breakdown = other.breakdown; linguistics = other.linguistics; + executor = other.executor; } public boolean equals(Context other) { @@ -202,7 +211,8 @@ public class Execution extends com.yahoo.processing.execution.Execution { && other.searchChainRegistry == searchChainRegistry && other.detailedDiagnostics == detailedDiagnostics && other.breakdown == breakdown - && other.linguistics == linguistics; + && other.linguistics == linguistics + && other.executor == executor; } @Override @@ -210,19 +220,15 @@ public class Execution extends com.yahoo.processing.execution.Execution { return java.util.Objects.hash(indexFacts, rendererRegistry, tokenRegistry, searchChainRegistry, detailedDiagnostics, breakdown, - linguistics); + linguistics, + executor); } @Override public boolean equals(Object other) { - if (other == null) { - return false; - } - if (other.getClass() != Context.class) { - return false; - } else { - return equals((Context) other); - } + if (other == null) return false; + if (other.getClass() != Context.class) return false; + return equals((Context) other); } /** @@ -268,9 +274,7 @@ public class Execution extends com.yahoo.processing.execution.Execution { * IndexFacts instance in a subclass. E.g. * execution.context().setIndexFacts(new WrapperClass(execution.context().getIndexFacts())). * - * @param indexFacts - * an instance to override the following searcher's view of - * the indexes. + * @param indexFacts an instance to override the following searcher's view of the indexes */ public void setIndexFacts(IndexFacts indexFacts) { this.indexFacts = indexFacts; @@ -294,9 +298,7 @@ public class Execution extends com.yahoo.processing.execution.Execution { return rendererRegistry; } - /** - * @return the current set of special strings for the query tokenizer - */ + /** Returns the current set of special strings for the query tokenizer */ public SpecialTokenRegistry getTokenRegistry() { return tokenRegistry; } @@ -359,6 +361,9 @@ public class Execution extends com.yahoo.processing.execution.Execution { this.linguistics = linguistics; } + /** Returns the executor that should be used to execute tasks as part of this execution, or null if none */ + public Executor getExecutor() { return executor; } + /** Creates a child trace if this has an owner, or a root trace otherwise */ private Trace createChildTrace() { return owner!=null ? owner.trace().createChild() : Trace.createRoot(0); diff --git a/container-search/src/main/java/com/yahoo/search/searchchain/ExecutionFactory.java b/container-search/src/main/java/com/yahoo/search/searchchain/ExecutionFactory.java index a813229c984..3ec29a77323 100644 --- a/container-search/src/main/java/com/yahoo/search/searchchain/ExecutionFactory.java +++ b/container-search/src/main/java/com/yahoo/search/searchchain/ExecutionFactory.java @@ -1,6 +1,7 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.searchchain; +import com.google.inject.Inject; import com.yahoo.component.AbstractComponent; import com.yahoo.component.chain.Chain; import com.yahoo.component.chain.ChainsConfigurer; @@ -9,6 +10,7 @@ import com.yahoo.component.chain.model.ChainsModelBuilder; import com.yahoo.component.provider.ComponentRegistry; import com.yahoo.container.QrSearchersConfig; import com.yahoo.container.core.ChainsConfig; +import com.yahoo.container.handler.threadpool.ContainerThreadPool; import com.yahoo.language.Linguistics; import com.yahoo.language.simple.SimpleLinguistics; import com.yahoo.prelude.IndexFacts; @@ -20,6 +22,8 @@ import com.yahoo.search.config.IndexInfoConfig; import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.vespa.configdefinition.SpecialtokensConfig; +import java.util.concurrent.Executor; + /** * Provides creation of fully configured query Execution instances. * Have an instance of this injected if you need to execute queries which are not initiated from @@ -34,19 +38,46 @@ public class ExecutionFactory extends AbstractComponent { private final SpecialTokenRegistry specialTokens; private final Linguistics linguistics; private final RendererRegistry rendererRegistry; + private final Executor executor; + @Inject public ExecutionFactory(ChainsConfig chainsConfig, IndexInfoConfig indexInfo, QrSearchersConfig clusters, ComponentRegistry<Searcher> searchers, SpecialtokensConfig specialTokens, Linguistics linguistics, - ComponentRegistry<Renderer> renderers) { + ComponentRegistry<Renderer> renderers, + ContainerThreadPool threadpool) { + this(chainsConfig, indexInfo, clusters, searchers, specialTokens, linguistics, renderers, threadpool.executor()); + } + + public ExecutionFactory(ChainsConfig chainsConfig, + IndexInfoConfig indexInfo, + QrSearchersConfig clusters, + ComponentRegistry<Searcher> searchers, + SpecialtokensConfig specialTokens, + Linguistics linguistics, + ComponentRegistry<Renderer> renderers, + Executor executor) { this.searchChainRegistry = createSearchChainRegistry(searchers, chainsConfig); this.indexFacts = new IndexFacts(new IndexModel(indexInfo, clusters)).freeze(); this.specialTokens = new SpecialTokenRegistry(specialTokens); this.linguistics = linguistics; this.rendererRegistry = new RendererRegistry(renderers.allComponents()); + this.executor = executor; + } + + /** @deprecated pass the container threadpool */ + @Deprecated // TODO: Remove on Vespa 8 + public ExecutionFactory(ChainsConfig chainsConfig, + IndexInfoConfig indexInfo, + QrSearchersConfig clusters, + ComponentRegistry<Searcher> searchers, + SpecialtokensConfig specialTokens, + Linguistics linguistics, + ComponentRegistry<Renderer> renderers) { + this(chainsConfig, indexInfo, clusters, searchers, specialTokens, linguistics, renderers, (Executor)null); } private SearchChainRegistry createSearchChainRegistry(ComponentRegistry<Searcher> searchers, ChainsConfig chainsConfig) { @@ -63,7 +94,7 @@ public class ExecutionFactory extends AbstractComponent { */ public Execution newExecution(Chain<? extends Searcher> searchChain) { return new Execution(searchChain, - new Execution.Context(searchChainRegistry, indexFacts, specialTokens, rendererRegistry, linguistics)); + new Execution.Context(searchChainRegistry, indexFacts, specialTokens, rendererRegistry, linguistics, executor)); } /** @@ -72,7 +103,7 @@ public class ExecutionFactory extends AbstractComponent { */ public Execution newExecution(String searchChainId) { return new Execution(searchChainRegistry().getChain(searchChainId), - new Execution.Context(searchChainRegistry, indexFacts, specialTokens, rendererRegistry, linguistics)); + new Execution.Context(searchChainRegistry, indexFacts, specialTokens, rendererRegistry, linguistics, executor)); } /** Returns the search chain registry used by this */ @@ -93,7 +124,8 @@ public class ExecutionFactory extends AbstractComponent { new ComponentRegistry<>(), new SpecialtokensConfig.Builder().build(), new SimpleLinguistics(), - new ComponentRegistry<>()); + new ComponentRegistry<>(), + (Executor)null); } } |