diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-04-23 21:07:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-23 21:07:39 +0200 |
commit | bbc315437e29723c60d17b7f715a3f11c97d2536 (patch) | |
tree | 518dee932199dcc396ef395cb64317068fb3975c | |
parent | 60b66c70d7fd7c7f17bb88d6e1fef06d63ea0910 (diff) | |
parent | d43d1012473e54da068d68e7f95719c94ebdb1a4 (diff) |
Merge pull request #5677 from vespa-engine/bratseth/dispatch-summaries-take-5
Bratseth/dispatch summaries take 5
34 files changed, 323 insertions, 241 deletions
diff --git a/container-search/src/main/java/com/yahoo/fs4/QueryPacket.java b/container-search/src/main/java/com/yahoo/fs4/QueryPacket.java index 0709baa9be2..b8242ff5101 100644 --- a/container-search/src/main/java/com/yahoo/fs4/QueryPacket.java +++ b/container-search/src/main/java/com/yahoo/fs4/QueryPacket.java @@ -15,7 +15,6 @@ import com.yahoo.vespa.objects.BufferSerializer; import java.nio.ByteBuffer; import java.util.List; - /** * An "extended query" packet. This is the query packets used today, * they allow more flexible sets of parameters to be shipped with queries. @@ -26,12 +25,13 @@ import java.util.List; */ public class QueryPacket extends Packet { - final private Query query; + private final Query query; + private QueryPacketData queryPacketData; - int sessionOffset = 0; // Start of sessionKey ignore section for cache key - int sessionSize = 0; // Length of sessionKey ignore section for cache key - int ignoreableOffset = 0; // Start of (hits/offset/timestamp) ignore section for cache key - int ignoreableSize = 0; // Length of (hits/offset/timestamp) ignore section for cache key + private int sessionOffset = 0; // Start of sessionKey ignore section for cache key + private int sessionSize = 0; // Length of sessionKey ignore section for cache key + private int ignoreableOffset = 0; // Start of (hits/offset/timestamp) ignore section for cache key + private int ignoreableSize = 0; // Length of (hits/offset/timestamp) ignore section for cache key private QueryPacket(Query query) { this.query = query; @@ -80,6 +80,7 @@ public class QueryPacket extends Packet { private int getSessionKeySkipLength() { return (sessionSize > 0) ? sessionSize + 4 : 0; } + /** * Returns an opaque cache key for the query represented by this * (pre-serialized) packet. @@ -191,14 +192,14 @@ public class QueryPacket extends Packet { /** * feature bits, taken from searchlib/common/transport.h - **/ - static final int QF_PARSEDQUERY = 0x00000002; - static final int QF_RANKP = 0x00000004; - static final int QF_SORTSPEC = 0x00000080; - static final int QF_LOCATION = 0x00000800; - static final int QF_PROPERTIES = 0x00100000; - static final int QF_GROUPSPEC = 0x00400000; - static final int QF_SESSIONID = 0x00800000; + */ + private static final int QF_PARSEDQUERY = 0x00000002; + private static final int QF_RANKP = 0x00000004; + private static final int QF_SORTSPEC = 0x00000080; + private static final int QF_LOCATION = 0x00000800; + private static final int QF_PROPERTIES = 0x00100000; + private static final int QF_GROUPSPEC = 0x00400000; + private static final int QF_SESSIONID = 0x00800000; private int getFeatureInt(boolean sendSessionId) { int features = QF_PARSEDQUERY | QF_RANKP; // this bitmask means "parsed query" in query packet. @@ -215,27 +216,27 @@ public class QueryPacket extends Packet { /** * query flag bits, taken from searchlib/common/transport.h - **/ - static final int QFLAG_EXTENDED_COVERAGE = 0x00000001; - static final int QFLAG_COVERAGE_NODES = 0x00000002; - static final int QFLAG_ESTIMATE = 0x00000080; - static final int QFLAG_DROP_SORTDATA = 0x00004000; - static final int QFLAG_NO_RESULTCACHE = 0x00010000; - static final int QFLAG_DUMP_FEATURES = 0x00040000; + */ + private static final int QFLAG_EXTENDED_COVERAGE = 0x00000001; + private static final int QFLAG_COVERAGE_NODES = 0x00000002; + private static final int QFLAG_ESTIMATE = 0x00000080; + private static final int QFLAG_DROP_SORTDATA = 0x00004000; + private static final int QFLAG_NO_RESULTCACHE = 0x00010000; + private static final int QFLAG_DUMP_FEATURES = 0x00040000; private int getFlagInt() { int flags = getQueryFlags(query); queryPacketData.setQueryFlags(flags); - /** + /* * QFLAG_DROP_SORTDATA * SORTDATA is a mangling of data from the attribute vectors * which were used in the search which is byte comparable in * such a way the comparing SORTDATA for two different hits * will reproduce the order in which the data were returned when - * using sortspec. For now we simple drop these, but if they - * should be necessary at later date, QueryResultPacket must be - * updated to be able to parse result packets correctly. + * using sortspec. For now we simply drop these. If they + * become necessar, QueryResultPacket must be + * updated to be able to read the sort data. */ flags |= QFLAG_DROP_SORTDATA; return flags; @@ -264,13 +265,12 @@ public class QueryPacket extends Packet { * creating a summary request. * * @return wrapper object suitable for creating a summary fetch packet - * @throws IllegalStateException - * if no wrapper has been generated + * @throws IllegalStateException if no wrapper has been generated */ public QueryPacketData getQueryPacketData() { - if (queryPacketData == null) { + if (queryPacketData == null) throw new IllegalStateException("Trying to fetch a hit tag without having encoded the packet first."); - } return queryPacketData; } + } 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 2709755da5d..258f0dec9ff 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 @@ -13,6 +13,7 @@ import com.yahoo.container.handler.VipStatus; import com.yahoo.fs4.mplex.Backend; import com.yahoo.container.search.LegacyEmulationConfig; import com.yahoo.net.HostName; +import com.yahoo.prelude.fastsearch.DocsumDefinitionSet; import com.yahoo.search.dispatch.Dispatcher; import com.yahoo.prelude.fastsearch.FS4ResourcePool; import com.yahoo.prelude.IndexFacts; diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/CacheControl.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/CacheControl.java index c1c818848ad..b7e16b6c082 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/CacheControl.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/CacheControl.java @@ -12,7 +12,7 @@ import com.yahoo.processing.request.CompoundName; /** * The cache control logic for FastSearcher * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class CacheControl { diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumDefinition.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumDefinition.java index 4fd0f884903..d50006fb82c 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumDefinition.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumDefinition.java @@ -21,20 +21,33 @@ import java.util.Map; */ public class DocsumDefinition { - private String name; - private final List<DocsumField> fields; + private final String name; + private final ImmutableList<DocsumField> fields; /** True if this contains dynamic fields */ - private boolean dynamic = false; + private final boolean dynamic; // Mapping between field names and their index in this.fields - private final Map<String,Integer> fieldNameToIndex; + private final ImmutableMap<String, Integer> fieldNameToIndex; + + public DocsumDefinition(String name, List<DocsumField> fields) { + this.name = name; + this.dynamic = false; + this.fields = ImmutableList.copyOf(fields); + ImmutableMap.Builder<String, Integer> fieldNameToIndexBuilder = new ImmutableMap.Builder<>(); + int i = 0; + for (DocsumField field : fields) + fieldNameToIndexBuilder.put(field.name, i++); + this.fieldNameToIndex = fieldNameToIndexBuilder.build(); + } + // TODO: Remove LegacyEmulationConfig (the config, not just the usage) on Vespa 7 DocsumDefinition(DocumentdbInfoConfig.Documentdb.Summaryclass config, LegacyEmulationConfig emulConfig) { this.name = config.name(); - List<DocsumField> fieldsBuilder = new ArrayList<>(); - Map<String,Integer> fieldNameToIndexBuilder = new HashMap<>(); + List<DocsumField> fieldsBuilder = new ArrayList<>(); + Map<String, Integer> fieldNameToIndexBuilder = new HashMap<>(); + boolean dynamic = false; for (DocumentdbInfoConfig.Documentdb.Summaryclass.Fields field : config.fields()) { // no, don't switch the order of the two next lines :) fieldNameToIndexBuilder.put(field.name(), fieldsBuilder.size()); @@ -42,6 +55,7 @@ public class DocsumDefinition { if (field.dynamic()) dynamic = true; } + this.dynamic = dynamic; fields = ImmutableList.copyOf(fieldsBuilder); fieldNameToIndex = ImmutableMap.copyOf(fieldNameToIndexBuilder); } diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumDefinitionSet.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumDefinitionSet.java index 8d882adeb02..c9e771fe48c 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumDefinitionSet.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumDefinitionSet.java @@ -1,6 +1,7 @@ // 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.google.common.collect.ImmutableMap; import com.yahoo.slime.BinaryFormat; import com.yahoo.data.access.Inspector; import com.yahoo.slime.Slime; @@ -10,9 +11,11 @@ import com.yahoo.container.search.LegacyEmulationConfig; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.util.HashMap; +import java.util.ArrayList; +import java.util.Collection; import java.util.Map; import java.util.logging.Logger; +import java.util.stream.Collectors; import static com.yahoo.data.access.Type.OBJECT; @@ -27,29 +30,44 @@ public final class DocsumDefinitionSet { public static final int SLIME_MAGIC_ID = 0x55555555; private final static Logger log = Logger.getLogger(DocsumDefinitionSet.class.getName()); - private final HashMap<String, DocsumDefinition> definitionsByName = new HashMap<>(); + private final Map<String, DocsumDefinition> definitionsByName; private final LegacyEmulationConfig emulationConfig; public DocsumDefinitionSet(DocumentdbInfoConfig.Documentdb config) { - this.emulationConfig = new LegacyEmulationConfig(new LegacyEmulationConfig.Builder()); - configure(config); + this(config, new LegacyEmulationConfig(new LegacyEmulationConfig.Builder())); } public DocsumDefinitionSet(DocumentdbInfoConfig.Documentdb config, LegacyEmulationConfig emulConfig) { + this(toDocsums(config, emulConfig), emulConfig); + } + + public DocsumDefinitionSet(Collection<DocsumDefinition> docsumDefinitions) { + this(docsumDefinitions, new LegacyEmulationConfig(new LegacyEmulationConfig.Builder())); + } + + public DocsumDefinitionSet(Collection<DocsumDefinition> docsumDefinitions, LegacyEmulationConfig emulConfig) { + this.definitionsByName = ImmutableMap.copyOf(docsumDefinitions.stream().collect(Collectors.toMap(DocsumDefinition::getName, p -> p))); this.emulationConfig = emulConfig; - configure(config); } + LegacyEmulationConfig legacyEmulationConfig() { return emulationConfig; } + /** - * Returns a docsum definition by name, or null if not found + * Returns the summary definition of the given name, or the default if not found. * - * @param name the name of the summary class to use, or null to use the name "default" - * @return the summary class found, or null if none + * @throws ConfigurationException if the requested summary class is not found and there is none called "default" */ - public final DocsumDefinition getDocsumDefinition(String name) { - if (name == null) - name="default"; - return definitionsByName.get(name); + public DocsumDefinition getDocsum(String summaryClass) { + DocsumDefinition ds = definitionsByName.get(summaryClass); + if (ds == null) { + ds = definitionsByName.get("default"); + } + if (ds == null) { + throw new ConfigurationException("Fetched hit with summary class " + summaryClass + + ", but this summary class is not in current summary config (" + toString() + ")" + + " (that is, you asked for something unknown, and no default was found)"); + } + return ds; } /** @@ -68,7 +86,7 @@ public final class DocsumDefinitionSet { if (docsumClassId != SLIME_MAGIC_ID) { throw new IllegalArgumentException("Only expecting SchemaLess docsums - summary class:" + summaryClass + " hit:" + hit); } - DocsumDefinition docsumDefinition = lookupDocsum(summaryClass); + DocsumDefinition docsumDefinition = getDocsum(summaryClass); Slime value = BinaryFormat.decode(buffer.array(), buffer.arrayOffset()+buffer.position(), buffer.remaining()); Inspector docsum = new SlimeAdapter(value.get()); if (docsum.type() != OBJECT) { @@ -78,19 +96,6 @@ public final class DocsumDefinitionSet { return null; } - private DocsumDefinition lookupDocsum(String summaryClass) { - DocsumDefinition ds = definitionsByName.get(summaryClass); - if (ds == null) { - ds = definitionsByName.get("default"); - } - if (ds == null) { - throw new ConfigurationException("Fetched hit with summary class " + summaryClass + - ", but this summary class is not in current summary config (" + toString() + ")" + - " (that is, you asked for something unknown, and no default was found)"); - } - return ds; - } - public String toString() { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, DocsumDefinition> e : definitionsByName.entrySet() ) { @@ -106,14 +111,13 @@ public final class DocsumDefinitionSet { return definitionsByName.size(); } - private void configure(DocumentdbInfoConfig.Documentdb config) { - for (int i = 0; i < config.summaryclass().size(); ++i) { - DocumentdbInfoConfig.Documentdb.Summaryclass sc = config.summaryclass(i); - DocsumDefinition docSumDef = new DocsumDefinition(sc, emulationConfig); - definitionsByName.put(sc.name(), docSumDef); - } - if (definitionsByName.size() == 0) { + private static Collection<DocsumDefinition> toDocsums(DocumentdbInfoConfig.Documentdb config, LegacyEmulationConfig emulConfig) { + Collection<DocsumDefinition> docsums = new ArrayList<>(); + for (int i = 0; i < config.summaryclass().size(); ++i) + docsums.add(new DocsumDefinition(config.summaryclass(i), emulConfig)); + if (docsums.isEmpty()) log.warning("No summary classes found in DocumentdbInfoConfig.Documentdb"); - } + return docsums; } + } diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumField.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumField.java index 1e44a8fa64d..d5e4eb75931 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumField.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocsumField.java @@ -73,8 +73,8 @@ public abstract class DocsumField { this.name = name; } - /* for unit test only */ - static DocsumField create(String name, String typename) { + /* For unit test only */ + public static DocsumField create(String name, String typename) { return create(name, typename, new LegacyEmulationConfig(new LegacyEmulationConfig.Builder())); } @@ -114,7 +114,7 @@ public abstract class DocsumField { /** * Convert a generic value into an object of the appropriate type * for this field. - **/ + */ public abstract Object convert(Inspector value); } diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocumentDatabase.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocumentDatabase.java index 3366f92384a..0ae0983a1ae 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocumentDatabase.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/DocumentDatabase.java @@ -4,10 +4,13 @@ package com.yahoo.prelude.fastsearch; import com.google.common.collect.ImmutableMap; import com.yahoo.container.search.LegacyEmulationConfig; +import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * Representation of a back-end document database. @@ -24,12 +27,16 @@ public class DocumentDatabase { private final String name; private final DocsumDefinitionSet docsumDefSet; - private final Map<String, RankProfile> rankProfiles; + private final ImmutableMap<String, RankProfile> rankProfiles; public DocumentDatabase(DocumentdbInfoConfig.Documentdb documentDb, LegacyEmulationConfig emulConfig) { - this.name = documentDb.name(); - this.docsumDefSet = new DocsumDefinitionSet(documentDb, emulConfig); - this.rankProfiles = ImmutableMap.copyOf(toRankProfiles(documentDb.rankprofile())); + this(documentDb.name(), new DocsumDefinitionSet(documentDb, emulConfig), toRankProfiles(documentDb.rankprofile())); + } + + public DocumentDatabase(String name, DocsumDefinitionSet docsumDefinitionSet, Collection<RankProfile> rankProfiles) { + this.name = name; + this.docsumDefSet = docsumDefinitionSet; + this.rankProfiles = ImmutableMap.copyOf(rankProfiles.stream().collect(Collectors.toMap(RankProfile::getName, p -> p))); } public String getName() { @@ -43,11 +50,14 @@ public class DocumentDatabase { /** Returns an unmodifiable map of all the rank profiles in this indexed by rank profile name */ public Map<String, RankProfile> rankProfiles() { return rankProfiles; } - private Map<String, RankProfile> toRankProfiles(List<DocumentdbInfoConfig.Documentdb.Rankprofile> rankProfileConfigList) { - Map<String, RankProfile> rankProfiles = new HashMap<>(); - for (DocumentdbInfoConfig.Documentdb.Rankprofile c : rankProfileConfigList) { - rankProfiles.put(c.name(), new RankProfile(c.name(), c.hasSummaryFeatures(), c.hasRankFeatures())); - } + private static ImmutableMap<String, RankProfile> toMap(Collection<RankProfile> rankProfiles) { + return ImmutableMap.copyOf(rankProfiles.stream().collect(Collectors.toMap(RankProfile::getName, p -> p))); + } + + private static Collection<RankProfile> toRankProfiles(Collection<DocumentdbInfoConfig.Documentdb.Rankprofile> rankProfileConfigList) { + List<RankProfile> rankProfiles = new ArrayList<>(); + for (DocumentdbInfoConfig.Documentdb.Rankprofile c : rankProfileConfigList) + rankProfiles.add(new RankProfile(c.name(), c.hasSummaryFeatures(), c.hasRankFeatures())); return rankProfiles; } 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 aab8aae6025..b3eaee8698a 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 @@ -74,9 +74,10 @@ public class FastHit extends Hit { setPartId(0, 0); } + @Override public String toString() { return super.toString() + " [fasthit, globalid: " + globalId + ", partId: " - + partId + ", distributionkey: " + distributionKey + "]"; + + partId + ", distributionkey: " + distributionKey + "]"; } public static String asHexString(GlobalId gid) { @@ -267,7 +268,8 @@ public class FastHit extends Hit { this.distributionKey = distributionKey; } - void addSummary(DocsumDefinition docsumDef, Inspector value) { + /** For internal use */ + public void addSummary(DocsumDefinition docsumDef, Inspector value) { reserve(docsumDef.getFieldCount()); for (DocsumField field : docsumDef.getFields()) { String fieldName = field.getName(); @@ -290,10 +292,8 @@ public class FastHit extends Hit { * easier. This is not a method to be used for efficiency, as it causes * object allocations. * - * @param fieldName - * the name of the field to insert undecoded UTF-8 into - * @param value - * an array of valid UTF-8 data + * @param fieldName the name of the field to insert undecoded UTF-8 into + * @param value an array of valid UTF-8 data */ @Beta public void setLazyStringField(String fieldName, byte[] value) { 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 7d822fd603b..7c8ecd44cf9 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 @@ -4,6 +4,7 @@ package com.yahoo.prelude.fastsearch; import java.util.Optional; import com.yahoo.compress.CompressionType; +import com.yahoo.container.search.LegacyEmulationConfig; import com.yahoo.fs4.BasicPacket; import com.yahoo.fs4.ChannelTimeoutException; import com.yahoo.fs4.GetDocSumsPacket; @@ -15,7 +16,6 @@ import com.yahoo.fs4.QueryResultPacket; import com.yahoo.fs4.mplex.Backend; import com.yahoo.fs4.mplex.FS4Channel; import com.yahoo.fs4.mplex.InvalidChannelException; -import com.yahoo.net.HostName; import com.yahoo.prelude.Ping; import com.yahoo.prelude.Pong; import com.yahoo.prelude.querytransform.QueryRewrite; @@ -56,6 +56,9 @@ public class FastSearcher extends VespaBackEndSearcher { /** If this is turned on this will make search queries directly to the local search node when possible */ private final static CompoundName dispatchDirect = new CompoundName("dispatch.direct"); + /** 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"); + /** The compression method which will be used with rpc dispatch. "lz4" (default) and "none" is supported. */ private final static CompoundName dispatchCompression = new CompoundName("dispatch.compression"); @@ -231,6 +234,7 @@ public class FastSearcher extends VespaBackEndSearcher { /** * Only used to fill the sddocname field when using direct dispatching as that is normally done in VespaBackEndSearcher.decodeSummary + * * @param result The result */ private void fillSDDocName(Result result) { @@ -255,11 +259,16 @@ public class FastSearcher extends VespaBackEndSearcher { Query query = result.getQuery(); traceQuery(getName(), "fill", query, query.getOffset(), query.getHits(), 2, quotedSummaryClass(summaryClass)); - if (wantsRPCSummaryFill(query)) { + if (query.properties().getBoolean(dispatchSummaries, true) + && ! summaryNeedsQuery(query) + && query.getRanking().getLocation() == null + && ! cacheControl.useCache(query) + && ! legacyEmulationConfigIsSet(getDocumentDatabase(query))) { + CompressionType compression = CompressionType.valueOf(query.properties().getString(dispatchCompression, "LZ4").toUpperCase()); fillSDDocName(result); - dispatcher.fill(result, summaryClass, compression); + dispatcher.fill(result, summaryClass, getDocumentDatabase(query), compression); return; } @@ -271,7 +280,7 @@ public class FastSearcher extends VespaBackEndSearcher { QueryPacket queryPacket = QueryPacket.create(query); cacheKey = new CacheKey(queryPacket); } - packetWrapper = cacheLookupTwoPhase(cacheKey, result,summaryClass); + packetWrapper = cacheLookupTwoPhase(cacheKey, result, summaryClass); } FS4Channel channel = chooseBackend(query).openChannel(); @@ -349,6 +358,14 @@ public class FastSearcher extends VespaBackEndSearcher { } } + private boolean legacyEmulationConfigIsSet(DocumentDatabase db) { + LegacyEmulationConfig config = db.getDocsumDefinitionSet().legacyEmulationConfig(); + if (config.forceFillEmptyFields()) return true; + if (config.stringBackedFeatureData()) return true; + if (config.stringBackedStructuredData()) return true; + return false; + } + private static @NonNull Optional<String> quotedSummaryClass(String summaryClass) { return Optional.of(summaryClass == null ? "[null]" : quote(summaryClass)); } @@ -465,14 +482,9 @@ public class FastSearcher extends VespaBackEndSearcher { } boolean couldSend = channel.sendPacket(docsumsPacket); - if (isLoggingFine()) - getLogger().finest("Sent " + docsumsPacket + " on " + channel); if ( ! couldSend) throw new IOException("Could not successfully send GetDocSumsPacket."); receivedPackets = channel.receivePackets(result.getQuery().getTimeLeft(), docsumsPacket.getNumDocsums() + 1); - if (isLoggingFine()) - getLogger().finest("got " + receivedPackets.length + "docsumPackets"); - return convertBasicPackets(receivedPackets); } diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FloatField.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FloatField.java index 6be5a27b49b..6c73167b162 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FloatField.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FloatField.java @@ -9,9 +9,10 @@ import com.yahoo.data.access.Inspector; /** - * @author <a href="mailto:mathiasm@yahoo-inc.com">Mathias M\u00f8lster Lidal</a> + * @author Mathias Mølster Lidal */ public class FloatField extends DocsumField { + static final double EMPTY_VALUE = Float.NaN; public FloatField(String name) { @@ -26,10 +27,12 @@ public class FloatField extends DocsumField { } } + @Override public Object decode(ByteBuffer b) { return convert(b.getFloat()); } + @Override public Object decode(ByteBuffer b, FastHit hit) { Object field = decode(b); hit.setField(name, field); @@ -46,4 +49,5 @@ public class FloatField extends DocsumField { public Object convert(Inspector value) { return convert((float)value.asDouble(EMPTY_VALUE)); } + } diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/IntegerField.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/IntegerField.java index fe44597b7d7..eef6fc73294 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/IntegerField.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/IntegerField.java @@ -12,9 +12,10 @@ import com.yahoo.search.result.NanNumber; import com.yahoo.data.access.Inspector; /** - * @author <a href="mailto:borud@yahoo-inc.com">Bj\u00f8rn Borud</a> + * @author Bjørn Borud */ public class IntegerField extends DocsumField { + static final int EMPTY_VALUE = Integer.MIN_VALUE; public IntegerField(String name) { @@ -25,20 +26,23 @@ public class IntegerField extends DocsumField { if (value == EMPTY_VALUE) { return NanNumber.NaN; } else { - return Integer.valueOf(value); + return value; } } + @Override public Object decode(ByteBuffer b) { return convert(b.getInt()); } + @Override public Object decode(ByteBuffer b, FastHit hit) { Object field = decode(b); hit.setField(name, field); return field; } + @Override public String toString() { return "field " + getName() + " type int"; } @@ -53,4 +57,5 @@ public class IntegerField extends DocsumField { public Object convert(Inspector value) { return convert((int)value.asLong(EMPTY_VALUE)); } + } diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/LongdataField.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/LongdataField.java index 08cd4ddff35..9d22168485c 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/LongdataField.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/LongdataField.java @@ -86,4 +86,5 @@ public class LongdataField extends DocsumField implements VariableLengthField { public Object convert(Inspector value) { return convert(value.asData(Value.empty().asData())); } + } diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java index eac1579a821..740deaa7ca1 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java @@ -55,8 +55,6 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { private static final CompoundName grouping=new CompoundName("grouping"); private static final CompoundName combinerows=new CompoundName("combinerows"); - /** If this is turned on this will fill summaries by dispatching directly to search nodes over RPC */ - private final static CompoundName dispatchSummaries = new CompoundName("dispatch.summaries"); protected static final CompoundName PACKET_COMPRESSION_LIMIT = new CompoundName("packetcompressionlimit"); protected static final CompoundName PACKET_COMPRESSION_TYPE = new CompoundName("packetcompressiontype"); @@ -110,10 +108,6 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { protected abstract void doPartialFill(Result result, String summaryClass); - protected static boolean wantsRPCSummaryFill(Query query) { - return query.properties().getBoolean(dispatchSummaries); - } - /** * Returns whether we need to send the query when fetching summaries. * This is necessary if the query requests summary features or dynamic snippeting @@ -124,8 +118,7 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { DocumentDatabase documentDb = getDocumentDatabase(query); // Needed to generate a dynamic summary? - DocsumDefinition docsumDefinition = documentDb.getDocsumDefinitionSet().getDocsumDefinition(query.getPresentation().getSummary()); - if (docsumDefinition == null) return true; // stay safe + DocsumDefinition docsumDefinition = documentDb.getDocsumDefinitionSet().getDocsum(query.getPresentation().getSummary()); if (docsumDefinition.isDynamic()) return true; // Needed to generate ranking features? @@ -216,12 +209,6 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { return new Result(query, ErrorMessage.createNullQuery(query.getHttpRequest().getUri().toString())); } - if (wantsRPCSummaryFill(query) && summaryNeedsQuery(query)) { - return new Result(query, ErrorMessage.createInvalidQueryParameter( - "When using dispatch.summaries and your summary/rankprofile require the query, " + - " you need to enable ranking.queryCache.")); - } - QueryRewrite.optimizeByRestrict(query); QueryRewrite.optimizeAndNot(query); QueryRewrite.collapseSingleComposites(query); @@ -492,13 +479,13 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { * when things are working normally we return 0. */ protected FillHitsResult fillHits(Result result, Packet[] packets, String summaryClass) throws IOException { - int skippedHits=0; + int skippedHits = 0; String lastError = null; int packetIndex = 0; for (Iterator<Hit> i = hitIterator(result); i.hasNext();) { Hit hit = i.next(); - if (hit instanceof FastHit && !hit.isFilled(summaryClass)) { + if (hit instanceof FastHit && ! hit.isFilled(summaryClass)) { FastHit fastHit = (FastHit) hit; ensureInstanceOf(DocsumPacket.class, packets[packetIndex], getName()); diff --git a/container-search/src/main/java/com/yahoo/prelude/hitfield/FieldPart.java b/container-search/src/main/java/com/yahoo/prelude/hitfield/FieldPart.java index df8f6e92d57..6ca5feb610f 100644 --- a/container-search/src/main/java/com/yahoo/prelude/hitfield/FieldPart.java +++ b/container-search/src/main/java/com/yahoo/prelude/hitfield/FieldPart.java @@ -4,11 +4,13 @@ package com.yahoo.prelude.hitfield; /** * Represents an element of a hit property * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public interface FieldPart { - public abstract boolean isFinal(); - public abstract boolean isToken(); - public abstract String getContent(); - public abstract String toString(); + + boolean isFinal(); + boolean isToken(); + String getContent(); + String toString(); + } diff --git a/container-search/src/main/java/com/yahoo/prelude/hitfield/HitField.java b/container-search/src/main/java/com/yahoo/prelude/hitfield/HitField.java index 770ac24dcab..79d871d8c74 100644 --- a/container-search/src/main/java/com/yahoo/prelude/hitfield/HitField.java +++ b/container-search/src/main/java/com/yahoo/prelude/hitfield/HitField.java @@ -10,11 +10,10 @@ import com.yahoo.prelude.searcher.JuniperSearcher; import com.yahoo.text.XML; /** - * Represents a Field in a Hit. The original raw content and the field - * name cannot be modified. But the tokenized version can be retrieved - * and set. + * Represents a tokenized string field in a Hit. The original raw content and the field + * name cannot be modified. But the tokenized version can be retrieved and set. * - * @author <a href="mailto:larschr@yahoo-inc.com">Lars Christian Jensen</a> + * @author Lars Christian Jensen */ public class HitField { @@ -345,10 +344,7 @@ public class HitField { return xml.toString(); } - /** - * @return the content of this field, using the arguments as bolding - * tags, as an XML string - */ + /** Returns the content of this field, using the arguments as bolding tags, as an XML string */ public String quotedContent(String boldOpenTag, String boldCloseTag, String separatorTag, diff --git a/container-search/src/main/java/com/yahoo/prelude/hitfield/ImmutableFieldPart.java b/container-search/src/main/java/com/yahoo/prelude/hitfield/ImmutableFieldPart.java index fa0ca62405f..268e1b53459 100644 --- a/container-search/src/main/java/com/yahoo/prelude/hitfield/ImmutableFieldPart.java +++ b/container-search/src/main/java/com/yahoo/prelude/hitfield/ImmutableFieldPart.java @@ -2,12 +2,12 @@ package com.yahoo.prelude.hitfield; /** - * Represents an element of a hit property which is a possibly - * mutable string element + * Represents an element of a hit property which is an immutable string element * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class ImmutableFieldPart implements FieldPart { + private final String content; private final String initContent; // Whether this element represents a (part of) a token or a @@ -15,10 +15,12 @@ public class ImmutableFieldPart implements FieldPart { // parts should inherit this state from the object they were // split from. private boolean tokenOrDelimiter; + public ImmutableFieldPart(String initContent, boolean tokenOrDelimiter) { this(initContent, initContent, tokenOrDelimiter); } + public ImmutableFieldPart(String initContent, String content, boolean tokenOrDelimiter) { @@ -27,9 +29,17 @@ public class ImmutableFieldPart implements FieldPart { this.content = content; this.tokenOrDelimiter = tokenOrDelimiter; } + + @Override public boolean isFinal() { return true; } + @Override public boolean isToken() { return tokenOrDelimiter; } + @Override public String getContent() { return content; } + public String getInitContent() { return initContent; } + + @Override public String toString() { return content; } + } diff --git a/container-search/src/main/java/com/yahoo/prelude/hitfield/JSONString.java b/container-search/src/main/java/com/yahoo/prelude/hitfield/JSONString.java index bdd7cf04c3e..06db012309e 100644 --- a/container-search/src/main/java/com/yahoo/prelude/hitfield/JSONString.java +++ b/container-search/src/main/java/com/yahoo/prelude/hitfield/JSONString.java @@ -19,7 +19,7 @@ import java.util.Iterator; /** * A JSON wrapper. Contains XML-style rendering of a JSON structure. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class JSONString implements Inspectable { diff --git a/container-search/src/main/java/com/yahoo/prelude/hitfield/MarkupFieldPart.java b/container-search/src/main/java/com/yahoo/prelude/hitfield/MarkupFieldPart.java index 23ca8272851..17def6771ae 100644 --- a/container-search/src/main/java/com/yahoo/prelude/hitfield/MarkupFieldPart.java +++ b/container-search/src/main/java/com/yahoo/prelude/hitfield/MarkupFieldPart.java @@ -4,19 +4,31 @@ package com.yahoo.prelude.hitfield; /** * Represents an element of a hit property which is markup, not content. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class MarkupFieldPart implements FieldPart { + private String content; + public MarkupFieldPart(String content) { this.content = content; } + + @Override public boolean isFinal() { return true; } + // Markup is never part of tokens as such + @Override public boolean isToken() { return false; } + public void setContent(String content) { this.content = content; } + + @Override public String getContent() { return content; } + + @Override public String toString() { return content; } + } diff --git a/container-search/src/main/java/com/yahoo/prelude/hitfield/RawData.java b/container-search/src/main/java/com/yahoo/prelude/hitfield/RawData.java index dbbbca63d43..a0c9b10c519 100644 --- a/container-search/src/main/java/com/yahoo/prelude/hitfield/RawData.java +++ b/container-search/src/main/java/com/yahoo/prelude/hitfield/RawData.java @@ -6,8 +6,8 @@ package com.yahoo.prelude.hitfield; * * @author arnej27959 */ -public final class RawData -{ +public final class RawData { + private byte[] content; /** @@ -52,4 +52,5 @@ public final class RawData } return buf.toString(); } + } diff --git a/container-search/src/main/java/com/yahoo/prelude/hitfield/StringFieldPart.java b/container-search/src/main/java/com/yahoo/prelude/hitfield/StringFieldPart.java index d7607fb7100..58018305fef 100644 --- a/container-search/src/main/java/com/yahoo/prelude/hitfield/StringFieldPart.java +++ b/container-search/src/main/java/com/yahoo/prelude/hitfield/StringFieldPart.java @@ -5,9 +5,10 @@ package com.yahoo.prelude.hitfield; * Represents an element of a hit property which is a possibly * mutable string element * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class StringFieldPart implements FieldPart { + private String content; private final String initContent; // Whether this element represents a (part of) a token or a @@ -15,17 +16,28 @@ public class StringFieldPart implements FieldPart { // parts should inherit this state from the object they were // split from. private boolean tokenOrDelimiter; + public StringFieldPart(String content, boolean tokenOrDelimiter) { this.content = content; initContent = content; this.tokenOrDelimiter = tokenOrDelimiter; } + + @Override public boolean isFinal() { return false; } + + @Override public boolean isToken() { return tokenOrDelimiter; } + + @Override public String getContent() { return content; } + public void setContent(String content) { this.content = content; } public String getInitContent() { return initContent; } + + @Override public String toString() { return content; } + } diff --git a/container-search/src/main/java/com/yahoo/prelude/hitfield/XmlRenderer.java b/container-search/src/main/java/com/yahoo/prelude/hitfield/XmlRenderer.java index 8bafbfd6ab5..99c5daa05b8 100644 --- a/container-search/src/main/java/com/yahoo/prelude/hitfield/XmlRenderer.java +++ b/container-search/src/main/java/com/yahoo/prelude/hitfield/XmlRenderer.java @@ -1,21 +1,14 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.prelude.hitfield; -import com.yahoo.text.Utf8; import com.yahoo.text.XML; import com.yahoo.data.access.Inspector; -import com.yahoo.data.access.Inspectable; import com.yahoo.data.access.Type; -import com.yahoo.data.access.simple.Value; -import com.yahoo.data.access.slime.SlimeAdapter; -import java.nio.charset.StandardCharsets; - -import java.util.Iterator; import java.util.Map; /** * Utility class for converting accessible data into the historical "prelude" xml format. - **/ + */ public class XmlRenderer { public static StringBuilder render(StringBuilder target, Inspector value) { diff --git a/container-search/src/main/java/com/yahoo/prelude/searcher/FillSearcher.java b/container-search/src/main/java/com/yahoo/prelude/searcher/FillSearcher.java index f1d14972033..df19526a0a9 100644 --- a/container-search/src/main/java/com/yahoo/prelude/searcher/FillSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/searcher/FillSearcher.java @@ -12,9 +12,10 @@ import com.yahoo.search.searchchain.Execution; * a search chain to ensure full results are present at an earlier * time than they would normally be. * - * @author <a href="mailto:havardpe@yahoo-inc.com">havardpe</a> - **/ + * @author havardpe + */ public class FillSearcher extends Searcher { + private final Searcher next; public FillSearcher() { @@ -49,4 +50,5 @@ public class FillSearcher extends Searcher { e.fill(result, summaryClass); } } + } diff --git a/container-search/src/main/java/com/yahoo/search/Searcher.java b/container-search/src/main/java/com/yahoo/search/Searcher.java index 2de9f5e05ee..5fefe9d2468 100644 --- a/container-search/src/main/java/com/yahoo/search/Searcher.java +++ b/container-search/src/main/java/com/yahoo/search/Searcher.java @@ -73,7 +73,6 @@ public abstract class Searcher extends Processor { // Note to developers: If you think you should add something here you are probably wrong // Create a subclass containing the new method instead. - private final Logger logger = Logger.getLogger(getClass().getName()); public Searcher() {} @@ -131,7 +130,7 @@ public abstract class Searcher extends Processor { /** Use the search method in Searcher processors. This forwards to it. */ @Override public final Response process(com.yahoo.processing.Request request, com.yahoo.processing.execution.Execution execution) { - return search((Query)request,(Execution)execution); + return search((Query)request, (Execution)execution); } /** @@ -147,7 +146,7 @@ public abstract class Searcher extends Processor { * @param summaryClass the name of the collection of fields to fetch the values of, or null to use the default */ public void fill(Result result, String summaryClass, Execution execution) { - execution.fill(result,summaryClass); + execution.fill(result, summaryClass); } /** 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 1b775d2c46f..c8d8aa961de 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 @@ -1,7 +1,6 @@ // Copyright 2017 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.google.common.annotations.Beta; import com.google.common.collect.ImmutableMap; import com.yahoo.collections.ListMap; import com.yahoo.component.AbstractComponent; @@ -9,6 +8,7 @@ import com.yahoo.compress.CompressionType; import com.yahoo.compress.Compressor; import com.yahoo.container.handler.VipStatus; import com.yahoo.container.protect.Error; +import com.yahoo.prelude.fastsearch.DocumentDatabase; import com.yahoo.slime.ArrayTraverser; import com.yahoo.data.access.slime.SlimeAdapter; import com.yahoo.prelude.fastsearch.FS4ResourcePool; @@ -22,12 +22,9 @@ import com.yahoo.search.result.Hit; import com.yahoo.data.access.Inspector; import com.yahoo.slime.BinaryFormat; import com.yahoo.slime.Cursor; -import com.yahoo.slime.JsonFormat; import com.yahoo.slime.Slime; import com.yahoo.vespa.config.search.DispatchConfig; -import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -38,12 +35,15 @@ import java.util.logging.Level; import java.util.logging.Logger; /** - * A dispatcher communicates with search nodes to (in the future) perform queries and (now) fill hits. + * A dispatcher communicates with search nodes to perform queries and fill hits. + * + * This is currently not functionally complete: Queries can only be dispatched to a single node, + * and summaries can only be requested when they do not need the query. + * * This class is multithread safe. * * @author bratseth */ -@Beta public class Dispatcher extends AbstractComponent { private final static Logger log = Logger.getLogger(Dispatcher.class.getName()); @@ -82,15 +82,20 @@ public class Dispatcher extends AbstractComponent { public SearchCluster searchCluster() { return searchCluster; } /** Fills the given summary class by sending RPC requests to the right search nodes */ - public void fill(Result result, String summaryClass, CompressionType compression) { + public void fill(Result result, String summaryClass, DocumentDatabase documentDb, CompressionType compression) { try { ListMap<Integer, FastHit> hitsByNode = hitsByNode(result); + if (result.getQuery().getTraceLevel() >=3) + result.getQuery().trace("Sending " + hitsByNode.size() + " summary fetch RPC requests", 3); + GetDocsumsResponseReceiver responseReceiver = new GetDocsumsResponseReceiver(hitsByNode.size(), compressor, result); for (Map.Entry<Integer, List<FastHit>> nodeHits : hitsByNode.entrySet()) { sendGetDocsumsRequest(nodeHits.getKey(), nodeHits.getValue(), summaryClass, compression, result, responseReceiver); } - responseReceiver.processResponses(result.getQuery(), summaryClass); + responseReceiver.processResponses(result.getQuery(), summaryClass, documentDb); + result.hits().setSorted(false); + result.analyzeHits(); } catch (TimeoutException e) { result.hits().addError(ErrorMessage.createTimeout("Summary data is incomplete: " + e.getMessage())); @@ -192,7 +197,7 @@ public class Dispatcher extends AbstractComponent { * Call this from the dispatcher thread to initiate and complete processing of responses. * This will block until all responses are available and processed, or to timeout. */ - public void processResponses(Query query, String summaryClass) throws TimeoutException { + public void processResponses(Query query, String summaryClass, DocumentDatabase documentDb) throws TimeoutException { try { int skippedHits = 0; while (outstandingResponses > 0) { @@ -203,11 +208,12 @@ public class Dispatcher extends AbstractComponent { Client.GetDocsumsResponseOrError response = responses.poll(timeLeftMs, TimeUnit.MILLISECONDS); if (response == null) throwTimeout(); - skippedHits += processResponse(response); + skippedHits += processResponse(response, summaryClass, documentDb); outstandingResponses--; } if (skippedHits != 0) { - result.hits().addError(com.yahoo.search.result.ErrorMessage.createEmptyDocsums("Missing hit summary data for summary " + summaryClass + " for " + skippedHits + " hits")); + result.hits().addError(com.yahoo.search.result.ErrorMessage.createEmptyDocsums("Missing hit summary data for summary " + + summaryClass + " for " + skippedHits + " hits")); } } catch (InterruptedException e) { @@ -215,7 +221,9 @@ public class Dispatcher extends AbstractComponent { } } - private int processResponse(Client.GetDocsumsResponseOrError responseOrError) { + private int processResponse(Client.GetDocsumsResponseOrError responseOrError, + String summaryClass, + DocumentDatabase documentDb) { if (responseOrError.error().isPresent()) { if (hasReportedError) return 0; String error = responseOrError.error().get(); @@ -226,7 +234,7 @@ public class Dispatcher extends AbstractComponent { Client.GetDocsumsResponse response = responseOrError.response().get(); CompressionType compression = CompressionType.valueOf(response.compression()); byte[] slimeBytes = compressor.decompress(response.compressedSlimeBytes(), compression, response.uncompressedSize()); - return fill(response.hitsContext(), slimeBytes); + return fill(response.hitsContext(), summaryClass, documentDb, slimeBytes); } return 0; } @@ -241,7 +249,7 @@ public class Dispatcher extends AbstractComponent { }); } - private int fill(List<FastHit> hits, byte[] slimeBytes) { + private int fill(List<FastHit> hits, String summaryClass, DocumentDatabase documentDb, byte[] slimeBytes) { com.yahoo.slime.Inspector root = BinaryFormat.decode(slimeBytes).get(); com.yahoo.slime.Inspector errors = root.field("errors"); boolean hasErrors = errors.valid() && (errors.entries() > 0); @@ -250,13 +258,14 @@ public class Dispatcher extends AbstractComponent { } Inspector summaries = new SlimeAdapter(root.field("docsums")); - if ( ! summaries.valid() && ! hasErrors) - throw new IllegalArgumentException("Expected a Slime root object containing a 'docsums' field"); + if ( ! summaries.valid()) + return 0; // No summaries; Perhaps we requested a non-existing summary class int skippedHits = 0; for (int i = 0; i < hits.size(); i++) { Inspector summary = summaries.entry(i).field("docsum"); if (summary.fieldCount() != 0) { - fill(hits.get(i), summary); + hits.get(i).addSummary(documentDb.getDocsumDefinitionSet().getDocsum(summaryClass), summary); + hits.get(i).setFilled(summaryClass); } else { skippedHits++; } @@ -264,27 +273,6 @@ public class Dispatcher extends AbstractComponent { return skippedHits; } - private void fill(FastHit hit, Inspector summary) { - hit.reserve(summary.fieldCount()); - summary.traverse((String name, Inspector value) -> { - hit.setField(name, nativeTypeOf(value)); - }); - } - - private Object nativeTypeOf(Inspector inspector) { - switch (inspector.type()) { - case ARRAY: return inspector; - case OBJECT: return inspector; - case BOOL: return inspector.asBool(); - case DATA: return inspector.asData(); - case DOUBLE: return inspector.asDouble(); - case LONG: return inspector.asLong(); - case STRING: return inspector.asString(); // TODO: Keep as utf8 - case EMPTY : return null; - default: throw new IllegalArgumentException("Unexpected Slime type " + inspector.type()); - } - } - } } 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 60f2691aa69..9b2a24cd01f 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 @@ -41,7 +41,6 @@ import java.util.stream.Collectors; * * @author bratseth */ -@Beta public class SearchCluster implements NodeManager<SearchCluster.Node> { private static final Logger log = Logger.getLogger(SearchCluster.class.getName()); diff --git a/container-search/src/main/java/com/yahoo/search/grouping/request/LongValue.java b/container-search/src/main/java/com/yahoo/search/grouping/request/LongValue.java index aa2de1a1298..2f5d833a5be 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/request/LongValue.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/request/LongValue.java @@ -4,16 +4,17 @@ package com.yahoo.search.grouping.request; /** * This class represents a constant {@link Long} value in a {@link GroupingExpression}. * - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ public class LongValue extends ConstantValue<Long> { /** * Constructs a new instance of this class. * - * @param value The immutable value to assign to this. + * @param value the immutable value to assign to this. */ public LongValue(long value) { super(value); } + } diff --git a/container-search/src/main/java/com/yahoo/search/result/Hit.java b/container-search/src/main/java/com/yahoo/search/result/Hit.java index 6adbac56dbe..076e6659d2b 100644 --- a/container-search/src/main/java/com/yahoo/search/result/Hit.java +++ b/container-search/src/main/java/com/yahoo/search/result/Hit.java @@ -89,10 +89,10 @@ public class Hit extends ListenableFreezableClass implements Data, Comparable<Hi * Set to true for hits which does not contain content, * but which contains meta information about the query or result */ - private boolean meta=false; + private boolean meta = false; /** If this is true, then this hit will not be counted as a concrete hit */ - private boolean auxiliary=false; + private boolean auxiliary = false; /** * The hit field used to store rank features. TODO: Remove on Vespa 7 @@ -403,16 +403,13 @@ public class Hit extends ListenableFreezableClass implements Data, Comparable<Hi //TODO Should it be deprecated ? public final Map<String,Object> fields() { return getUnmodifiableFieldMap(); } - /** - * Will preallocate in order to avoid resizing. - * @param minSize The minimum size to reserve - */ + /** Aallocate room for the given number of fields to avoid resizing. */ public void reserve(int minSize) { getFieldMap(minSize); } /** - * Fields + * Returns an iterator over the fields of this * * @return an iterator for traversing the fields of this hit */ @@ -663,9 +660,7 @@ public class Hit extends ListenableFreezableClass implements Data, Comparable<Hi if (p == null) { return null; } else if (p instanceof HitField) { - HitField hf = (HitField) p; - - return hf.quotedContent(false); + return ((HitField)p).quotedContent(false); } else if (p instanceof StructuredData) { return p.toString(); } else if (p instanceof XMLString || p instanceof JSONString) { @@ -743,9 +738,10 @@ public class Hit extends ListenableFreezableClass implements Data, Comparable<Hi } /** - * For vespa internal use only. + * For internal use only. * Gives access to the modifiable backing set of filled summaries. * This set might be unmodifiable if the size is less than or equal to 1 + * * @return the set of filled summaries. */ protected final Set<String> getFilledInternal() { @@ -755,6 +751,7 @@ public class Hit extends ListenableFreezableClass implements Data, Comparable<Hi private Map<String,Object> getFieldMap() { return getFieldMap(16); } + private Map<String,Object> getFieldMap(int minSize) { if (fields == null) { // Compensate for loadfactor and then some, rounded up.... diff --git a/container-search/src/main/java/com/yahoo/search/result/HitGroup.java b/container-search/src/main/java/com/yahoo/search/result/HitGroup.java index 4f4dff6f395..cb3a9abffc4 100644 --- a/container-search/src/main/java/com/yahoo/search/result/HitGroup.java +++ b/container-search/src/main/java/com/yahoo/search/result/HitGroup.java @@ -583,8 +583,7 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable< Collections.sort(hits); hitsSorted = true; } else { - // This may or may not lead to a sorted result set, but - // it's a best effort + // This may or may not lead to a sorted result set, but it's a best effort hitOrderer.order(hits); if (likelyHitsHaveCorrectValueForSortFields()) { hitsSorted = true; diff --git a/container-search/src/main/java/com/yahoo/search/result/NanNumber.java b/container-search/src/main/java/com/yahoo/search/result/NanNumber.java index 2103583dfa0..078ac04f85e 100644 --- a/container-search/src/main/java/com/yahoo/search/result/NanNumber.java +++ b/container-search/src/main/java/com/yahoo/search/result/NanNumber.java @@ -4,14 +4,14 @@ package com.yahoo.search.result; /** * A class representing unset or undefined numeric values. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ @SuppressWarnings("serial") public final class NanNumber extends Number { + public static final NanNumber NaN = new NanNumber(); - private NanNumber() { - } + private NanNumber() { } @Override public double doubleValue() { diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/DocsumDefinitionTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/DocsumDefinitionTestCase.java index 1abfea268f2..b0bbdda32df 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/DocsumDefinitionTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/DocsumDefinitionTestCase.java @@ -47,7 +47,7 @@ public class DocsumDefinitionTestCase { } assertEquals(7, set.size()); - DocsumDefinition docsum0 = set.getDocsumDefinition("default"); + DocsumDefinition docsum0 = set.getDocsum("default"); assertNotNull(docsum0); assertEquals("default", docsum0.getName()); diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java index 20150fc2671..3cfd8b337fc 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java @@ -4,6 +4,7 @@ package com.yahoo.prelude.fastsearch.test; import com.google.common.collect.ImmutableList; import com.yahoo.component.chain.Chain; import com.yahoo.config.subscription.ConfigGetter; +import com.yahoo.container.handler.VipStatus; import com.yahoo.container.search.Fs4Config; import com.yahoo.fs4.mplex.*; import com.yahoo.fs4.test.QueryTestCase; @@ -14,6 +15,7 @@ import com.yahoo.prelude.fastsearch.DocumentdbInfoConfig; import com.yahoo.container.protect.Error; import com.yahoo.fs4.*; import com.yahoo.prelude.fastsearch.test.fs4mock.MockBackend; +import com.yahoo.prelude.fastsearch.test.fs4mock.MockFS4ResourcePool; import com.yahoo.prelude.fastsearch.test.fs4mock.MockFSChannel; import com.yahoo.processing.execution.Execution.Trace; import com.yahoo.search.Query; @@ -111,30 +113,45 @@ public class FastSearcherTestCase { .summaryclass(new DocumentdbInfoConfig.Documentdb.Summaryclass.Builder().name("simple").id(7)) .rankprofile(new DocumentdbInfoConfig.Documentdb.Rankprofile.Builder() .name("simpler").hasRankFeatures(false).hasSummaryFeatures(false)))); + + List<SearchCluster.Node> nodes = new ArrayList<>(); + nodes.add(new SearchCluster.Node("host1", 5000, 0)); + nodes.add(new SearchCluster.Node("host2", 5000, 0)); + + MockFS4ResourcePool mockFs4ResourcePool = new MockFS4ResourcePool(); FastSearcher fastSearcher = new FastSearcher(new MockBackend(), - new FS4ResourcePool(1), - new MockDispatcher(Collections.emptyList()), + mockFs4ResourcePool, + new MockDispatcher(nodes, mockFs4ResourcePool, 1, new VipStatus()), new SummaryParameters(null), new ClusterParams("testhittype"), - new CacheParams(100, 1e64), + new CacheParams(0, 0), documentdbConfigWithOneDb); - String query = "?query=sddocname:a&dispatch.summaries"; - Result result = doSearch(fastSearcher,new Query(query), 0, 10); - ErrorMessage message = result.hits().getError(); - - assertNotNull("Got error", message); - assertEquals("Invalid query parameter", message.getMessage()); - assertEquals("When using dispatch.summaries and your summary/rankprofile require the query, you need to enable ranking.queryCache.", message.getDetailedMessage()); - assertEquals(Error.INVALID_QUERY_PARAMETER.code, message.getCode()); + { // No direct.summaries + String query = "?query=sddocname:a&summary=simple"; + Result result = doSearch(fastSearcher, new Query(query), 0, 10); + doFill(fastSearcher, result); + ErrorMessage error = result.hits().getError(); + assertNull("Since we don't route to the dispatcher we hit the mock backend, so no error", error); + } - query = "?query=sddocname:a&dispatch.summaries&ranking.queryCache"; - result = doSearch(fastSearcher,new Query(query), 0, 10); - assertNull(result.hits().getError()); + { // direct.summaries due to query cache + String query = "?query=sddocname:a&ranking.queryCache"; + Result result = doSearch(fastSearcher, new Query(query), 0, 10); + doFill(fastSearcher, result); + ErrorMessage error = result.hits().getError(); + assertEquals("Since we don't actually run summary backends we get this error when the Dispatcher is used", + "Error response from rpc node connection to host1:0: Connection error", error.getDetailedMessage()); + } - query = "?query=sddocname:a&dispatch.summaries&summary=simple&ranking=simpler"; - result = doSearch(fastSearcher,new Query(query), 0, 10); - assertNull(result.hits().getError()); + { // direct.summaries due to no summary features + String query = "?query=sddocname:a&dispatch.summaries&summary=simple&ranking=simpler"; + Result result = doSearch(fastSearcher, new Query(query), 0, 10); + doFill(fastSearcher, result); + ErrorMessage error = result.hits().getError(); + assertEquals("Since we don't actually run summary backends we get this error when the Dispatcher is used", + "Error response from rpc node connection to host1:0: Connection error", error.getDetailedMessage()); + } } @Test @@ -281,7 +298,7 @@ public class FastSearcherTestCase { assertEquals(100, fastSearcher.getCacheControl().capacity()); // Default cache =100MB - Query query = new Query("?query=ignored"); + Query query = new Query("?query=ignored&dispatch.summaries=false"); query.getRanking().setQueryCache(true); Result result = doSearch(fastSearcher, query, 0, 10); @@ -321,7 +338,6 @@ public class FastSearcherTestCase { answer.flip(); answer.get(expected); - assertEquals(expected.length, actual.length); for (int i = 0; i < expected.length; ++i) { if (expected[i] == IGNORE) { actual[i] = IGNORE; diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/fs4mock/MockFSChannel.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/fs4mock/MockFSChannel.java index 8d705406774..37a74831e56 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/fs4mock/MockFSChannel.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/fs4mock/MockFSChannel.java @@ -96,13 +96,13 @@ public class MockFSChannel extends FS4Channel { && lastQueryPacket.getLastOffset() >= 1) { result.addDocument( new DocumentInfo(DocsumDefinitionTestCase.createGlobalId(123), - 2003, 234, 1000)); + 2003, 234, 0)); } if (lastQueryPacket.getOffset() <= 1 && lastQueryPacket.getLastOffset() >= 2) { result.addDocument( new DocumentInfo(DocsumDefinitionTestCase.createGlobalId(456), - 1855, 234, 1001)); + 1855, 234, 1)); } packets.add(result); } diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/FillTestCase.java b/container-search/src/test/java/com/yahoo/search/dispatch/FillTestCase.java index 9938498fa1a..ed421be1947 100644 --- a/container-search/src/test/java/com/yahoo/search/dispatch/FillTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/dispatch/FillTestCase.java @@ -2,6 +2,11 @@ package com.yahoo.search.dispatch; import com.yahoo.compress.CompressionType; +import com.yahoo.log.event.Collection; +import com.yahoo.prelude.fastsearch.DocsumDefinition; +import com.yahoo.prelude.fastsearch.DocsumDefinitionSet; +import com.yahoo.prelude.fastsearch.DocsumField; +import com.yahoo.prelude.fastsearch.DocumentDatabase; import com.yahoo.prelude.fastsearch.FastHit; import com.yahoo.search.Query; import com.yahoo.search.Result; @@ -10,7 +15,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; @@ -44,7 +52,8 @@ public class FillTestCase { client.setDocsumReponse("host1", 2, "summaryClass1", map("field1", "s.1.2", "field2", 2)); client.setDocsumReponse("host2", 3, "summaryClass1", map("field1", "s.2.3", "field2", 3)); client.setDocsumReponse("host0", 4, "summaryClass1", map("field1", "s.0.4", "field2", 4)); - dispatcher.fill(result, "summaryClass1", CompressionType.valueOf("LZ4")); + + dispatcher.fill(result, "summaryClass1", db(), CompressionType.valueOf("LZ4")); assertEquals("s.0.0", result.hits().get("hit:0").getField("field1").toString()); assertEquals("s.2.1", result.hits().get("hit:1").getField("field1").toString()); @@ -79,7 +88,7 @@ public class FillTestCase { client.setDocsumReponse("host1", 2, "summaryClass1", new HashMap<>()); client.setDocsumReponse("host2", 3, "summaryClass1", map("field1", "s.2.3", "field2", 3)); client.setDocsumReponse("host0", 4, "summaryClass1",new HashMap<>()); - dispatcher.fill(result, "summaryClass1", CompressionType.valueOf("LZ4")); + dispatcher.fill(result, "summaryClass1", db(), CompressionType.valueOf("LZ4")); assertEquals("s.0.0", result.hits().get("hit:0").getField("field1").toString()); assertEquals("s.2.1", result.hits().get("hit:1").getField("field1").toString()); @@ -108,11 +117,20 @@ public class FillTestCase { Result result = new Result(query); result.hits().add(createHit(0, 0)); - dispatcher.fill(result, "summaryClass1", CompressionType.valueOf("LZ4")); + dispatcher.fill(result, "summaryClass1", db(), CompressionType.valueOf("LZ4")); assertEquals("Malfunctioning", result.hits().getError().getDetailedMessage()); } + private DocumentDatabase db() { + List<DocsumField> fields = new ArrayList<>(); + fields.add(DocsumField.create("field1", "string")); + fields.add(DocsumField.create("field2", "int64")); + DocsumDefinitionSet docsums = new DocsumDefinitionSet(Collections.singleton(new DocsumDefinition("summaryClass1", + fields))); + return new DocumentDatabase("default", docsums, Collections.emptySet()); + } + private FastHit createHit(int sourceNodeId, int hitId) { FastHit hit = new FastHit("hit:" + hitId, 1.0); hit.setPartId(sourceNodeId, 0); diff --git a/vespajlib/src/main/java/com/yahoo/text/XML.java b/vespajlib/src/main/java/com/yahoo/text/XML.java index 30f30b2a270..f4cd355b0e1 100644 --- a/vespajlib/src/main/java/com/yahoo/text/XML.java +++ b/vespajlib/src/main/java/com/yahoo/text/XML.java @@ -28,17 +28,18 @@ import org.xml.sax.SAXParseException; * @author Steinar Knutsen */ public class XML { + /** * The point of this weird class and the jumble of abstract methods is * linking the scan for characters that must be quoted into the quoting * table, and making it actual work to make them go out of sync again. */ private static abstract class LegalCharacters { + // To quote http://www.w3.org/TR/REC-xml/ : // Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | // [#x10000-#x10FFFF] - final boolean isLegal(final int codepoint, final boolean escapeLow, - final int stripCodePoint, final boolean isAttribute) { + final boolean isLegal(int codepoint, boolean escapeLow, int stripCodePoint, boolean isAttribute) { if (codepoint == stripCodePoint) { return removeCodePoint(); } else if (codepoint < ' ') { @@ -75,7 +76,7 @@ public class XML { } } - private boolean quotCodePoint(final boolean isAttribute) { + private boolean quotCodePoint(boolean isAttribute) { if (isAttribute) { quoteQuot(); return false; @@ -84,7 +85,7 @@ public class XML { } } - private boolean filterCodePoint(final int codepoint) { + private boolean filterCodePoint(int codepoint) { replace(codepoint); return false; } @@ -104,7 +105,7 @@ public class XML { return false; } - private boolean ctrlEscapeCodePoint(final int codepoint) { + private boolean ctrlEscapeCodePoint(int codepoint) { ctrlEscape(codepoint); return false; } @@ -349,8 +350,7 @@ public class XML { * </ul> * with character entities. * - * @param stripCodePoint - * any occurrence of this character is removed from the string + * @param stripCodePoint any occurrence of this character is removed from the string */ public static String xmlEscape(String string, boolean isAttribute, boolean escapeLowAscii, StringBuilder buffer, int stripCodePoint) { @@ -399,8 +399,7 @@ public class XML { /** * Returns the Document of an XML file reader * - * @throws RuntimeException - * if the root Document cannot be returned + * @throws RuntimeException if the root Document cannot be returned */ public static Document getDocument(Reader reader) { try { |