summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-10-06 09:28:43 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-10-06 09:28:43 +0200
commitdbb226c2bdff11e8e299df60a46a2017d4a3dce0 (patch)
treef0e1638021ee704573d809199fee6c962e5a2328 /container-search/src/main/java/com/yahoo
parent95f131db13acc76df96c07f47baace6842d767af (diff)
Message VIP handler from SearchCluster
Diffstat (limited to 'container-search/src/main/java/com/yahoo')
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java2
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/fastsearch/FastSearcher.java3
-rw-r--r--container-search/src/main/java/com/yahoo/search/dispatch/Dispatcher.java6
-rw-r--r--container-search/src/main/java/com/yahoo/search/dispatch/SearchCluster.java43
4 files changed, 41 insertions, 13 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 25031f7376f..3e0f922959a 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
@@ -113,7 +113,7 @@ public class ClusterSearcher extends Searcher {
QrSearchersConfig.Searchcluster searchClusterConfig = getSearchClusterConfigFromClusterName(qrsConfig, clusterModelName);
documentTypes = new LinkedHashSet<>();
failoverToRemote = clusterConfig.failoverToRemote();
- Dispatcher dispatcher = new Dispatcher(dispatchConfig, fs4ResourcePool, clusterInfoConfig.nodeCount());
+ Dispatcher dispatcher = new Dispatcher(dispatchConfig, fs4ResourcePool, clusterInfoConfig.nodeCount(), vipStatus);
String eventName = clusterModelName + ".cache_hit_ratio";
cacheHitRatio = new Value(eventName, manager, new Value.Parameters().setNameExtension(false)
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 e9624f0cbdf..504c5dd363a 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
@@ -3,7 +3,6 @@ package com.yahoo.prelude.fastsearch;
import java.util.Optional;
-import com.google.common.collect.ImmutableCollection;
import com.yahoo.compress.CompressionType;
import com.yahoo.fs4.BasicPacket;
import com.yahoo.fs4.ChannelTimeoutException;
@@ -227,7 +226,7 @@ public class FastSearcher extends VespaBackEndSearcher {
// as that probably means that we are in a failover situation
if ( ! dispatchBackend.getHost().equals(selfHostname)) return dispatchBackend;
- Optional<SearchCluster.Node> directDispatchRecipient = dispatcher.searchCluster().dispatchDirectlyFrom(selfHostname);
+ Optional<SearchCluster.Node> directDispatchRecipient = dispatcher.searchCluster().directDispatchTarget();
if ( ! directDispatchRecipient.isPresent()) return dispatchBackend;
query.trace(false, 2, "Dispatching directly to ", directDispatchRecipient.get());
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 6245a0ee442..ef81d404b29 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
@@ -7,6 +7,7 @@ import com.yahoo.collections.ListMap;
import com.yahoo.component.AbstractComponent;
import com.yahoo.compress.CompressionType;
import com.yahoo.compress.Compressor;
+import com.yahoo.container.handler.VipStatus;
import com.yahoo.data.access.slime.SlimeAdapter;
import com.yahoo.prelude.fastsearch.FS4ResourcePool;
import com.yahoo.prelude.fastsearch.FastHit;
@@ -50,9 +51,10 @@ public class Dispatcher extends AbstractComponent {
private final Compressor compressor = new Compressor();
- public Dispatcher(DispatchConfig dispatchConfig, FS4ResourcePool fs4ResourcePool, int containerClusterSize) {
+ public Dispatcher(DispatchConfig dispatchConfig, FS4ResourcePool fs4ResourcePool,
+ int containerClusterSize, VipStatus vipStatus) {
this.client = new RpcClient();
- this.searchCluster = new SearchCluster(dispatchConfig, fs4ResourcePool, containerClusterSize);
+ this.searchCluster = new SearchCluster(dispatchConfig, fs4ResourcePool, containerClusterSize, vipStatus);
// Create node rpc connections, indexed by the legacy "partid", which allows us to bridge
// between fs4 calls (for search) and rpc calls (for summary fetch)
diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/SearchCluster.java b/container-search/src/main/java/com/yahoo/search/dispatch/SearchCluster.java
index db987fde58c..83d16f58662 100644
--- a/container-search/src/main/java/com/yahoo/search/dispatch/SearchCluster.java
+++ b/container-search/src/main/java/com/yahoo/search/dispatch/SearchCluster.java
@@ -5,6 +5,8 @@ import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
+import com.yahoo.container.handler.VipStatus;
+import com.yahoo.net.HostName;
import com.yahoo.search.cluster.ClusterMonitor;
import com.yahoo.search.cluster.NodeManager;
import com.yahoo.search.result.ErrorMessage;
@@ -50,20 +52,27 @@ public class SearchCluster implements NodeManager<SearchCluster.Node> {
private final ImmutableMultimap<String, Node> nodesByHost;
private final ClusterMonitor<Node> clusterMonitor;
private final int containerClusterSize;
+ private final String selfHostname;
+ private final VipStatus vipStatus;
// Only needed until query requests are moved to rpc
private final FS4ResourcePool fs4ResourcePool;
- public SearchCluster(DispatchConfig dispatchConfig, FS4ResourcePool fs4ResourcePool, int containerClusterSize) {
- this(dispatchConfig.minActivedocsPercentage(), toNodes(dispatchConfig), fs4ResourcePool, containerClusterSize);
+ public SearchCluster(DispatchConfig dispatchConfig, FS4ResourcePool fs4ResourcePool,
+ int containerClusterSize, VipStatus vipStatus) {
+ this(dispatchConfig.minActivedocsPercentage(), toNodes(dispatchConfig), fs4ResourcePool,
+ containerClusterSize, vipStatus);
}
- public SearchCluster(double minActivedocsCoverage, List<Node> nodes, FS4ResourcePool fs4ResourcePool, int containerClusterSize) {
+ public SearchCluster(double minActivedocsCoverage, List<Node> nodes, FS4ResourcePool fs4ResourcePool,
+ int containerClusterSize, VipStatus vipStatus) {
this.minActivedocsCoveragePercentage = minActivedocsCoverage;
this.size = nodes.size();
this.fs4ResourcePool = fs4ResourcePool;
this.containerClusterSize = containerClusterSize;
-
+ this.selfHostname = HostName.getLocalhost();
+ this.vipStatus = vipStatus;
+
// Create groups
ImmutableMap.Builder<Integer, Group> groupsBuilder = new ImmutableMap.Builder<>();
for (Map.Entry<Integer, List<Node>> group : nodes.stream().collect(Collectors.groupingBy(Node::group)).entrySet())
@@ -102,8 +111,11 @@ public class SearchCluster implements NodeManager<SearchCluster.Node> {
*/
public ImmutableMultimap<String, Node> nodesByHost() { return nodesByHost; }
- /** Whether direct dispatch (bypassing fdispatch) should be used when dispatching queries from the given hostname */
- public Optional<Node> dispatchDirectlyFrom(String selfHostname) {
+ /**
+ * Returns the recipient we should dispatch queries directly to (bypassing fdispatch),
+ * or empty if we should not dispatch directly.
+ */
+ public Optional<Node> directDispatchTarget() {
// A search node in the search cluster in question is configured on the same host as the currently running container.
// It has all the data <==> No other nodes in the search cluster have the same group id as this node.
// That local search node responds.
@@ -135,11 +147,26 @@ public class SearchCluster implements NodeManager<SearchCluster.Node> {
/** Used by the cluster monitor to manage node status */
@Override
- public void working(Node node) { node.setWorking(true); }
+ public void working(Node node) {
+ node.setWorking(true);
+
+ if (usesDirectDispatchTo(node))
+ vipStatus.removeFromRotation(this);
+ }
/** Used by the cluster monitor to manage node status */
@Override
- public void failed(Node node) { node.setWorking(false); }
+ public void failed(Node node) {
+ node.setWorking(false);
+
+ // Take ourselves out if we usually dispatch only to our own host
+ if (usesDirectDispatchTo(node))
+ vipStatus.removeFromRotation(this);
+ }
+
+ private boolean usesDirectDispatchTo(Node node) {
+ return directDispatchTarget().map((Node target) -> target.equals(node)).orElse(false);
+ }
/** Used by the cluster monitor to manage node status */
@Override