summaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@verizonmedia.com>2020-01-20 10:37:07 +0100
committerJon Bratseth <bratseth@verizonmedia.com>2020-01-20 10:37:07 +0100
commit19c9987d9e5e38996b51ca5d11f152a9392ddc83 (patch)
tree2612490273ab8f20fe481fff3e2d5150896d9508 /container-search
parent8c772566c23fb22ad4e84d76127d6f1dab8b716f (diff)
Add isBlockingWrites to pong
- Add isBlockingWrites to pong - Cleanup and deprecate unused complexity: There is just one node and one error
Diffstat (limited to 'container-search')
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/Ping.java2
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/Pong.java94
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/query/NearItem.java15
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/query/ONearItem.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/cluster/ClusterSearcher.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcPing.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/dispatch/searchcluster/SearchCluster.java2
-rw-r--r--container-search/src/test/java/com/yahoo/search/cluster/test/ClusterSearcherTestCase.java9
-rw-r--r--container-search/src/test/java/com/yahoo/search/cluster/test/ClusteredConnectionTestCase.java8
9 files changed, 82 insertions, 54 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/Ping.java b/container-search/src/main/java/com/yahoo/prelude/Ping.java
index dd14e150d95..1d5d4c92827 100644
--- a/container-search/src/main/java/com/yahoo/prelude/Ping.java
+++ b/container-search/src/main/java/com/yahoo/prelude/Ping.java
@@ -4,7 +4,7 @@ package com.yahoo.prelude;
/**
* A ping, typically to ask whether backend is alive.
*
- * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
+ * @author Steinar Knutsen
*/
public class Ping {
diff --git a/container-search/src/main/java/com/yahoo/prelude/Pong.java b/container-search/src/main/java/com/yahoo/prelude/Pong.java
index a60fba9a4f7..ff08d5fb33b 100644
--- a/container-search/src/main/java/com/yahoo/prelude/Pong.java
+++ b/container-search/src/main/java/com/yahoo/prelude/Pong.java
@@ -4,82 +4,102 @@ package com.yahoo.prelude;
import com.yahoo.search.result.ErrorMessage;
import com.yahoo.search.statistics.ElapsedTime;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.Optional;
+import java.util.stream.Collectors;
/**
* An answer from Ping.
*
- * @author Steinar Knutsen
+ * @author bratseth
*/
public class Pong {
- private String pingInfo="";
- private final List<ErrorMessage> errors = new ArrayList<>(1);
- private ElapsedTime elapsed = new ElapsedTime();
+ private final ElapsedTime elapsed = new ElapsedTime();
private final Optional<Long> activeDocuments;
+ private final boolean isBlockingWrites;
+ private final Optional<ErrorMessage> error;
public Pong() {
- this.activeDocuments = Optional.empty();
+ this(Optional.empty(), false, Optional.empty());
}
public Pong(ErrorMessage error) {
- errors.add(error);
- this.activeDocuments = Optional.empty();
+ this(Optional.empty(), false, Optional.of(error));
}
public Pong(long activeDocuments) {
- this.activeDocuments = Optional.of(activeDocuments);
+ this(Optional.of(activeDocuments), false, Optional.empty());
}
- public void addError(ErrorMessage error) {
- errors.add(error);
+ public Pong(long activeDocuments, boolean isBlockingWrites) {
+ this(Optional.of(activeDocuments), isBlockingWrites, Optional.empty());
}
- public ErrorMessage getError(int i) {
- return errors.get(i);
+ private Pong(Optional<Long> activeDocuments, boolean isBlockingWrites, Optional<ErrorMessage> error) {
+ this.activeDocuments = activeDocuments;
+ this.isBlockingWrites = isBlockingWrites;
+ this.error = error;
}
- /** Returns the number of active documents in the backend responding in this Pong, if available */
- public Optional<Long> activeDocuments() {
- return activeDocuments;
+ /**
+ * @deprecated do not use. Additional errors are ignored.
+ */
+ @Deprecated
+ public void addError(ErrorMessage error) { }
+
+ /**
+ * @deprecated use error() instead
+ */
+ @Deprecated
+ public ErrorMessage getError(int i) {
+ if (i > 1) throw new IllegalArgumentException("No error at position " + i);
+ if (i == 0 && error.isEmpty()) throw new IllegalArgumentException("No error at position " + i);
+ return error.get();
}
- /** Returns the number of nodes which responded to this Pong, if available */
+ public Optional<ErrorMessage> error() { return error; }
+
+ /** Returns the number of active documents in the backend responding in this Pong, if available */
+ public Optional<Long> activeDocuments() { return activeDocuments; }
+
+ /** Returns true if the pinged node is currently blocking write operations due t being full */
+ public boolean isBlockingWrites() { return isBlockingWrites; }
+
+ /**
+ * Returns Optional.empty()
+ *
+ * @return empty
+ * @deprecated do not use. There is always one pong per node.
+ */
+ @Deprecated
public Optional<Integer> activeNodes() {
return Optional.empty();
}
+ /**
+ * Returns a list containing 0 or 1 errors
+ *
+ * @deprecated use error() instead
+ */
+ @Deprecated
public List<ErrorMessage> getErrors() {
- return Collections.unmodifiableList(errors);
+ return error.stream().collect(Collectors.toList());
}
/** Returns whether there is an error or not */
- public boolean badResponse() {
- return ! errors.isEmpty();
- }
+ public boolean badResponse() { return error.isPresent(); }
- public ElapsedTime getElapsedTime() {
- return elapsed;
- }
+ public ElapsedTime getElapsedTime() { return elapsed; }
/** Returns a string which included the ping info (if any) and any errors added to this */
@Override
public String toString() {
- StringBuilder m = new StringBuilder("Result of pinging");
- if (pingInfo.length() > 0) {
- m.append(" using ");
- m.append(pingInfo);
- }
- if (errors.size() > 0)
- m.append(" ");
- for (int i = 0; i < errors.size(); i++) {
- m.append(errors.get(i).toString());
- if ( i <errors.size()-1)
- m.append(", ");
- }
+ StringBuilder m = new StringBuilder("Ping result");
+ activeDocuments.ifPresent(docCount -> m.append(" active docs: ").append(docCount));
+ if (isBlockingWrites)
+ m.append(" blocking writes: true");
+ error.ifPresent(e -> m.append(" error: ").append(error));
return m.toString();
}
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/NearItem.java b/container-search/src/main/java/com/yahoo/prelude/query/NearItem.java
index 153606e6d99..69131b6c690 100644
--- a/container-search/src/main/java/com/yahoo/prelude/query/NearItem.java
+++ b/container-search/src/main/java/com/yahoo/prelude/query/NearItem.java
@@ -8,7 +8,7 @@ import java.nio.ByteBuffer;
/**
- * <p>A set of terms which must be near each other to match.</p>
+ * A set of terms which must be near each other to match.
*
* @author bratseth
* @author havardpe
@@ -18,7 +18,7 @@ public class NearItem extends CompositeItem {
protected int distance;
/** The default distance used if none is specified: 2 */
- public static final int defaultDistance=2;
+ public static final int defaultDistance = 2;
/** Creates a NEAR item with distance 2 */
public NearItem() {
@@ -26,8 +26,7 @@ public class NearItem extends CompositeItem {
}
/**
- * Creates a <i>near</i> item with a limit to the distance
- * between the words.
+ * Creates a <i>near</i> item with a limit to the distance between the words.
*
* @param distance the number of word position which may separate
* the words for this near item to match
@@ -47,14 +46,17 @@ public class NearItem extends CompositeItem {
return distance;
}
+ @Override
public ItemType getItemType() {
return ItemType.NEAR;
}
+ @Override
public String getName() {
return "NEAR";
}
+ @Override
protected void encodeThis(ByteBuffer buffer) {
super.encodeThis(buffer);
IntegerCompressor.putCompressedPositiveNumber(distance, buffer);
@@ -67,6 +69,7 @@ public class NearItem extends CompositeItem {
}
/** Appends the heading of this string - <code>[getName()]([limit]) </code> */
+ @Override
protected void appendHeadingString(StringBuilder buffer) {
buffer.append(getName());
buffer.append("(");
@@ -75,6 +78,7 @@ public class NearItem extends CompositeItem {
buffer.append(" ");
}
+ @Override
public int hashCode() {
return super.hashCode() + 23* distance;
}
@@ -83,10 +87,11 @@ public class NearItem extends CompositeItem {
* Returns whether this item is of the same class and
* contains the same state as the given item
*/
+ @Override
public boolean equals(Object object) {
if (!super.equals(object)) return false;
NearItem other = (NearItem) object; // Ensured by superclass
- if (this.distance !=other.distance) return false;
+ if (this.distance != other.distance) return false;
return true;
}
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/ONearItem.java b/container-search/src/main/java/com/yahoo/prelude/query/ONearItem.java
index 84e93d5de8f..88982195af6 100644
--- a/container-search/src/main/java/com/yahoo/prelude/query/ONearItem.java
+++ b/container-search/src/main/java/com/yahoo/prelude/query/ONearItem.java
@@ -25,10 +25,12 @@ public class ONearItem extends NearItem {
super(distance);
}
+ @Override
public ItemType getItemType() {
return ItemType.ONEAR;
}
+ @Override
public String getName() {
return "ONEAR";
}
diff --git a/container-search/src/main/java/com/yahoo/search/cluster/ClusterSearcher.java b/container-search/src/main/java/com/yahoo/search/cluster/ClusterSearcher.java
index 06cbf9a9706..20f56c86f7b 100644
--- a/container-search/src/main/java/com/yahoo/search/cluster/ClusterSearcher.java
+++ b/container-search/src/main/java/com/yahoo/search/cluster/ClusterSearcher.java
@@ -96,7 +96,7 @@ public abstract class ClusterSearcher<T> extends PingableSearcher implements Nod
future.cancel(true);
if (pong.badResponse()) {
- monitor.failed(p, pong.getError(0));
+ monitor.failed(p, pong.error().get());
log(LogLevel.FINE, "Failed ping - ", pong);
} else {
monitor.responded(p);
diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcPing.java b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcPing.java
index f2e22ba86dc..3c4735e57e2 100644
--- a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcPing.java
+++ b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcPing.java
@@ -18,6 +18,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
public class RpcPing implements Callable<Pong> {
+
private static final String RPC_METHOD = "vespa.searchprotocol.ping";
private static final CompressionType PING_COMPRESSION = CompressionType.NONE;
@@ -75,4 +76,5 @@ public class RpcPing implements Callable<Pong> {
return new Pong(reply.getActiveDocs());
}
}
+
}
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 eff6ae26816..5f211c37917 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
@@ -274,7 +274,7 @@ public class SearchCluster implements NodeManager<Node> {
futurePong.cancel(true);
if (pong.badResponse()) {
- clusterMonitor.failed(node, pong.getError(0));
+ clusterMonitor.failed(node, pong.error().get());
} else {
if (pong.activeDocuments().isPresent()) {
node.setActiveDocuments(pong.activeDocuments().get());
diff --git a/container-search/src/test/java/com/yahoo/search/cluster/test/ClusterSearcherTestCase.java b/container-search/src/test/java/com/yahoo/search/cluster/test/ClusterSearcherTestCase.java
index 2992d8ab896..8dcc25e4b3b 100644
--- a/container-search/src/test/java/com/yahoo/search/cluster/test/ClusterSearcherTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/cluster/test/ClusterSearcherTestCase.java
@@ -56,11 +56,10 @@ public class ClusterSearcherTestCase {
@Override
public Pong ping(Ping ping, Execution execution) {
- Pong pong = new Pong();
- if (isBlocking()) {
- pong.addError(ErrorMessage.createTimeout("Dummy timeout"));
- }
- return new Pong();
+ if (isBlocking())
+ return new Pong(ErrorMessage.createTimeout("Dummy timeout"));
+ else
+ return new Pong();
}
public boolean isBlocking() {
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 c90d2774bd1..a824edd1996 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
@@ -182,10 +182,10 @@ public class ClusteredConnectionTestCase {
@Override
public Pong ping(Ping ping,Connection connection) {
- Pong pong = new Pong();
- if (connection.getResponse() == null)
- pong.addError(ErrorMessage.createBackendCommunicationError("No ping response from '" + connection + "'"));
- return pong;
+ if (connection.getResponse() != null)
+ return new Pong();
+ else
+ return new Pong(ErrorMessage.createBackendCommunicationError("No ping response from '" + connection + "'"));
}
}