diff options
author | Geir Storli <geirstorli@yahoo.no> | 2017-11-23 16:31:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-23 16:31:06 +0100 |
commit | 81226e4673d4291e82d8119b0ddf83ca23071fa4 (patch) | |
tree | 94f5f79ed49366daa70a9ee1f52041ababb31cfb /config-model | |
parent | 75d658556fdee38cac7160beb68a74f0bdf0f660 (diff) | |
parent | aeb5055a0093675a9f0099c31706529a55a9a1d3 (diff) |
Merge pull request #4255 from vespa-engine/geirst/produce-new-bucket-spaces-config-for-distributor-nodes
Produce new bucket spaces config for distributor nodes.
Diffstat (limited to 'config-model')
3 files changed, 59 insertions, 7 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/DistributorCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/content/DistributorCluster.java index 2bfa8fa93a0..81aca977400 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/content/DistributorCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/content/DistributorCluster.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.content; +import com.yahoo.documentmodel.NewDocumentType; +import com.yahoo.vespa.config.content.core.BucketspacesConfig; import com.yahoo.vespa.config.content.core.StorDistributormanagerConfig; import com.yahoo.vespa.config.content.core.StorServerConfig; import com.yahoo.document.select.DocumentSelector; @@ -18,11 +20,15 @@ import java.util.logging.Logger; /** * Generates distributor-specific configuration. */ -public class DistributorCluster extends AbstractConfigProducer<Distributor> - implements StorDistributormanagerConfig.Producer, StorServerConfig.Producer, MetricsmanagerConfig.Producer { +public class DistributorCluster extends AbstractConfigProducer<Distributor> implements + StorDistributormanagerConfig.Producer, + StorServerConfig.Producer, + MetricsmanagerConfig.Producer, + BucketspacesConfig.Producer { public static final Logger log = Logger.getLogger(DistributorCluster.class.getPackage().toString()); + private static class GcOptions { public final int interval; public final String selection; @@ -145,6 +151,20 @@ public class DistributorCluster extends AbstractConfigProducer<Distributor> builder.is_distributor(true); } + private static final String DEFAULT_BUCKET_SPACE = "default"; + private static final String GLOBAL_BUCKET_SPACE = "global"; + + @Override + public void getConfig(BucketspacesConfig.Builder builder) { + for (NewDocumentType docType : parent.getDocumentDefinitions().values()) { + BucketspacesConfig.Documenttype.Builder docTypeBuilder = new BucketspacesConfig.Documenttype.Builder(); + docTypeBuilder.name(docType.getName()); + String bucketSpace = (parent.isGloballyDistributed(docType) ? GLOBAL_BUCKET_SPACE : DEFAULT_BUCKET_SPACE); + docTypeBuilder.bucketspace(bucketSpace); + builder.documenttype(docTypeBuilder); + } + } + public String getClusterName() { return parent.getName(); } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java index 6e82379d00b..16b0674fc14 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/content/cluster/ContentCluster.java @@ -531,6 +531,10 @@ public class ContentCluster extends AbstractConfigProducer implements StorDistri */ public Map<String, NewDocumentType> getDocumentDefinitions() { return documentDefinitions; } + public boolean isGloballyDistributed(NewDocumentType docType) { + return globallyDistributedDocuments.contains(docType); + } + public final ContentSearchCluster getSearch() { return search; } public Redundancy redundancy() { return redundancy; } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/DistributorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/content/DistributorTest.java index 624d3e8ded8..d4e804d3f95 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/DistributorTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/DistributorTest.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.vespa.model.content; +import com.yahoo.vespa.config.content.core.BucketspacesConfig; import com.yahoo.vespa.config.content.core.StorCommunicationmanagerConfig; import com.yahoo.vespa.config.content.core.StorDistributormanagerConfig; import com.yahoo.vespa.config.content.core.StorServerConfig; @@ -305,22 +306,28 @@ public class DistributorTest { private static class DocDef { public final String type; public final String mode; + public final boolean global; - private DocDef(String type, String mode) { + private DocDef(String type, String mode, boolean global) { this.type = type; this.mode = mode; + this.global = global; } public static DocDef storeOnly(String type) { - return new DocDef(type, "store-only"); + return new DocDef(type, "store-only", false); } public static DocDef index(String type) { - return new DocDef(type, "index"); + return new DocDef(type, "index", false); + } + + public static DocDef indexGlobal(String type) { + return new DocDef(type, "index", true); } public static DocDef streaming(String type) { - return new DocDef(type, "streaming"); + return new DocDef(type, "streaming", false); } } @@ -328,7 +335,8 @@ public class DistributorTest { return "<content id='storage'>\n" + " <documents>\n" + Arrays.stream(defs) - .map(def -> String.format(" <document type='%s' mode='%s'/>", def.type, def.mode)) + .map(def -> String.format(" <document type='%s' mode='%s' global='%s'/>", + def.type, def.mode, (def.global ? "true" : "false"))) .collect(Collectors.joining("\n")) + "\n </documents>\n" + "</content>"; @@ -371,4 +379,24 @@ public class DistributorTest { generateXmlForDocDefs(DocDef.streaming("music"))); assertThat(config.disable_bucket_activation(), is(true)); } + + private BucketspacesConfig clusterXmlToBucketspacesConfig(String xml) { + BucketspacesConfig.Builder builder = new BucketspacesConfig.Builder(); + parse(xml).getConfig(builder); + return new BucketspacesConfig(builder); + } + + private void assertDocumentType(String expName, String expBucketSpace, BucketspacesConfig.Documenttype docType) { + assertEquals(expName, docType.name()); + assertEquals(expBucketSpace, docType.bucketspace()); + } + + @Test + public void bucket_spaces_config_is_produced_for_distributor_cluster() { + BucketspacesConfig config = clusterXmlToBucketspacesConfig( + generateXmlForDocDefs(DocDef.index("music"), DocDef.indexGlobal("movies"))); + assertEquals(2, config.documenttype().size()); + assertDocumentType("movies", "global", config.documenttype(0)); + assertDocumentType("music", "default", config.documenttype(1)); + } } |