From ebaad057086d6d7f8e9c2af33b5d29ad3cd41973 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Tue, 13 Aug 2019 15:55:43 +0200 Subject: Declare dispatch parameters --- .../src/main/java/com/yahoo/search/Query.java | 2 + .../java/com/yahoo/search/dispatch/Dispatcher.java | 74 +++++++++++++++------- .../main/java/com/yahoo/search/query/Model.java | 3 +- .../query/profile/types/FieldDescription.java | 2 +- 4 files changed, 55 insertions(+), 26 deletions(-) (limited to 'container-search/src') 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 e0bd3fc4f99..8354ed12fb3 100644 --- a/container-search/src/main/java/com/yahoo/search/Query.java +++ b/container-search/src/main/java/com/yahoo/search/Query.java @@ -13,6 +13,7 @@ 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.dispatch.Dispatcher; import com.yahoo.search.dispatch.rpc.ProtobufSerialization; import com.yahoo.search.federation.FederationSearcher; import com.yahoo.search.query.Model; @@ -220,6 +221,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { argumentType.addField(new FieldDescription(Ranking.RANKING, new QueryProfileFieldType(Ranking.getArgumentType()))); argumentType.addField(new FieldDescription(Model.MODEL, new QueryProfileFieldType(Model.getArgumentType()))); argumentType.addField(new FieldDescription(Select.SELECT, new QueryProfileFieldType(Select.getArgumentType()))); + argumentType.addField(new FieldDescription(Dispatcher.DISPATCH, new QueryProfileFieldType(Dispatcher.getArgumentType()))); argumentType.freeze(); } public static QueryProfileType getArgumentType() { return argumentType; } 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 fb587e394d9..07e65a9f265 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 @@ -17,6 +17,9 @@ import com.yahoo.search.dispatch.searchcluster.Group; import com.yahoo.search.dispatch.searchcluster.Node; import com.yahoo.search.dispatch.searchcluster.PingFactory; import com.yahoo.search.dispatch.searchcluster.SearchCluster; +import com.yahoo.search.query.profile.types.FieldDescription; +import com.yahoo.search.query.profile.types.FieldType; +import com.yahoo.search.query.profile.types.QueryProfileType; import com.yahoo.search.result.ErrorMessage; import com.yahoo.vespa.config.search.DispatchConfig; @@ -40,16 +43,21 @@ import java.util.Set; * @author ollvir */ public class Dispatcher extends AbstractComponent { + + public static final String DISPATCH = "dispatch"; + private static final String INTERNAL = "internal"; + private static final String PROTOBUF = "profobuf"; + private static final String FDISPATCH_METRIC = "dispatch_fdispatch"; private static final String INTERNAL_METRIC = "dispatch_internal"; private static final int MAX_GROUP_SELECTION_ATTEMPTS = 3; /** If enabled, this internal dispatcher will be preferred over fdispatch whenever possible */ - public static final CompoundName dispatchInternal = new CompoundName("dispatch.internal"); + public static final CompoundName dispatchInternal = CompoundName.fromComponents(DISPATCH, INTERNAL); /** If enabled, search queries will use protobuf rpc */ - public static final CompoundName dispatchProtobuf = new CompoundName("dispatch.protobuf"); + public static final CompoundName dispatchProtobuf = CompoundName.fromComponents(DISPATCH, PROTOBUF); /** A model of the search cluster this dispatches to */ private final SearchCluster searchCluster; @@ -63,8 +71,25 @@ public class Dispatcher extends AbstractComponent { private final Metric metric; private final Metric.Context metricContext; - public static Dispatcher create(String clusterId, DispatchConfig dispatchConfig, FS4ResourcePool fs4ResourcePool, int containerClusterSize, - VipStatus vipStatus, Metric metric) { + private static final QueryProfileType argumentType; + + static { + argumentType = new QueryProfileType(DISPATCH); + argumentType.setStrict(true); + argumentType.setBuiltin(true); + argumentType.addField(new FieldDescription(INTERNAL, FieldType.booleanType)); + argumentType.addField(new FieldDescription(PROTOBUF, FieldType.booleanType)); + argumentType.freeze(); + } + + public static QueryProfileType getArgumentType() { return argumentType; } + + public static Dispatcher create(String clusterId, + DispatchConfig dispatchConfig, + FS4ResourcePool fs4ResourcePool, + int containerClusterSize, + VipStatus vipStatus, + Metric metric) { var searchCluster = new SearchCluster(clusterId, dispatchConfig, containerClusterSize, vipStatus); var rpcFactory = new RpcInvokerFactory(new RpcResourcePool(dispatchConfig), searchCluster, !dispatchConfig.useFdispatchByDefault()); var pingFactory = dispatchConfig.useFdispatchByDefault()? new FS4PingFactory(fs4ResourcePool) : rpcFactory; @@ -72,11 +97,14 @@ public class Dispatcher extends AbstractComponent { return new Dispatcher(searchCluster, dispatchConfig, rpcFactory, pingFactory, metric); } - public Dispatcher(SearchCluster searchCluster, DispatchConfig dispatchConfig, InvokerFactory invokerFactory, PingFactory pingFactory, - Metric metric) { + public Dispatcher(SearchCluster searchCluster, + DispatchConfig dispatchConfig, + InvokerFactory invokerFactory, + PingFactory pingFactory, + Metric metric) { this.searchCluster = searchCluster; this.loadBalancer = new LoadBalancer(searchCluster, - dispatchConfig.distributionPolicy() == DispatchConfig.DistributionPolicy.ROUNDROBIN); + dispatchConfig.distributionPolicy() == DispatchConfig.DistributionPolicy.ROUNDROBIN); this.multilevelDispatch = dispatchConfig.useMultilevelDispatch(); this.internalDispatchByDefault = !dispatchConfig.useFdispatchByDefault(); this.invokerFactory = invokerFactory; @@ -105,14 +133,14 @@ public class Dispatcher extends AbstractComponent { } public Optional getSearchInvoker(Query query, VespaBackEndSearcher searcher) { - if (multilevelDispatch || !query.properties().getBoolean(dispatchInternal, internalDispatchByDefault)) { + if (multilevelDispatch || ! query.properties().getBoolean(dispatchInternal, internalDispatchByDefault)) { emitDispatchMetric(Optional.empty()); return Optional.empty(); } Optional invoker = getSearchPathInvoker(query, searcher); - if (!invoker.isPresent()) { + if (invoker.isEmpty()) { invoker = getInternalInvoker(query, searcher); } if (invoker.isPresent() && query.properties().getBoolean(com.yahoo.search.query.Model.ESTIMATE)) { @@ -128,17 +156,14 @@ public class Dispatcher extends AbstractComponent { // build invoker based on searchpath private Optional getSearchPathInvoker(Query query, VespaBackEndSearcher searcher) { String searchPath = query.getModel().getSearchPath(); - if (searchPath == null) { - return Optional.empty(); - } + if (searchPath == null) return Optional.empty(); + try { List nodes = SearchPath.selectNodes(searchPath, searchCluster); - if (nodes.isEmpty()) { - return Optional.empty(); - } else { - query.trace(false, 2, "Dispatching internally with search path ", searchPath); - return invokerFactory.createSearchInvoker(searcher, query, OptionalInt.empty(), nodes, true); - } + if (nodes.isEmpty()) return Optional.empty(); + + query.trace(false, 2, "Dispatching internally with search path ", searchPath); + return invokerFactory.createSearchInvoker(searcher, query, OptionalInt.empty(), nodes, true); } catch (InvalidSearchPathException e) { return Optional.of(new SearchErrorInvoker(ErrorMessage.createIllegalQuery(e.getMessage()))); } @@ -158,14 +183,15 @@ public class Dispatcher extends AbstractComponent { Set rejected = null; for (int i = 0; i < max; i++) { Optional groupInCluster = loadBalancer.takeGroup(rejected); - if (!groupInCluster.isPresent()) { - // No groups available - break; - } + if (groupInCluster.isEmpty()) break; // No groups available + Group group = groupInCluster.get(); boolean acceptIncompleteCoverage = (i == max - 1); - Optional invoker = invokerFactory.createSearchInvoker(searcher, query, OptionalInt.of(group.id()), group.nodes(), - acceptIncompleteCoverage); + Optional invoker = invokerFactory.createSearchInvoker(searcher, + query, + OptionalInt.of(group.id()), + group.nodes(), + acceptIncompleteCoverage); if (invoker.isPresent()) { query.trace(false, 2, "Dispatching internally to search group ", group.id()); query.getModel().setSearchPath("/" + group.id()); 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 5ed58a74627..f06aab09a3d 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 @@ -34,6 +34,7 @@ import static com.yahoo.text.Lowercase.toLowerCase; * @author bratseth */ public class Model implements Cloneable { + /** The type representing the property arguments consumed by this */ private static final QueryProfileType argumentType; private static final CompoundName argumentTypeName; @@ -67,7 +68,7 @@ public class Model implements Cloneable { argumentType.addField(new FieldDescription(SEARCH_PATH, "string", "searchpath")); argumentType.addField(new FieldDescription(RESTRICT, "string", "restrict")); argumentType.freeze(); - argumentTypeName=new CompoundName(argumentType.getId().getName()); + argumentTypeName = new CompoundName(argumentType.getId().getName()); } public static QueryProfileType getArgumentType() { return argumentType; } diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java index e8d8ecb02bb..2f4804f0c48 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java @@ -41,7 +41,7 @@ public class FieldDescription implements Comparable { } public FieldDescription(String name, String type, String aliases) { - this(name,type,aliases,false,true); + this(name, type, aliases, false, true); } public FieldDescription(String name, FieldType type, String aliases) { -- cgit v1.2.3