diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2021-01-19 22:15:20 +0100 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2021-01-19 22:15:20 +0100 |
commit | 7913d1f58cbd2a328719bcdcfec48d1e3b50b8b7 (patch) | |
tree | 2d04a18a31f7449344d485a2db8bb5eb9e780b5e /vdslib/src | |
parent | be65ce1bf5de044e90c817c265edae2ff1af1f25 (diff) |
Use only injected config for injected document access
Diffstat (limited to 'vdslib/src')
-rw-r--r-- | vdslib/src/main/java/com/yahoo/vdslib/distribution/Distribution.java | 139 | ||||
-rw-r--r-- | vdslib/src/test/java/com/yahoo/vdslib/distribution/CrossPlatformTestFactory.java | 5 |
2 files changed, 97 insertions, 47 deletions
diff --git a/vdslib/src/main/java/com/yahoo/vdslib/distribution/Distribution.java b/vdslib/src/main/java/com/yahoo/vdslib/distribution/Distribution.java index 16f18cf8f8b..26e8f074b49 100644 --- a/vdslib/src/main/java/com/yahoo/vdslib/distribution/Distribution.java +++ b/vdslib/src/main/java/com/yahoo/vdslib/distribution/Distribution.java @@ -9,6 +9,7 @@ import com.yahoo.vdslib.state.Node; import com.yahoo.vdslib.state.NodeState; import com.yahoo.vdslib.state.NodeType; import com.yahoo.vdslib.state.State; +import com.yahoo.vespa.config.content.DistributionConfig; import com.yahoo.vespa.config.content.StorDistributionConfig; import com.yahoo.document.BucketId; @@ -52,61 +53,103 @@ public class Distribution { return config.getAcquire().redundancy; } - private ConfigSubscriber.SingleSubscriber<StorDistributionConfig> configSubscriber = new ConfigSubscriber.SingleSubscriber<>() { - private int[] getGroupPath(String path) { - if (path.equals("invalid")) { return new int[0]; } - StringTokenizer st = new StringTokenizer(path, "."); - int[] p = new int[st.countTokens()]; - for (int i=0; i<p.length; ++i) { - p[i] = Integer.valueOf(st.nextToken()); - } - return p; + private static int[] getGroupPath(String path) { + if (path.equals("invalid")) { return new int[0]; } + StringTokenizer st = new StringTokenizer(path, "."); + int[] p = new int[st.countTokens()]; + for (int i=0; i<p.length; ++i) { + p[i] = Integer.valueOf(st.nextToken()); } + return p; + } - @Override - public void configure(StorDistributionConfig config) { - try{ - Group root = null; - for (int i=0; i<config.group().size(); ++i) { - StorDistributionConfig.Group cg = config.group(i); - int[] path = new int[0]; - if (root != null) { - path = getGroupPath(cg.index()); - } - boolean isLeafGroup = (cg.nodes().size() > 0); - Group group; - int index = (path.length == 0 ? 0 : path[path.length - 1]); - if (isLeafGroup) { - group = new Group(index, cg.name()); - List<ConfiguredNode> nodes = new ArrayList<>(); - for (StorDistributionConfig.Group.Nodes node : cg.nodes()) { - nodes.add(new ConfiguredNode(node.index(), node.retired())); - } - group.setNodes(nodes); - } else { - group = new Group(index, cg.name(), new Group.Distribution(cg.partitions(), config.redundancy())); + // NOTE: keep in sync with the below + private ConfigSubscriber.SingleSubscriber<StorDistributionConfig> configSubscriber = config -> { + try { + Group root = null; + for (int i=0; i<config.group().size(); ++i) { + StorDistributionConfig.Group cg = config.group(i); + int[] path = new int[0]; + if (root != null) { + path = getGroupPath(cg.index()); + } + boolean isLeafGroup = (cg.nodes().size() > 0); + Group group; + int index = (path.length == 0 ? 0 : path[path.length - 1]); + if (isLeafGroup) { + group = new Group(index, cg.name()); + List<ConfiguredNode> nodes = new ArrayList<>(); + for (StorDistributionConfig.Group.Nodes node : cg.nodes()) { + nodes.add(new ConfiguredNode(node.index(), node.retired())); } - group.setCapacity(cg.capacity()); - if (path.length == 0) { - root = group; - } else { - Group parent = root; - for (int j=0; j<path.length - 1; ++j) { - parent = parent.getSubgroups().get(path[j]); - } - parent.addSubGroup(group); + group.setNodes(nodes); + } else { + group = new Group(index, cg.name(), new Group.Distribution(cg.partitions(), config.redundancy())); + } + group.setCapacity(cg.capacity()); + if (path.length == 0) { + root = group; + } else { + Group parent = root; + for (int j=0; j<path.length - 1; ++j) { + parent = parent.getSubgroups().get(path[j]); } + parent.addSubGroup(group); } - if (root == null) - throw new IllegalStateException("Config does not specify a root group"); - root.calculateDistributionHashValues(); - Distribution.this.config.setRelease(new Config(root, config.redundancy(), config.distributor_auto_ownership_transfer_on_whole_group_down())); - } catch (ParseException e) { - throw new IllegalStateException("Failed to parse config", e); } + if (root == null) + throw new IllegalStateException("Config does not specify a root group"); + root.calculateDistributionHashValues(); + Distribution.this.config.setRelease(new Config(root, config.redundancy(), config.distributor_auto_ownership_transfer_on_whole_group_down())); + } catch (ParseException e) { + throw new IllegalStateException("Failed to parse config", e); } }; + // TODO jonmv: De-dupe with this.configSubscriber once common config is used + private void configure(DistributionConfig.Cluster config) { + try { + Group root = null; + for (int i=0; i<config.group().size(); ++i) { + DistributionConfig.Cluster.Group cg = config.group(i); + int[] path = new int[0]; + if (root != null) { + path = getGroupPath(cg.index()); + } + boolean isLeafGroup = (cg.nodes().size() > 0); + Group group; + int index = (path.length == 0 ? 0 : path[path.length - 1]); + if (isLeafGroup) { + group = new Group(index, cg.name()); + List<ConfiguredNode> nodes = new ArrayList<>(); + for (DistributionConfig.Cluster.Group.Nodes node : cg.nodes()) { + nodes.add(new ConfiguredNode(node.index(), node.retired())); + } + group.setNodes(nodes); + } else { + group = new Group(index, cg.name(), new Group.Distribution(cg.partitions(), config.redundancy())); + } + group.setCapacity(cg.capacity()); + if (path.length == 0) { + root = group; + } else { + Group parent = root; + for (int j=0; j<path.length - 1; ++j) { + parent = parent.getSubgroups().get(path[j]); + } + parent.addSubGroup(group); + } + } + if (root == null) + throw new IllegalStateException("Config does not specify a root group"); + root.calculateDistributionHashValues(); + Distribution.this.config.setRelease(new Config(root, config.redundancy(), true)); + } catch (ParseException e) { + throw new IllegalStateException("Failed to parse config", e); + } + } + + public Distribution(String configId) { int mask = 0; for (int i=0; i<=64; ++i) { @@ -131,6 +174,10 @@ public class Distribution { configSubscriber.configure(config); } + public Distribution(DistributionConfig.Cluster config) { + configure(config); + } + public void close() { if (configSub!=null) { configSub.close(); diff --git a/vdslib/src/test/java/com/yahoo/vdslib/distribution/CrossPlatformTestFactory.java b/vdslib/src/test/java/com/yahoo/vdslib/distribution/CrossPlatformTestFactory.java index 94f7d7a8c94..7dadd9560b5 100644 --- a/vdslib/src/test/java/com/yahoo/vdslib/distribution/CrossPlatformTestFactory.java +++ b/vdslib/src/test/java/com/yahoo/vdslib/distribution/CrossPlatformTestFactory.java @@ -1,7 +1,10 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vdslib.distribution; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; /** * Helper class to implement unit tests that should produce the same result in different implementations. |