diff options
author | Frode Lundgren <frodelu@verizonmedia.com> | 2021-01-15 21:43:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-15 21:43:23 +0100 |
commit | ed3116a4b2a90f15f379bb8bf4298cb7480e7b42 (patch) | |
tree | dc06bdbdf3e9c095ebfd9316099d6ae70231a393 | |
parent | dfeaed2d8926952e1898f5d75df2a4e83a2a5ff2 (diff) | |
parent | ed79699c3758a7dd6483492d8f7bcccb2882fd17 (diff) |
Merge pull request #16071 from vespa-engine/jonmv/add-document-types-to-Model
Move logic for indexed document types inside config model api wrapping
5 files changed, 51 insertions, 41 deletions
diff --git a/config-model-api/src/main/java/com/yahoo/config/model/api/Model.java b/config-model-api/src/main/java/com/yahoo/config/model/api/Model.java index 36479c7504a..f98d72374bf 100644 --- a/config-model-api/src/main/java/com/yahoo/config/model/api/Model.java +++ b/config-model-api/src/main/java/com/yahoo/config/model/api/Model.java @@ -10,6 +10,7 @@ import com.yahoo.vespa.config.ConfigPayload; import com.yahoo.vespa.config.buildergen.ConfigDefinition; import java.time.Instant; +import java.util.Map; import java.util.Set; import java.util.Collection; @@ -80,4 +81,10 @@ public interface Model { /** Returns the provisioned hosts of this. */ default Provisioned provisioned() { return new Provisioned(); } + /** Returns the set of document types in each content cluster. */ + default Map<String, Set<String>> documentTypesByCluster() { return Map.of(); } + + /** Returns the set of document types in each cluster, that have an index for one of more fields. */ + default Map<String, Set<String>> indexedDocumentTypesByCluster() { return Map.of(); } + } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java b/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java index acb4f58655d..660c47d037d 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/VespaModel.java @@ -35,6 +35,7 @@ import com.yahoo.searchdefinition.RankProfileRegistry; import com.yahoo.searchdefinition.RankingConstants; import com.yahoo.searchdefinition.derived.AttributeFields; import com.yahoo.searchdefinition.derived.RankProfileList; +import com.yahoo.searchdefinition.document.SDField; import com.yahoo.searchdefinition.processing.Processing; import com.yahoo.vespa.config.ConfigDefinitionKey; import com.yahoo.vespa.config.ConfigKey; @@ -81,6 +82,10 @@ import java.util.stream.Collectors; import static com.yahoo.config.codegen.ConfiggenUtil.createClassName; import static com.yahoo.text.StringUtilities.quote; +import static java.util.stream.Collectors.toMap; +import static java.util.stream.Collectors.toSet; +import static java.util.stream.Collectors.toUnmodifiableMap; +import static java.util.stream.Collectors.toUnmodifiableSet; /** * <p> @@ -202,6 +207,38 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri } + @Override + public Map<String, Set<String>> documentTypesByCluster() { + return getContentClusters().entrySet().stream() + .collect(toMap(cluster -> cluster.getKey(), + cluster -> cluster.getValue().getDocumentDefinitions().keySet())); + } + + @Override + public Map<String, Set<String>> indexedDocumentTypesByCluster() { + return getContentClusters().entrySet().stream() + .collect(toUnmodifiableMap(cluster -> cluster.getKey(), + cluster -> documentTypesWithIndex(cluster.getValue()))); + } + + private static Set<String> documentTypesWithIndex(ContentCluster content) { + Set<String> typesWithIndexMode = content.getSearch().getDocumentTypesWithIndexedCluster().stream() + .map(type -> type.getFullName().getName()) + .collect(toSet()); + + Set<String> typesWithIndexedFields = content.getSearch().getIndexed() == null + ? Set.of() + : content.getSearch().getIndexed().getDocumentDbs().stream() + .filter(database -> database.getDerivedConfiguration() + .getSearch() + .allConcreteFields() + .stream().anyMatch(SDField::doesIndexing)) + .map(database -> database.getInputDocType()) + .collect(toSet()); + + return typesWithIndexMode.stream().filter(typesWithIndexedFields::contains).collect(toUnmodifiableSet()); + } + private void propagateRestartOnDeploy() { if (applicationPackage.getMetaData().isInternalRedeploy()) return; @@ -632,6 +669,4 @@ public final class VespaModel extends AbstractConfigProducerRoot implements Seri .collect(Collectors.toSet()); } - - } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationReindexing.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationReindexing.java index 1736b23012d..c603b4af6a5 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationReindexing.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationReindexing.java @@ -50,40 +50,6 @@ public class ApplicationReindexing implements Reindexing { return new ApplicationReindexing(true, new Status(now), Map.of()); } - /** Returns the set of document types in each content cluster, in the given application */ - public static Map<String, Set<String>> documentTypes(Application application) { - Map<String, ContentCluster> contentClusters = ((VespaModel) application.getModel()).getContentClusters(); - return contentClusters.entrySet().stream() - .collect(toMap(cluster -> cluster.getKey(), - cluster -> cluster.getValue().getDocumentDefinitions().keySet())); - } - - /** Returns the set of document types in each cluster, in the given application, that have an index for one of more fields. */ - public static Map<String, Set<String>> documentTypesWithIndex(Application application) { - Map<String, ContentCluster> contentClusters = ((VespaModel) application.getModel()).getContentClusters(); - return contentClusters.entrySet().stream() - .collect(toUnmodifiableMap(cluster -> cluster.getKey(), - cluster -> documentTypesWithIndex(cluster.getValue()))); - } - - private static Set<String> documentTypesWithIndex(ContentCluster content) { - Set<String> typesWithIndexMode = content.getSearch().getDocumentTypesWithIndexedCluster().stream() - .map(type -> type.getFullName().getName()) - .collect(toSet()); - - Set<String> typesWithIndexedFields = content.getSearch().getIndexed() == null - ? Set.of() - : content.getSearch().getIndexed().getDocumentDbs().stream() - .filter(database -> database.getDerivedConfiguration() - .getSearch() - .allConcreteFields() - .stream().anyMatch(SDField::doesIndexing)) - .map(database -> database.getInputDocType()) - .collect(toSet()); - - return typesWithIndexMode.stream().filter(typesWithIndexedFields::contains).collect(toUnmodifiableSet()); - } - /** Returns a copy of this with reindexing for the whole application ready at the given instant. */ public ApplicationReindexing withReady(Instant readyAt) { return new ApplicationReindexing(enabled, diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java index 401823aa6cd..0da377d889b 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java @@ -28,6 +28,7 @@ import com.yahoo.vespa.config.server.http.HttpHandler; import com.yahoo.vespa.config.server.http.JSONResponse; import com.yahoo.vespa.config.server.http.NotFoundException; import com.yahoo.vespa.config.server.tenant.Tenant; +import com.yahoo.vespa.model.VespaModel; import java.io.IOException; import java.net.URLDecoder; @@ -232,10 +233,10 @@ public class ApplicationHandler extends HttpHandler { private HttpResponse triggerReindexing(HttpRequest request, ApplicationId applicationId) { Application application = applicationRepository.getActiveApplicationSet(applicationId) - .orElseThrow(() -> new NotFoundException(applicationId + " not found")) - .getForVersionOrLatest(Optional.empty(), applicationRepository.clock().instant()); - Map<String, Set<String>> documentTypes = ApplicationReindexing.documentTypes(application); - Map<String, Set<String>> indexedDocumentTypes = ApplicationReindexing.documentTypesWithIndex(application); + .orElseThrow(() -> new NotFoundException(applicationId + " not found")) + .getForVersionOrLatest(Optional.empty(), applicationRepository.clock().instant()); + Map<String, Set<String>> documentTypes = application.getModel().documentTypesByCluster(); + Map<String, Set<String>> indexedDocumentTypes = application.getModel().indexedDocumentTypesByCluster(); boolean indexedOnly = request.getBooleanProperty("indexedOnly"); Set<String> clusters = StringUtilities.split(request.getProperty("clusterId")); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ReindexingMaintainer.java b/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ReindexingMaintainer.java index 34e4a5becfb..971c2c20ae9 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ReindexingMaintainer.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/maintenance/ReindexingMaintainer.java @@ -11,6 +11,7 @@ import com.yahoo.vespa.config.server.application.ConfigConvergenceChecker; import com.yahoo.vespa.config.server.tenant.Tenant; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.flags.FlagSource; +import com.yahoo.vespa.model.VespaModel; import com.yahoo.yolean.Exceptions; import java.time.Clock; @@ -98,7 +99,7 @@ public class ReindexingMaintainer extends ConfigServerMaintainer { } static ApplicationReindexing withOnlyCurrentData(ApplicationReindexing reindexing, Application application) { - return withOnlyCurrentData(reindexing, ApplicationReindexing.documentTypes(application)); + return withOnlyCurrentData(reindexing, application.getModel().documentTypesByCluster()); } static ApplicationReindexing withOnlyCurrentData(ApplicationReindexing reindexing, Map<String, ? extends Collection<String>> clusterDocumentTypes) { |