diff options
author | Olli Virtanen <olli.virtanen@oath.com> | 2019-05-28 14:29:29 +0200 |
---|---|---|
committer | Olli Virtanen <olli.virtanen@oath.com> | 2019-05-28 14:29:29 +0200 |
commit | 61ef8a814998a1ea0b98ecfc1ef7e830f9d1776c (patch) | |
tree | 2e540320e29b9566b07ea68605fad9ce895028ab /container-search | |
parent | df0d8f4a1a42cb0d6fa45cf059b0d63f915f2230 (diff) |
Java dispatcher only uses RPC/protobuf
Diffstat (limited to 'container-search')
12 files changed, 112 insertions, 187 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java b/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java index e850312158c..3f45e8e8f00 100644 --- a/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java @@ -106,7 +106,7 @@ public class ClusterSearcher extends Searcher { super(id); this.fs4ResourcePool = fs4ResourcePool; - Dispatcher dispatcher = new Dispatcher(id.stringValue(), dispatchConfig, fs4ResourcePool, clusterInfoConfig.nodeCount(), vipStatus, metric); + Dispatcher dispatcher = Dispatcher.create(id.stringValue(), dispatchConfig, fs4ResourcePool, clusterInfoConfig.nodeCount(), vipStatus, metric); monitor = (dispatcher.searchCluster().directDispatchTarget().isPresent()) // dispatcher should decide vip status instead ? new ClusterMonitor(this, monitorConfig, Optional.empty()) diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4InvokerFactory.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4InvokerFactory.java deleted file mode 100644 index b9af60089f8..00000000000 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4InvokerFactory.java +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.prelude.fastsearch; - -import com.google.common.collect.ImmutableMap; -import com.yahoo.fs4.mplex.Backend; -import com.yahoo.prelude.Pong; -import com.yahoo.search.Query; -import com.yahoo.search.Result; -import com.yahoo.search.cluster.ClusterMonitor; -import com.yahoo.search.dispatch.FillInvoker; -import com.yahoo.search.dispatch.InterleavedFillInvoker; -import com.yahoo.search.dispatch.InvokerFactory; -import com.yahoo.search.dispatch.SearchInvoker; -import com.yahoo.search.dispatch.searchcluster.Node; -import com.yahoo.search.dispatch.searchcluster.Pinger; -import com.yahoo.search.dispatch.searchcluster.SearchCluster; -import com.yahoo.search.result.Hit; - -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.Callable; - -/** - * FS4InvokerFactory constructs {@link FillInvoker} and {@link SearchInvoker} objects that communicate with - * content nodes or dispatchers over the fnet/FS4 protocol - * - * @author ollivir - */ -public class FS4InvokerFactory extends InvokerFactory { - private final FS4ResourcePool fs4ResourcePool; - private final ImmutableMap<Integer, Node> nodesByKey; - - public FS4InvokerFactory(FS4ResourcePool fs4ResourcePool, SearchCluster searchCluster) { - super(searchCluster); - this.fs4ResourcePool = fs4ResourcePool; - - ImmutableMap.Builder<Integer, Node> builder = ImmutableMap.builder(); - searchCluster.groups().values().forEach(group -> group.nodes().forEach(node -> builder.put(node.key(), node))); - this.nodesByKey = builder.build(); - } - - public SearchInvoker createDirectSearchInvoker(VespaBackEndSearcher searcher, Query query, Node node) { - Backend backend = fs4ResourcePool.getBackend(node.hostname(), node.fs4port()); - return new FS4SearchInvoker(searcher, query, backend.openChannel(), Optional.of(node)); - } - - @Override - protected Optional<SearchInvoker> createNodeSearchInvoker(VespaBackEndSearcher searcher, Query query, Node node) { - Backend backend = fs4ResourcePool.getBackend(node.hostname(), node.fs4port()); - if (backend.probeConnection()) { - return Optional.of(new FS4SearchInvoker(searcher, query, backend.openChannel(), Optional.of(node))); - } else { - return Optional.empty(); - } - } - - public FillInvoker createFillInvoker(VespaBackEndSearcher searcher, Result result, Node node) { - return new FS4FillInvoker(searcher, result.getQuery(), fs4ResourcePool, node.hostname(), node.fs4port()); - } - - /** - * Create a {@link FillInvoker} for a the hits in a {@link Result}. - * - * @param searcher the searcher processing the query - * @param result the Result containing hits that need to be filled - * @return Optional containing the FillInvoker or <i>empty</i> if some hit is from an unknown content node - */ - public Optional<FillInvoker> createFillInvoker(VespaBackEndSearcher searcher, Result result) { - Collection<Integer> requiredNodes = requiredFillNodes(result); - - Map<Integer, FillInvoker> invokers = new HashMap<>(); - for (Integer distKey : requiredNodes) { - Node node = nodesByKey.get(distKey); - if (node == null) { - return Optional.empty(); - } - invokers.put(distKey, createFillInvoker(searcher, result, node)); - } - - if (invokers.size() == 1) { - return Optional.of(invokers.values().iterator().next()); - } else { - return Optional.of(new InterleavedFillInvoker(invokers)); - } - } - - private static Collection<Integer> requiredFillNodes(Result result) { - Set<Integer> requiredNodes = new HashSet<>(); - for (Iterator<Hit> i = result.hits().unorderedDeepIterator(); i.hasNext();) { - Hit h = i.next(); - if (h instanceof FastHit) { - FastHit hit = (FastHit) h; - requiredNodes.add(hit.getDistributionKey()); - } - } - return requiredNodes; - } - - @Override - public Callable<Pong> createPinger(Node node, ClusterMonitor<Node> monitor) { - return new Pinger(node, monitor, fs4ResourcePool); - } -} diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4PingFactory.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4PingFactory.java new file mode 100644 index 00000000000..2abaf341c58 --- /dev/null +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4PingFactory.java @@ -0,0 +1,29 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.prelude.fastsearch; + +import com.yahoo.prelude.Pong; +import com.yahoo.search.cluster.ClusterMonitor; +import com.yahoo.search.dispatch.searchcluster.Node; +import com.yahoo.search.dispatch.searchcluster.PingFactory; +import com.yahoo.search.dispatch.searchcluster.Pinger; + +import java.util.concurrent.Callable; + +/** + * FS4PingFactory constructs {@link Pinger} objects that communicate with + * content nodes or dispatchers over the fnet/FS4 protocol + * + * @author ollivir + */ +public class FS4PingFactory implements PingFactory { + private final FS4ResourcePool fs4ResourcePool; + + public FS4PingFactory(FS4ResourcePool fs4ResourcePool) { + this.fs4ResourcePool = fs4ResourcePool; + } + + @Override + public Callable<Pong> createPinger(Node node, ClusterMonitor<Node> monitor) { + return new Pinger(node, monitor, fs4ResourcePool); + } +} diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastSearcher.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastSearcher.java index 5f6d4220dd4..0c8ebd70b5e 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastSearcher.java @@ -5,7 +5,6 @@ import com.yahoo.fs4.BasicPacket; import com.yahoo.fs4.ChannelTimeoutException; import com.yahoo.fs4.PingPacket; import com.yahoo.fs4.PongPacket; -import com.yahoo.fs4.QueryPacket; import com.yahoo.fs4.mplex.Backend; import com.yahoo.fs4.mplex.FS4Channel; import com.yahoo.fs4.mplex.InvalidChannelException; @@ -53,6 +52,7 @@ public class FastSearcher extends VespaBackEndSearcher { private final Dispatcher dispatcher; private final Backend dispatchBackend; + private final FS4ResourcePool fs4ResourcePool; /** * Creates a Fastsearcher. @@ -75,6 +75,7 @@ public class FastSearcher extends VespaBackEndSearcher { init(fs4ResourcePool.getServerId(), docSumParams, clusterParams, documentdbInfoConfig); this.dispatchBackend = dispatchBackend; this.dispatcher = dispatcher; + this.fs4ResourcePool = fs4ResourcePool; } /** @@ -213,7 +214,9 @@ public class FastSearcher extends VespaBackEndSearcher { Optional<Node> direct = getDirectNode(query); if(direct.isPresent()) { - return dispatcher.getFS4InvokerFactory().createDirectSearchInvoker(this, query, direct.get()); + var node = direct.get(); + Backend backend = fs4ResourcePool.getBackend(node.hostname(), node.fs4port()); + return new FS4SearchInvoker(this, query, backend.openChannel(), direct); } return new FS4SearchInvoker(this, query, dispatchBackend.openChannel(), Optional.empty()); } @@ -232,7 +235,9 @@ public class FastSearcher extends VespaBackEndSearcher { Optional<Node> direct = getDirectNode(query); if (direct.isPresent()) { - return dispatcher.getFS4InvokerFactory().createFillInvoker(this, result, direct.get()); + var node = direct.get(); + Backend backend = fs4ResourcePool.getBackend(node.hostname(), node.fs4port()); + return new FS4FillInvoker(this, query, backend); } return new FS4FillInvoker(this, query, dispatchBackend); } 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 4f546201e76..6a51958d6de 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 @@ -4,7 +4,7 @@ package com.yahoo.search.dispatch; import com.yahoo.component.AbstractComponent; import com.yahoo.container.handler.VipStatus; import com.yahoo.jdisc.Metric; -import com.yahoo.prelude.fastsearch.FS4InvokerFactory; +import com.yahoo.prelude.fastsearch.FS4PingFactory; import com.yahoo.prelude.fastsearch.FS4ResourcePool; import com.yahoo.prelude.fastsearch.VespaBackEndSearcher; import com.yahoo.processing.request.CompoundName; @@ -15,6 +15,7 @@ import com.yahoo.search.dispatch.rpc.RpcInvokerFactory; import com.yahoo.search.dispatch.rpc.RpcResourcePool; 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.result.ErrorMessage; import com.yahoo.vespa.config.search.DispatchConfig; @@ -56,40 +57,33 @@ public class Dispatcher extends AbstractComponent { private final LoadBalancer loadBalancer; private final boolean multilevelDispatch; private final boolean internalDispatchByDefault; - private final boolean dispatchWithProtobuf; - private final FS4InvokerFactory fs4InvokerFactory; - private final RpcInvokerFactory rpcInvokerFactory; + private final InvokerFactory invokerFactory; private final Metric metric; private final Metric.Context metricContext; - public Dispatcher(String clusterId, DispatchConfig dispatchConfig, FS4ResourcePool fs4ResourcePool, int containerClusterSize, + public static Dispatcher create(String clusterId, DispatchConfig dispatchConfig, FS4ResourcePool fs4ResourcePool, int containerClusterSize, VipStatus vipStatus, Metric metric) { - this(new SearchCluster(clusterId, dispatchConfig, containerClusterSize, vipStatus), dispatchConfig, fs4ResourcePool, 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; - public Dispatcher(SearchCluster searchCluster, DispatchConfig dispatchConfig, FS4ResourcePool fs4ResourcePool, Metric metric) { - this(searchCluster, dispatchConfig, new FS4InvokerFactory(fs4ResourcePool, searchCluster), - new RpcInvokerFactory(new RpcResourcePool(dispatchConfig), searchCluster, dispatchConfig.dispatchWithProtobuf()), metric); + return new Dispatcher(searchCluster, dispatchConfig, rpcFactory, pingFactory, metric); } - public Dispatcher(SearchCluster searchCluster, DispatchConfig dispatchConfig, FS4InvokerFactory fs4InvokerFactory, - RpcInvokerFactory rpcInvokerFactory, 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); this.multilevelDispatch = dispatchConfig.useMultilevelDispatch(); this.internalDispatchByDefault = !dispatchConfig.useFdispatchByDefault(); - this.dispatchWithProtobuf = dispatchConfig.dispatchWithProtobuf(); - - this.fs4InvokerFactory = fs4InvokerFactory; - this.rpcInvokerFactory = rpcInvokerFactory; - + this.invokerFactory = invokerFactory; this.metric = metric; this.metricContext = metric.createContext(null); - searchCluster.startClusterMonitoring(dispatchWithProtobuf ? rpcInvokerFactory : fs4InvokerFactory); + searchCluster.startClusterMonitoring(pingFactory); } /** Returns the search cluster this dispatches to */ @@ -99,19 +93,13 @@ public class Dispatcher extends AbstractComponent { @Override public void deconstruct() { - rpcInvokerFactory.release(); + invokerFactory.release(); } public Optional<FillInvoker> getFillInvoker(Result result, VespaBackEndSearcher searcher) { - Optional<FillInvoker> rpcInvoker = rpcInvokerFactory.createFillInvoker(searcher, result); - if (rpcInvoker.isPresent()) { - return rpcInvoker; - } - if (result.getQuery().properties().getBoolean(dispatchInternal, internalDispatchByDefault)) { - Optional<FillInvoker> fs4Invoker = fs4InvokerFactory.createFillInvoker(searcher, result); - if (fs4Invoker.isPresent()) { - return fs4Invoker; - } + Optional<FillInvoker> invoker = invokerFactory.createFillInvoker(searcher, result); + if (invoker.isPresent()) { + return invoker; } return Optional.empty(); } @@ -122,13 +110,10 @@ public class Dispatcher extends AbstractComponent { return Optional.empty(); } - InvokerFactory factory = query.properties().getBoolean(dispatchProtobuf, dispatchWithProtobuf) - ? rpcInvokerFactory : fs4InvokerFactory; - - Optional<SearchInvoker> invoker = getSearchPathInvoker(query, factory, searcher); + Optional<SearchInvoker> invoker = getSearchPathInvoker(query, searcher); if (!invoker.isPresent()) { - invoker = getInternalInvoker(query, factory, searcher); + invoker = getInternalInvoker(query, searcher); } if (invoker.isPresent() && query.properties().getBoolean(com.yahoo.search.query.Model.ESTIMATE)) { query.setHits(0); @@ -140,12 +125,8 @@ public class Dispatcher extends AbstractComponent { return invoker; } - public FS4InvokerFactory getFS4InvokerFactory() { - return fs4InvokerFactory; - } - // build invoker based on searchpath - private Optional<SearchInvoker> getSearchPathInvoker(Query query, InvokerFactory invokerFactory, VespaBackEndSearcher searcher) { + private Optional<SearchInvoker> getSearchPathInvoker(Query query, VespaBackEndSearcher searcher) { String searchPath = query.getModel().getSearchPath(); if (searchPath == null) { return Optional.empty(); @@ -163,7 +144,7 @@ public class Dispatcher extends AbstractComponent { } } - private Optional<SearchInvoker> getInternalInvoker(Query query, InvokerFactory invokerFactory, VespaBackEndSearcher searcher) { + private Optional<SearchInvoker> getInternalInvoker(Query query, VespaBackEndSearcher searcher) { Optional<Node> directNode = searchCluster.directDispatchTarget(); if (directNode.isPresent()) { Node node = directNode.get(); diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/InvokerFactory.java b/container-search/src/main/java/com/yahoo/search/dispatch/InvokerFactory.java index 0ce1b74c02d..31af74a39b2 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/InvokerFactory.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/InvokerFactory.java @@ -1,11 +1,9 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.dispatch; -import com.yahoo.prelude.Pong; import com.yahoo.prelude.fastsearch.VespaBackEndSearcher; import com.yahoo.search.Query; import com.yahoo.search.Result; -import com.yahoo.search.cluster.ClusterMonitor; import com.yahoo.search.dispatch.searchcluster.Node; import com.yahoo.search.dispatch.searchcluster.SearchCluster; import com.yahoo.search.result.Coverage; @@ -17,7 +15,6 @@ import java.util.List; import java.util.Optional; import java.util.OptionalInt; import java.util.Set; -import java.util.concurrent.Callable; /** * @author ollivir @@ -33,8 +30,6 @@ public abstract class InvokerFactory { public abstract Optional<FillInvoker> createFillInvoker(VespaBackEndSearcher searcher, Result result); - public abstract Callable<Pong> createPinger(Node node, ClusterMonitor<Node> monitor); - /** * Create a {@link SearchInvoker} for a list of content nodes. * @@ -113,4 +108,6 @@ public abstract class InvokerFactory { coverage.setNodesTried(count); return new SearchErrorInvoker(ErrorMessage.createBackendCommunicationError(down.toString()), coverage); } + + public void release() {} } diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcInvokerFactory.java b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcInvokerFactory.java index b0a418241f8..0cd646914a1 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcInvokerFactory.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcInvokerFactory.java @@ -13,6 +13,7 @@ import com.yahoo.search.dispatch.FillInvoker; import com.yahoo.search.dispatch.InvokerFactory; import com.yahoo.search.dispatch.SearchInvoker; import com.yahoo.search.dispatch.searchcluster.Node; +import com.yahoo.search.dispatch.searchcluster.PingFactory; import com.yahoo.search.dispatch.searchcluster.SearchCluster; import java.util.Optional; @@ -21,7 +22,7 @@ import java.util.concurrent.Callable; /** * @author ollivir */ -public class RpcInvokerFactory extends InvokerFactory { +public class RpcInvokerFactory extends InvokerFactory implements PingFactory { /** Unless turned off this will fill summaries by dispatching directly to search nodes over RPC when possible */ private final static CompoundName dispatchSummaries = new CompoundName("dispatch.summaries"); diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/PingFactory.java b/container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/PingFactory.java new file mode 100644 index 00000000000..634e1e3e97d --- /dev/null +++ b/container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/PingFactory.java @@ -0,0 +1,11 @@ +package com.yahoo.search.dispatch.searchcluster; + +import com.yahoo.prelude.Pong; +import com.yahoo.search.cluster.ClusterMonitor; + +import java.util.concurrent.Callable; + +public interface PingFactory { + public abstract Callable<Pong> createPinger(Node node, ClusterMonitor<Node> monitor); + +} diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/SearchCluster.java b/container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/SearchCluster.java index 603932d56f9..3657e0b5c76 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/SearchCluster.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/SearchCluster.java @@ -10,7 +10,6 @@ import com.yahoo.net.HostName; import com.yahoo.prelude.Pong; import com.yahoo.search.cluster.ClusterMonitor; import com.yahoo.search.cluster.NodeManager; -import com.yahoo.search.dispatch.InvokerFactory; import com.yahoo.search.result.ErrorMessage; import com.yahoo.vespa.config.search.DispatchConfig; @@ -46,7 +45,7 @@ public class SearchCluster implements NodeManager<Node> { private final ImmutableList<Group> orderedGroups; private final ClusterMonitor<Node> clusterMonitor; private final VipStatus vipStatus; - private InvokerFactory pingFactory; + private PingFactory pingFactory; /** * A search node on this local machine having the entire corpus, which we therefore @@ -89,7 +88,7 @@ public class SearchCluster implements NodeManager<Node> { this.clusterMonitor = new ClusterMonitor<>(this); } - public void startClusterMonitoring(InvokerFactory pingFactory) { + public void startClusterMonitoring(PingFactory pingFactory) { this.pingFactory = pingFactory; for (var group : orderedGroups) { diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/MockDispatcher.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/MockDispatcher.java index e78fd920adc..92ccd7e46b2 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/MockDispatcher.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/MockDispatcher.java @@ -2,9 +2,8 @@ package com.yahoo.prelude.fastsearch.test; import com.yahoo.container.handler.VipStatus; -import com.yahoo.prelude.fastsearch.FS4InvokerFactory; +import com.yahoo.prelude.fastsearch.FS4PingFactory; import com.yahoo.prelude.fastsearch.FS4ResourcePool; -import com.yahoo.search.Result; import com.yahoo.search.dispatch.Dispatcher; import com.yahoo.search.dispatch.rpc.RpcInvokerFactory; import com.yahoo.search.dispatch.rpc.RpcResourcePool; @@ -31,8 +30,8 @@ class MockDispatcher extends Dispatcher { private MockDispatcher(SearchCluster searchCluster, DispatchConfig dispatchConfig, FS4ResourcePool fs4ResourcePool, RpcResourcePool rpcResourcePool) { - super(searchCluster, dispatchConfig, new FS4InvokerFactory(fs4ResourcePool, searchCluster), - new RpcInvokerFactory(rpcResourcePool, searchCluster, dispatchConfig.dispatchWithProtobuf()), new MockMetric()); + super(searchCluster, dispatchConfig, new RpcInvokerFactory(rpcResourcePool, searchCluster, !dispatchConfig.useFdispatchByDefault()), + new FS4PingFactory(fs4ResourcePool), new MockMetric()); } private static DispatchConfig toDispatchConfig(List<Node> nodes) { @@ -49,8 +48,4 @@ class MockDispatcher extends Dispatcher { } return new DispatchConfig(dispatchConfigBuilder); } - - public void fill(Result result, String summaryClass) { - } - } diff --git a/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java b/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java index a35cbdf289e..84c10991293 100644 --- a/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java @@ -196,6 +196,7 @@ public class ClusteredConnectionTestCase { public SimpleQuery(int hashValue) { this.hashValue = hashValue; + this.setTimeout(50); } @Override diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/DispatcherTest.java b/container-search/src/test/java/com/yahoo/search/dispatch/DispatcherTest.java index 25aed879a48..03a417c9bbb 100644 --- a/container-search/src/test/java/com/yahoo/search/dispatch/DispatcherTest.java +++ b/container-search/src/test/java/com/yahoo/search/dispatch/DispatcherTest.java @@ -1,13 +1,15 @@ // Copyright 2019 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.dispatch; -import com.yahoo.prelude.fastsearch.FS4InvokerFactory; +import com.yahoo.prelude.Pong; import com.yahoo.prelude.fastsearch.VespaBackEndSearcher; import com.yahoo.prelude.fastsearch.test.MockMetric; import com.yahoo.processing.request.CompoundName; import com.yahoo.search.Query; -import com.yahoo.search.dispatch.rpc.RpcInvokerFactory; +import com.yahoo.search.Result; +import com.yahoo.search.cluster.ClusterMonitor; import com.yahoo.search.dispatch.searchcluster.Node; +import com.yahoo.search.dispatch.searchcluster.PingFactory; import com.yahoo.search.dispatch.searchcluster.SearchCluster; import com.yahoo.vespa.config.search.DispatchConfig; import org.junit.Test; @@ -15,10 +17,12 @@ import org.junit.Test; import java.util.List; import java.util.Optional; import java.util.OptionalInt; +import java.util.concurrent.Callable; import static com.yahoo.search.dispatch.MockSearchCluster.createDispatchConfig; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; /** * @author ollivir @@ -39,7 +43,9 @@ public class DispatcherTest { builder.useMultilevelDispatch(true); DispatchConfig dc = new DispatchConfig(builder); - Dispatcher disp = new Dispatcher(cl, dc, new MockFS4InvokerFactory(cl), new MockRpcInvokerFactory(), new MockMetric()); + var invokerFactory = new MockInvokerFactory(cl); + + Dispatcher disp = new Dispatcher(cl, dc, invokerFactory, invokerFactory, new MockMetric()); assertThat(disp.getSearchInvoker(query(), null).isPresent(), is(false)); } @@ -48,12 +54,12 @@ public class DispatcherTest { SearchCluster cl = new MockSearchCluster("1", 2, 2); Query q = query(); q.getModel().setSearchPath("1/0"); // second node in first group - MockFS4InvokerFactory invokerFactory = new MockFS4InvokerFactory(cl, (nodes, a) -> { + MockInvokerFactory invokerFactory = new MockInvokerFactory(cl, (nodes, a) -> { assertThat(nodes.size(), is(1)); assertThat(nodes.get(0).key(), is(2)); return true; }); - Dispatcher disp = new Dispatcher(cl, createDispatchConfig(), invokerFactory, new MockRpcInvokerFactory(), new MockMetric()); + Dispatcher disp = new Dispatcher(cl, createDispatchConfig(), invokerFactory, invokerFactory, new MockMetric()); Optional<SearchInvoker> invoker = disp.getSearchInvoker(q, null); assertThat(invoker.isPresent(), is(true)); invokerFactory.verifyAllEventsProcessed(); @@ -67,8 +73,8 @@ public class DispatcherTest { return Optional.of(new Node(1, "test", 123, 1)); } }; - MockFS4InvokerFactory invokerFactory = new MockFS4InvokerFactory(cl, (n, a) -> true); - Dispatcher disp = new Dispatcher(cl, createDispatchConfig(), invokerFactory, new MockRpcInvokerFactory(), new MockMetric()); + MockInvokerFactory invokerFactory = new MockInvokerFactory(cl, (n, a) -> true); + Dispatcher disp = new Dispatcher(cl, createDispatchConfig(), invokerFactory, invokerFactory, new MockMetric()); Optional<SearchInvoker> invoker = disp.getSearchInvoker(query(), null); assertThat(invoker.isPresent(), is(true)); invokerFactory.verifyAllEventsProcessed(); @@ -78,14 +84,14 @@ public class DispatcherTest { public void requireThatInvokerConstructionIsRetriedAndLastAcceptsAnyCoverage() { SearchCluster cl = new MockSearchCluster("1", 2, 1); - MockFS4InvokerFactory invokerFactory = new MockFS4InvokerFactory(cl, (n, acceptIncompleteCoverage) -> { + MockInvokerFactory invokerFactory = new MockInvokerFactory(cl, (n, acceptIncompleteCoverage) -> { assertThat(acceptIncompleteCoverage, is(false)); return false; }, (n, acceptIncompleteCoverage) -> { assertThat(acceptIncompleteCoverage, is(true)); return true; }); - Dispatcher disp = new Dispatcher(cl, createDispatchConfig(), invokerFactory, new MockRpcInvokerFactory(), new MockMetric()); + Dispatcher disp = new Dispatcher(cl, createDispatchConfig(), invokerFactory, invokerFactory, new MockMetric()); Optional<SearchInvoker> invoker = disp.getSearchInvoker(query(), null); assertThat(invoker.isPresent(), is(true)); invokerFactory.verifyAllEventsProcessed(); @@ -95,8 +101,8 @@ public class DispatcherTest { public void requireThatInvokerConstructionDoesNotRepeatGroups() { SearchCluster cl = new MockSearchCluster("1", 2, 1); - MockFS4InvokerFactory invokerFactory = new MockFS4InvokerFactory(cl, (n, a) -> false, (n, a) -> false); - Dispatcher disp = new Dispatcher(cl, createDispatchConfig(), invokerFactory, null, new MockMetric()); + MockInvokerFactory invokerFactory = new MockInvokerFactory(cl, (n, a) -> false, (n, a) -> false); + Dispatcher disp = new Dispatcher(cl, createDispatchConfig(), invokerFactory, invokerFactory, new MockMetric()); Optional<SearchInvoker> invoker = disp.getSearchInvoker(query(), null); assertThat(invoker.isPresent(), is(false)); invokerFactory.verifyAllEventsProcessed(); @@ -106,12 +112,12 @@ public class DispatcherTest { public boolean returnInvoker(List<Node> nodes, boolean acceptIncompleteCoverage); } - private static class MockFS4InvokerFactory extends FS4InvokerFactory { + private static class MockInvokerFactory extends InvokerFactory implements PingFactory { private final FactoryStep[] events; private int step = 0; - public MockFS4InvokerFactory(SearchCluster cl, FactoryStep... events) { - super(null, cl); + public MockInvokerFactory(SearchCluster cl, FactoryStep... events) { + super(cl); this.events = events; } @@ -133,15 +139,23 @@ public class DispatcherTest { void verifyAllEventsProcessed() { assertThat(step, is(events.length)); } - } - public class MockRpcInvokerFactory extends RpcInvokerFactory { - public MockRpcInvokerFactory() { - super(null, null, true); + @Override + protected Optional<SearchInvoker> createNodeSearchInvoker(VespaBackEndSearcher searcher, Query query, Node node) { + fail("Unexpected call to createNodeSearchInvoker"); + return null; + } + + @Override + public Optional<FillInvoker> createFillInvoker(VespaBackEndSearcher searcher, Result result) { + fail("Unexpected call to createFillInvoker"); + return null; } @Override - public void release() { + public Callable<Pong> createPinger(Node node, ClusterMonitor<Node> monitor) { + fail("Unexpected call to createPinger"); + return null; } } } |