From f82fe83ea8cdab7e190e917b9391b5f0c36a3351 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 23 Nov 2022 12:04:55 +0100 Subject: No need to require the full SearchCluster when you only need a list of Groups. --- .../src/main/java/com/yahoo/search/dispatch/Dispatcher.java | 9 ++++----- .../src/main/java/com/yahoo/search/dispatch/LoadBalancer.java | 7 +++---- 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'container-search/src/main/java/com') 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 55073f25f0e..3a198c3576a 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 @@ -52,10 +52,9 @@ public class Dispatcher extends AbstractComponent { /** If set will control computation of how many hits will be fetched from each partition.*/ public static final CompoundName topKProbability = CompoundName.fromComponents(DISPATCH, TOP_K_PROBABILITY); - /** A model of the search cluster this dispatches to */ - private final SearchCluster searchCluster; private final ClusterMonitor clusterMonitor; private final LoadBalancer loadBalancer; + private final SearchCluster searchCluster; private final InvokerFactory invokerFactory; private final int maxHitsPerNode; private final RpcResourcePool rpcResourcePool; @@ -114,7 +113,7 @@ public class Dispatcher extends AbstractComponent { this.searchCluster = searchCluster; this.clusterMonitor = clusterMonitor; - this.loadBalancer = new LoadBalancer(searchCluster, toLoadBalancerPolicy(dispatchConfig.distributionPolicy())); + this.loadBalancer = new LoadBalancer(searchCluster.orderedGroups(), toLoadBalancerPolicy(dispatchConfig.distributionPolicy())); this.invokerFactory = invokerFactory; this.rpcResourcePool = rpcResourcePool; this.maxHitsPerNode = dispatchConfig.maxHitsPerNode(); @@ -172,7 +171,7 @@ public class Dispatcher extends AbstractComponent { public SearchInvoker getSearchInvoker(Query query, VespaBackEndSearcher searcher) { SearchCluster cluster = searchCluster; // Take a snapshot - SearchInvoker invoker = getSearchPathInvoker(query, searcher, cluster).orElseGet(() -> getInternalInvoker(query, searcher, cluster)); + SearchInvoker invoker = getSearchPathInvoker(query, searcher, cluster).orElseGet(() -> getInternalInvoker(query, searcher, cluster, loadBalancer)); if (query.properties().getBoolean(com.yahoo.search.query.Model.ESTIMATE)) { query.setHits(0); @@ -201,7 +200,7 @@ public class Dispatcher extends AbstractComponent { } } - private SearchInvoker getInternalInvoker(Query query, VespaBackEndSearcher searcher, SearchCluster cluster) { + private SearchInvoker getInternalInvoker(Query query, VespaBackEndSearcher searcher, SearchCluster cluster, LoadBalancer loadBalancer) { Optional directNode = cluster.localCorpusDispatchTarget(); if (directNode.isPresent()) { Node node = directNode.get(); diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/LoadBalancer.java b/container-search/src/main/java/com/yahoo/search/dispatch/LoadBalancer.java index 59821827d4e..52cc6ad7711 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/LoadBalancer.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/LoadBalancer.java @@ -2,7 +2,6 @@ package com.yahoo.search.dispatch; import com.yahoo.search.dispatch.searchcluster.Group; -import com.yahoo.search.dispatch.searchcluster.SearchCluster; import java.time.Duration; import java.util.ArrayList; @@ -34,9 +33,9 @@ public class LoadBalancer { public enum Policy { ROUNDROBIN, LATENCY_AMORTIZED_OVER_REQUESTS, LATENCY_AMORTIZED_OVER_TIME, BEST_OF_RANDOM_2} - public LoadBalancer(SearchCluster searchCluster, Policy policy) { - this.scoreboard = new ArrayList<>(searchCluster.groups().size()); - for (Group group : searchCluster.orderedGroups()) { + public LoadBalancer(List groups, Policy policy) { + this.scoreboard = new ArrayList<>(groups.size()); + for (Group group : groups) { scoreboard.add(new GroupStatus(group)); } if (scoreboard.size() == 1) -- cgit v1.2.3