diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2018-03-16 17:50:44 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@oath.com> | 2018-03-19 13:01:16 +0100 |
commit | 7d4570b514ada0bf92d0bc79f7ce3b8d050647f8 (patch) | |
tree | 4ae892973144b5a6054d60199f270fc62b9df00f /config-model | |
parent | 99c0278cfa2118fb26a4e13b8ede982cb6abf1fe (diff) |
No need for an array when you just need a count
Diffstat (limited to 'config-model')
3 files changed, 17 insertions, 73 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/PriorityMapping.java b/config-model/src/main/java/com/yahoo/vespa/model/content/PriorityMapping.java deleted file mode 100644 index e239c66f1cf..00000000000 --- a/config-model/src/main/java/com/yahoo/vespa/model/content/PriorityMapping.java +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.model.content; - -import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol; -import com.yahoo.vespa.model.builder.xml.dom.ModelElement; - -import java.util.HashMap; -import java.util.Map; - -/** - * Created with IntelliJ IDEA. - * User: thomasg - * Date: 5/7/12 - * Time: 2:00 PM - * To change this template use File | Settings | File Templates. - */ -public class PriorityMapping { - ModelElement clusterXml; - Map<DocumentProtocol.Priority, Integer> priorityMappings = new HashMap<>(); - - public PriorityMapping(ModelElement clusterXml) { - this.clusterXml = clusterXml; - - int val = 50; - for (DocumentProtocol.Priority p : DocumentProtocol.Priority.values()) { - priorityMappings.put(p, val); - val += 10; - } - priorityMappings.put(DocumentProtocol.Priority.HIGHEST, 0); - priorityMappings.put(DocumentProtocol.Priority.LOWEST, 255); - } - - public int getPriorityMapping(String priorityName) { - return priorityMappings.get(Enum.valueOf(DocumentProtocol.Priority.class, priorityName)); - } - -} diff --git a/config-model/src/main/java/com/yahoo/vespa/model/content/storagecluster/FileStorProducer.java b/config-model/src/main/java/com/yahoo/vespa/model/content/storagecluster/FileStorProducer.java index b4faa6eeb7e..0cc62fb6680 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/content/storagecluster/FileStorProducer.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/content/storagecluster/FileStorProducer.java @@ -3,12 +3,8 @@ package com.yahoo.vespa.model.content.storagecluster; import com.yahoo.vespa.config.content.StorFilestorConfig; import com.yahoo.vespa.model.builder.xml.dom.ModelElement; -import com.yahoo.vespa.model.content.PriorityMapping; import com.yahoo.vespa.model.content.cluster.ContentCluster; -import java.util.ArrayList; -import java.util.List; - /** * Serves stor-filestor for storage clusters. */ @@ -19,7 +15,7 @@ public class FileStorProducer implements StorFilestorConfig.Producer { return new FileStorProducer(parent, getThreads(clusterElem)); } - private List<StorFilestorConfig.Threads.Builder> getThreads(ModelElement clusterElem) { + private Integer getThreads(ModelElement clusterElem) { ModelElement tuning = clusterElem.getChild("tuning"); if (tuning == null) { return null; @@ -29,44 +25,34 @@ public class FileStorProducer implements StorFilestorConfig.Producer { return null; } - List<StorFilestorConfig.Threads.Builder> retVal = new ArrayList<>(); - - PriorityMapping mapping = new PriorityMapping(clusterElem); + Integer count = threads.getIntegerAttribute("count"); + if (count != null) { + return count; + } + // Backward compatible fallback + int numThreads = 0; for (ModelElement thread : threads.subElements("thread")) { - String priorityName = thread.getStringAttribute("lowest-priority"); - if (priorityName == null) { - priorityName = "LOWEST"; - } - - Integer count = thread.getIntegerAttribute("count"); - if (count == null) { - count = 1; - } - - for (int i = 0; i < count; ++i) { - retVal.add(new StorFilestorConfig.Threads.Builder().lowestpri(mapping.getPriorityMapping(priorityName))); - } + count = thread.getIntegerAttribute("count"); + numThreads += (count == null) ? 1 : count; } - return retVal; + return numThreads; } } - private List<StorFilestorConfig.Threads.Builder> threads; + private Integer numThreads; private ContentCluster cluster; - public FileStorProducer(ContentCluster parent, List<StorFilestorConfig.Threads.Builder> threads) { - this.threads = threads; + public FileStorProducer(ContentCluster parent, Integer numThreads) { + this.numThreads = numThreads; this.cluster = parent; } @Override public void getConfig(StorFilestorConfig.Builder builder) { - if (threads != null) { - for (StorFilestorConfig.Threads.Builder t : threads) { - builder.threads.add(t); - } + if (numThreads != null) { + builder.num_threads(numThreads); } builder.enable_multibit_split_optimalization(cluster.getPersistence().enableMultiLevelSplitting()); } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/content/StorageClusterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/content/StorageClusterTest.java index 0fae6c6d751..95da1516e80 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/content/StorageClusterTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/content/StorageClusterTest.java @@ -120,12 +120,7 @@ public class StorageClusterTest { StorFilestorConfig config = new StorFilestorConfig(builder); - assertEquals(4, config.threads().size()); - assertEquals(190, config.threads().get(0).lowestpri()); - assertEquals(190, config.threads().get(1).lowestpri()); - assertEquals(60, config.threads().get(2).lowestpri()); - assertEquals(255, config.threads().get(3).lowestpri()); - + assertEquals(4, config.num_threads()); assertEquals(true, config.enable_multibit_split_optimalization()); } @@ -145,7 +140,7 @@ public class StorageClusterTest { StorFilestorConfig config = new StorFilestorConfig(builder); - assertEquals(0, config.threads().size()); + assertEquals(6, config.num_threads()); } @Test |