diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2020-11-04 14:34:50 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2020-11-04 14:34:50 +0100 |
commit | bdd6068f43504027bc4bf2a04708486cc8ccbcb9 (patch) | |
tree | 49ebf1f9410c7092fdb4d280a95204f2678bd167 /config-model | |
parent | 8b5422be3a3e339540573fbed8063636644af603 (diff) |
Detect doctypes changing indexing-mode 'indexed' <=> 'store-only'
Diffstat (limited to 'config-model')
2 files changed, 63 insertions, 41 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/change/IndexingModeChangeValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/change/IndexingModeChangeValidator.java index 0b907b43203..e3f16baf95a 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/change/IndexingModeChangeValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/change/IndexingModeChangeValidator.java @@ -40,45 +40,54 @@ public class IndexingModeChangeValidator implements ChangeValidator { return actions; } - private List<ConfigChangeAction> validateContentCluster( + private static List<ConfigChangeAction> validateContentCluster( ContentCluster currentCluster, ContentCluster nextCluster, ValidationOverrides overrides, Instant now) { - List<ConfigChangeAction> changes = new ArrayList<>(); + List<ConfigChangeAction> actions = new ArrayList<>(); ContentSearchCluster currentSearchCluster = currentCluster.getSearch(); ContentSearchCluster nextSearchCluster = nextCluster.getSearch(); - { - Set<String> currentStreamingTypes = toDocumentTypeNames(currentSearchCluster.getDocumentTypesWithStreamingCluster()); - Set<String> nextIndexedTypes = toDocumentTypeNames(nextSearchCluster.getDocumentTypesWithIndexedCluster()); - for (String type : nextIndexedTypes) { - if (currentStreamingTypes.contains(type)) { - changes.add(createReindexAction(overrides, now, nextCluster, type, "streaming", "indexed")); - } - } - } - { - Set<String> currentIndexedTypes = toDocumentTypeNames(currentSearchCluster.getDocumentTypesWithIndexedCluster()); - Set<String> nextStreamingTypes = toDocumentTypeNames(nextSearchCluster.getDocumentTypesWithStreamingCluster()); - for (String type : nextStreamingTypes) { - if (currentIndexedTypes.contains(type)) { - changes.add(createReindexAction(overrides, now, nextCluster, type, "indexed", "streaming")); - } - } - } - return changes; + findDocumentTypesWithActionableIndexingModeChange( + actions, overrides, nextCluster, now, + toDocumentTypeNames(currentSearchCluster.getDocumentTypesWithStreamingCluster()), + toDocumentTypeNames(nextSearchCluster.getDocumentTypesWithIndexedCluster()), + "streaming", "indexed"); + findDocumentTypesWithActionableIndexingModeChange( + actions, overrides, nextCluster, now, + toDocumentTypeNames(currentSearchCluster.getDocumentTypesWithIndexedCluster()), + toDocumentTypeNames(nextSearchCluster.getDocumentTypesWithStreamingCluster()), + "indexed", "streaming"); + findDocumentTypesWithActionableIndexingModeChange( + actions, overrides, nextCluster, now, + toDocumentTypeNames(currentSearchCluster.getDocumentTypesWithStoreOnly()), + toDocumentTypeNames(nextSearchCluster.getDocumentTypesWithIndexedCluster()), + "store-only", "indexed"); + findDocumentTypesWithActionableIndexingModeChange( + actions, overrides, nextCluster, now, + toDocumentTypeNames(currentSearchCluster.getDocumentTypesWithIndexedCluster()), + toDocumentTypeNames(nextSearchCluster.getDocumentTypesWithStoreOnly()), + "indexed", "store-only"); + return actions; } - private static VespaReindexAction createReindexAction( - ValidationOverrides overrides, Instant now, ContentCluster nextCluster, String documentType, String indexModeFrom, String indexModeTo) { - List<ServiceInfo> services = nextCluster.getSearch().getSearchNodes().stream() - .map(SearchNode::getServiceInfo) - .collect(Collectors.toList()); - return VespaReindexAction.of( - nextCluster.id(), - ValidationId.indexModeChange.value(), - overrides, - String.format("Document type '%s' in cluster '%s' changed indexing mode from '%s' to '%s'", documentType, nextCluster.getName(), indexModeFrom, indexModeTo), - services, - documentType, - now); + private static void findDocumentTypesWithActionableIndexingModeChange( + List<ConfigChangeAction> actions, ValidationOverrides overrides, ContentCluster nextCluster, Instant now, + Set<String> currentTypes, Set<String> nextTypes, String currentIndexMode, String nextIndexingMode) { + for (String type : nextTypes) { + if (currentTypes.contains(type)) { + List<ServiceInfo> services = nextCluster.getSearch().getSearchNodes().stream() + .map(SearchNode::getServiceInfo) + .collect(Collectors.toList()); + actions.add(VespaReindexAction.of( + nextCluster.id(), + ValidationId.indexModeChange.value(), + overrides, + String.format( + "Document type '%s' in cluster '%s' changed indexing mode from '%s' to '%s'", + type, nextCluster.getName(), currentIndexMode, nextIndexingMode), + services, + type, + now)); + } + } } private static Set<String> toDocumentTypeNames(List<NewDocumentType> types) { diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/IndexingModeChangeValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/IndexingModeChangeValidatorTest.java index 70995a40181..8e2cecf89b4 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/IndexingModeChangeValidatorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/change/IndexingModeChangeValidatorTest.java @@ -6,7 +6,6 @@ import com.yahoo.config.model.api.ConfigChangeReindexAction; import com.yahoo.config.provision.Environment; import com.yahoo.vespa.model.VespaModel; import com.yahoo.vespa.model.application.validation.ValidationTester; -import com.yahoo.vespa.model.search.AbstractSearchCluster; import org.junit.Test; import java.util.List; @@ -17,23 +16,38 @@ import static org.junit.Assert.assertTrue; /** * @author bratseth + * @author bjorncs */ public class IndexingModeChangeValidatorTest { @Test - public void testChangingIndexMode() { + public void testChangingIndexModeFromIndexedToStreaming() { ValidationTester tester = new ValidationTester(); VespaModel oldModel = - tester.deploy(null, getServices(AbstractSearchCluster.IndexingMode.REALTIME), Environment.prod, validationOverrides).getFirst(); + tester.deploy(null, getServices("index"), Environment.prod, validationOverrides).getFirst(); List<ConfigChangeAction> changeActions = - tester.deploy(oldModel, getServices(AbstractSearchCluster.IndexingMode.STREAMING), Environment.prod, validationOverrides).getSecond(); + tester.deploy(oldModel, getServices("streaming"), Environment.prod, validationOverrides).getSecond(); assertReindexingChange(true, // allowed=true due to validation override "Document type 'music' in cluster 'default' changed indexing mode from 'indexed' to 'streaming'", changeActions); } + @Test + public void testChangingIndexModeFromStoreOnlyToIndexed() { + ValidationTester tester = new ValidationTester(); + + VespaModel oldModel = + tester.deploy(null, getServices("index"), Environment.prod, validationOverrides).getFirst(); + List<ConfigChangeAction> changeActions = + tester.deploy(oldModel, getServices("store-only"), Environment.prod, validationOverrides).getSecond(); + + assertReindexingChange(true, // allowed=true due to validation override + "Document type 'music' in cluster 'default' changed indexing mode from 'indexed' to 'store-only'", + changeActions); + } + private void assertReindexingChange(boolean allowed, String message, List<ConfigChangeAction> changeActions) { List<ConfigChangeAction> reindexingActions = changeActions.stream() .filter(a -> a instanceof ConfigChangeReindexAction) @@ -45,13 +59,12 @@ public class IndexingModeChangeValidatorTest { assertEquals(message, reindexingActions.get(0).getMessage()); } - private static final String getServices(AbstractSearchCluster.IndexingMode indexingMode) { + private static final String getServices(String indexingMode) { return "<services version='1.0'>" + " <content id='default' version='1.0'>" + " <redundancy>1</redundancy>" + " <documents>" + - " <document type='music' mode='" + - (indexingMode.equals(AbstractSearchCluster.IndexingMode.REALTIME) ? "index" : "streaming") + "'/>" + + " <document type='music' mode='" + indexingMode + "'/>" + " </documents>" + " <nodes count='1'/>" + " </content>" + |