summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/fastsearch
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-09-13 10:01:11 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2019-09-13 10:01:11 +0200
commit5f56dbef4aaf4a2212fcd44bc8ce4a60f1cf2904 (patch)
tree0e66181f21526b934e0a47ddeb7cd3b57848b0ba /container-search/src/main/java/com/yahoo/prelude/fastsearch
parent04694f5e9157f350af5bdbe4f39e272118a7eacb (diff)
Avoid wrapping the 12 bytes in yet another object.
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude/fastsearch')
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumPacketKey.java66
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4FillInvoker.java59
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4SearchInvoker.java2
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/fastsearch/FastHit.java35
4 files changed, 33 insertions, 129 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumPacketKey.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumPacketKey.java
deleted file mode 100644
index a3b5a6f57b6..00000000000
--- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumPacketKey.java
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2017 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.document.GlobalId;
-
-
-/**
- * Key for each entry in the packet cache.
- *
- * @author Mathias Mølster Lidal
- */
-public class DocsumPacketKey {
-
- private GlobalId globalId;
- private int partid;
- private String summaryClass;
-
- private static boolean strEquals(String a, String b) {
- if (a == null || b == null) {
- return (a == null && b == null);
- }
- return a.equals(b);
- }
-
- private static int strHashCode(String s) {
- if (s == null) {
- return 0;
- }
- return s.hashCode();
- }
-
- public DocsumPacketKey(GlobalId globalId, int partid, String summaryClass) {
- this.globalId = globalId;
- this.partid = partid;
- this.summaryClass = summaryClass;
- }
-
- public GlobalId getGlobalId() {
- return globalId;
- }
-
- public int getPartid() {
- return partid;
- }
-
- @Override
- public boolean equals(Object o) {
- if (o instanceof DocsumPacketKey) {
- DocsumPacketKey other = (DocsumPacketKey) o;
-
- if (globalId.equals(other.getGlobalId())
- && partid == other.getPartid()
- && strEquals(summaryClass, other.summaryClass))
- {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return globalId.hashCode() + 10 * partid + strHashCode(summaryClass);
- }
-
-}
diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4FillInvoker.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4FillInvoker.java
index 97a04b9853c..a4729a87326 100644
--- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4FillInvoker.java
+++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4FillInvoker.java
@@ -41,22 +41,15 @@ public class FS4FillInvoker extends FillInvoker {
@Override
protected void sendFillRequest(Result result, String summaryClass) {
- if (countFastHits(result) > 0) {
- DocsumPacketKey[] summaryPacketKeys = getPacketKeys(result, summaryClass);
- if (summaryPacketKeys.length == 0) {
- expectedFillResults = 0;
- } else {
- try {
- expectedFillResults = requestSummaries(result, summaryClass);
- } catch (InvalidChannelException e) {
- result.hits()
- .addError(ErrorMessage.createBackendCommunicationError("Invalid channel " + getName() + " (summary fetch)"));
- return;
- } catch (IOException e) {
- result.hits().addError(ErrorMessage.createBackendCommunicationError(
- "IO error while talking on channel " + getName() + " (summary fetch): " + e.getMessage()));
- return;
- }
+ if (countFastHits(result, summaryClass) > 0) {
+ try {
+ expectedFillResults = requestSummaries(result, summaryClass);
+ } catch (InvalidChannelException e) {
+ result.hits()
+ .addError(ErrorMessage.createBackendCommunicationError("Invalid channel " + getName() + " (summary fetch)"));
+ } catch (IOException e) {
+ result.hits().addError(ErrorMessage.createBackendCommunicationError(
+ "IO error while talking on channel " + getName() + " (summary fetch): " + e.getMessage()));
}
} else {
expectedFillResults = 0;
@@ -132,10 +125,11 @@ public class FS4FillInvoker extends FillInvoker {
}
}
- private int countFastHits(Result result) {
+ private int countFastHits(Result result, String summaryClass) {
int count = 0;
for (Iterator<Hit> i = hitIterator(result); i.hasNext();) {
- if (i.next() instanceof FastHit)
+ Hit hit = i.next();
+ if (hit instanceof FastHit && !hit.isFilled(summaryClass))
count++;
}
return count;
@@ -170,35 +164,6 @@ public class FS4FillInvoker extends FillInvoker {
return convertBasicPackets(receivedPackets);
}
- /**
- * Returns an array of the hits contained in a result
- *
- * @return array of docids, empty array if no hits
- */
- private DocsumPacketKey[] getPacketKeys(Result result, String summaryClass) {
- DocsumPacketKey[] packetKeys = new DocsumPacketKey[result.getHitCount()];
- int x = 0;
-
- for (Iterator<com.yahoo.search.result.Hit> i = hitIterator(result); i.hasNext();) {
- com.yahoo.search.result.Hit hit = i.next();
- if (hit instanceof FastHit) {
- FastHit fastHit = (FastHit) hit;
- if (!fastHit.isFilled(summaryClass)) {
- packetKeys[x] = new DocsumPacketKey(fastHit.getGlobalId(), fastHit.getPartId(), summaryClass);
- x++;
- }
- }
- }
- if (x < packetKeys.length) {
- DocsumPacketKey[] tmp = new DocsumPacketKey[x];
-
- System.arraycopy(packetKeys, 0, tmp, 0, x);
- return tmp;
- } else {
- return packetKeys;
- }
- }
-
private static Packet[] convertBasicPackets(BasicPacket[] basicPackets) throws ClassCastException {
// trying to cast a BasicPacket[] to Packet[] will compile,
// but lead to a runtime error. At least that's what I got
diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4SearchInvoker.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4SearchInvoker.java
index 27c4c73dd65..33715921e6d 100644
--- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4SearchInvoker.java
+++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FS4SearchInvoker.java
@@ -228,7 +228,7 @@ public class FS4SearchInvoker extends SearchInvoker implements ResponseMonitor<F
hit.setRelevance(new Relevance(rank.doubleValue()));
hit.setDistributionKey(document.getDistributionKey());
- hit.setGlobalId(document.getGlobalId());
+ hit.setGlobalId(document.getRawGlobalId());
hit.setPartId(document.getPartId());
hit.setSortData(document.getSortData(), sorting);
}
diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastHit.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastHit.java
index 0126fc01410..515e09d0007 100644
--- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastHit.java
+++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastHit.java
@@ -30,9 +30,7 @@ import java.util.function.BiConsumer;
* @author Steinar Knutsen
*/
public class FastHit extends Hit {
-
- private static final GlobalId emptyGlobalId = new GlobalId(new byte[GlobalId.LENGTH]);
-
+ private static final byte [] emptyGID = new byte[GlobalId.LENGTH];
/** The index of the content node this hit originated at */
private int distributionKey = 0;
@@ -41,7 +39,7 @@ public class FastHit extends Hit {
/** The global id of this document in the backend node which produced it */
//Todo should be bytearray directly and generate GlobvalId on access
- private GlobalId globalId = emptyGlobalId;
+ private byte [] globalId;
//TODO Remove with fs4
private transient QueryPacketData queryPacketData = null;
@@ -71,9 +69,14 @@ public class FastHit extends Hit {
/**
* Creates an empty and temporarily invalid summary hit
*/
- public FastHit() { }
+ public FastHit() {
+ super(new Relevance(0.0));
+ globalId = emptyGID;
+ partId = 0;
+ distributionKey = 0;
+ }
- public FastHit(GlobalId gid, Relevance relevance, int partId, int distributionKey) {
+ public FastHit(byte [] gid, Relevance relevance, int partId, int distributionKey) {
super(relevance);
this.globalId = gid;
this.partId = partId;
@@ -87,11 +90,13 @@ public class FastHit extends Hit {
// Note: This constructor is only used for tests, production use is always of the empty constructor
private FastHit(String uri, double relevance, String source) {
+ super(new Relevance(relevance));
+ partId = 0;
+ distributionKey = 0;
+ globalId = emptyGID;
setId(uri);
- setRelevance(new Relevance(relevance));
setSource(source);
types().add("summary");
- setPartId(0);
}
/** Returns false - this is a concrete hit containing requested content */
@@ -110,16 +115,17 @@ public class FastHit extends Hit {
// Fallback to index:[source]/[partid]/[id]
StringBuilder sb = new StringBuilder(64);
sb.append("index:").append(getSource()).append('/').append(getPartId()).append('/');
- appendAsHex(getGlobalId(), sb);
+ appendAsHex(globalId, sb);
URI indexUri = new URI(sb.toString());
assignId(indexUri);
return indexUri;
}
/** Returns the global id of this document in the backend node which produced it */
- public GlobalId getGlobalId() { return globalId; }
+ public GlobalId getGlobalId() { return new GlobalId(globalId); }
+ public byte [] getRawGlobalId() { return globalId; }
- public void setGlobalId(GlobalId globalId) { this.globalId = globalId; }
+ public void setGlobalId(byte [] globalId) { this.globalId = globalId; }
public int getPartId() { return partId; }
@@ -363,7 +369,7 @@ public class FastHit extends Hit {
@Override
public String toString() {
- return super.toString() + " [fasthit, globalid: " + globalId + ", partId: "
+ return super.toString() + " [fasthit, globalid: " + new GlobalId(globalId).toString() + ", partId: "
+ partId + ", distributionkey: " + distributionKey + "]";
}
@@ -377,9 +383,8 @@ public class FastHit extends Hit {
}
}
- private void appendAsHex(GlobalId gid, StringBuilder sb) {
- byte[] rawGid = gid.getRawId();
- for (byte b : rawGid) {
+ private static void appendAsHex(byte [] gid, StringBuilder sb) {
+ for (byte b : gid) {
String hex = Integer.toHexString(0xFF & b);
if (hex.length() == 1) {
sb.append('0');