summaryrefslogtreecommitdiffstats
path: root/vdslib
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2023-03-27 09:19:31 +0200
committerHarald Musum <musum@yahooinc.com>2023-03-27 09:19:31 +0200
commitfd247da0ffae2cde82efddc5bb427734ce945c1b (patch)
tree9f7c7fd8ffd84c1b30d1b62f77e4ecb69181f93f /vdslib
parent4b9e04fd0b4013fe2f6e5748a02aa593637e4b5f (diff)
Minor cleanup, no functional changes
Diffstat (limited to 'vdslib')
-rw-r--r--vdslib/src/main/java/com/yahoo/vdslib/state/ClusterState.java47
-rw-r--r--vdslib/src/main/java/com/yahoo/vdslib/state/Node.java5
-rw-r--r--vdslib/src/main/java/com/yahoo/vdslib/state/NodeState.java15
-rw-r--r--vdslib/src/main/java/com/yahoo/vdslib/state/NodeType.java13
4 files changed, 34 insertions, 46 deletions
diff --git a/vdslib/src/main/java/com/yahoo/vdslib/state/ClusterState.java b/vdslib/src/main/java/com/yahoo/vdslib/state/ClusterState.java
index e8af249422f..4bf305e65e0 100644
--- a/vdslib/src/main/java/com/yahoo/vdslib/state/ClusterState.java
+++ b/vdslib/src/main/java/com/yahoo/vdslib/state/ClusterState.java
@@ -23,7 +23,7 @@ public class ClusterState implements Cloneable {
private static final NodeState DEFAULT_DISTRIBUTOR_DOWN_NODE_STATE = new NodeState(NodeType.DISTRIBUTOR, State.DOWN);
/**
- * Maintains a bitset where all non-down nodes have a bit set. All nodes that differs from defaultUp
+ * Maintains a bitset where all non-down nodes have a bit set. All nodes that differ from defaultUp
* and defaultDown are store explicit in a hash map.
*/
private static class Nodes {
@@ -102,19 +102,19 @@ public class ClusterState implements Cloneable {
}
}
- boolean similarToImpl(Nodes other, final NodeStateCmp nodeStateCmp) {
+ boolean notSimilarTo(Nodes other, final NodeStateCmp nodeStateCmp) {
// TODO verify behavior of C++ impl against this
- if (logicalNodeCount != other.logicalNodeCount) return false;
- if (type != other.type) return false;
- if ( ! upNodes.equals(other.upNodes)) return false;
+ if (logicalNodeCount != other.logicalNodeCount) return true;
+ if (type != other.type) return true;
+ if ( ! upNodes.equals(other.upNodes)) return true;
for (Integer node : unionNodeSetWith(other.nodeStates.keySet())) {
final NodeState lhs = nodeStates.get(node);
final NodeState rhs = other.nodeStates.get(node);
if (!nodeStateCmp.similar(type, lhs, rhs)) {
- return false;
+ return true;
}
}
- return true;
+ return false;
}
private Set<Integer> unionNodeSetWith(final Set<Integer> otherNodes) {
@@ -144,8 +144,7 @@ public class ClusterState implements Cloneable {
@Override
public boolean equals(Object obj) {
- if (! (obj instanceof Nodes)) return false;
- Nodes b = (Nodes) obj;
+ if (! (obj instanceof Nodes b)) return false;
if (logicalNodeCount != b.logicalNodeCount) return false;
if (type != b.type) return false;
if (!upNodes.equals(b.upNodes)) return false;
@@ -218,8 +217,7 @@ public class ClusterState implements Cloneable {
@Override
public boolean equals(Object o) {
- if (!(o instanceof ClusterState)) { return false; }
- ClusterState other = (ClusterState) o;
+ if (!(o instanceof ClusterState other)) { return false; }
if (version != other.version
|| !state.equals(other.state)
|| distributionBits != other.distributionBits
@@ -242,8 +240,7 @@ public class ClusterState implements Cloneable {
}
public boolean similarTo(Object o) {
- if (!(o instanceof ClusterState)) { return false; }
- final ClusterState other = (ClusterState) o;
+ if (!(o instanceof final ClusterState other)) { return false; }
return similarToImpl(other, this::normalizedNodeStateSimilarTo);
}
@@ -265,19 +262,15 @@ public class ClusterState implements Cloneable {
if (!metaInformationSimilarTo(other)) {
return false;
}
- if ( !distributorNodes.similarToImpl(other.distributorNodes, nodeStateCmp)) return false;
- if ( !storageNodes.similarToImpl(other.storageNodes, nodeStateCmp)) return false;
+ if (distributorNodes.notSimilarTo(other.distributorNodes, nodeStateCmp)) return false;
+ if (storageNodes.notSimilarTo(other.storageNodes, nodeStateCmp)) return false;
return true;
}
private boolean metaInformationSimilarTo(final ClusterState other) {
- if (version != other.version || !state.equals(other.state)) {
- return false;
- }
- if (distributionBits != other.distributionBits) {
- return false;
- }
- return true;
+ return version == other.version
+ && state.equals(other.state)
+ && distributionBits == other.distributionBits;
}
private boolean normalizedNodeStateSimilarTo(final NodeType nodeType, final NodeState lhs, final NodeState rhs) {
@@ -356,8 +349,8 @@ public class ClusterState implements Cloneable {
break;
case 'v':
if (key.equals("version")) {
- try{
- setVersion(Integer.valueOf(value));
+ try {
+ setVersion(Integer.parseInt(value));
} catch (Exception e) {
throw new ParseException("Illegal version '" + value + "'. Must be an integer, in state: " + serialized, 0);
}
@@ -382,7 +375,7 @@ public class ClusterState implements Cloneable {
if (dot < 0) {
int nodeCount;
try{
- nodeCount = Integer.valueOf(value);
+ nodeCount = Integer.parseInt(value);
} catch (Exception e) {
throw new ParseException("Illegal node count '" + value + "' in state: " + serialized, 0);
}
@@ -392,9 +385,9 @@ public class ClusterState implements Cloneable {
int dot2 = key.indexOf('.', dot + 1);
Node node;
if (dot2 < 0) {
- node = new Node(nodeType, Integer.valueOf(key.substring(dot + 1)));
+ node = new Node(nodeType, Integer.parseInt(key.substring(dot + 1)));
} else {
- node = new Node(nodeType, Integer.valueOf(key.substring(dot + 1, dot2)));
+ node = new Node(nodeType, Integer.parseInt(key.substring(dot + 1, dot2)));
}
if (node.getIndex() >= getNodeCount(nodeType)) {
throw new ParseException("Cannot index " + nodeType + " node " + node.getIndex() + " of " + getNodeCount(nodeType) + " in state: " + serialized, 0);
diff --git a/vdslib/src/main/java/com/yahoo/vdslib/state/Node.java b/vdslib/src/main/java/com/yahoo/vdslib/state/Node.java
index 0147ab0d056..445472bba4c 100644
--- a/vdslib/src/main/java/com/yahoo/vdslib/state/Node.java
+++ b/vdslib/src/main/java/com/yahoo/vdslib/state/Node.java
@@ -18,7 +18,7 @@ public class Node implements Comparable<Node> {
int dot = serialized.lastIndexOf('.');
if (dot < 0) throw new IllegalArgumentException("Not a legal node string '" + serialized + "'.");
type = NodeType.get(serialized.substring(0, dot));
- index = Integer.valueOf(serialized.substring(dot + 1));
+ index = Integer.parseInt(serialized.substring(dot + 1));
}
public static Node ofStorage(int index) {
@@ -52,8 +52,7 @@ public class Node implements Comparable<Node> {
@Override
public boolean equals(Object o) {
- if (!(o instanceof Node)) return false;
- Node n = (Node) o;
+ if (!(o instanceof Node n)) return false;
return (type.equals(n.type) && index == n.index);
}
diff --git a/vdslib/src/main/java/com/yahoo/vdslib/state/NodeState.java b/vdslib/src/main/java/com/yahoo/vdslib/state/NodeState.java
index 9f6efd7b5e0..4bb27e8599e 100644
--- a/vdslib/src/main/java/com/yahoo/vdslib/state/NodeState.java
+++ b/vdslib/src/main/java/com/yahoo/vdslib/state/NodeState.java
@@ -49,8 +49,7 @@ public class NodeState implements Cloneable {
}
public boolean equals(Object o) {
- if (!(o instanceof NodeState)) { return false; }
- NodeState ns = (NodeState) o;
+ if (!(o instanceof NodeState ns)) { return false; }
// Note that 'description' is not considered as it carries semantics.
if (state != ns.state
|| Math.abs(capacity - ns.capacity) > 0.0000000001
@@ -235,7 +234,7 @@ public class NodeState implements Cloneable {
if (key.length() > 1) break;
if (type != null && !type.equals(NodeType.STORAGE)) break;
try{
- newState.setCapacity(Float.valueOf(value));
+ newState.setCapacity(Float.parseFloat(value));
} catch (Exception e) {
throw new ParseException("Illegal capacity '" + value + "'. Capacity must be a positive floating point number", 0);
}
@@ -243,7 +242,7 @@ public class NodeState implements Cloneable {
case 'i':
if (key.length() > 1) break;
try{
- newState.setInitProgress(Float.valueOf(value));
+ newState.setInitProgress(Float.parseFloat(value));
} catch (Exception e) {
throw new ParseException("Illegal init progress '" + value + "'. Init progress must be a floating point number from 0.0 to 1.0", 0);
}
@@ -251,7 +250,7 @@ public class NodeState implements Cloneable {
case 't':
if (key.length() > 1) break;
try{
- newState.setStartTimestamp(Long.valueOf(value));
+ newState.setStartTimestamp(Long.parseLong(value));
if (newState.getStartTimestamp() < 0) throw new Exception();
} catch (Exception e) {
throw new ParseException("Illegal start timestamp " + value + ". Start timestamp must be 0 or a positive long.", 0);
@@ -265,8 +264,8 @@ public class NodeState implements Cloneable {
if (type != null && !type.equals(NodeType.STORAGE)) break;
int size = 0;
if (key.length() == 1) {
- try{
- size = Integer.valueOf(value);
+ try {
+ size = Integer.parseInt(value);
} catch (Exception e) {
throw new ParseException("Invalid disk count '" + value + "'. Need a positive integer value", 0);
}
@@ -277,7 +276,7 @@ public class NodeState implements Cloneable {
int endp = key.indexOf('.', 2);
String indexStr = (endp < 0 ? key.substring(2) : key.substring(2, endp));
try{
- diskIndex = Integer.valueOf(indexStr);
+ diskIndex = Integer.parseInt(indexStr);
} catch (Exception e) {
throw new ParseException("Invalid disk index '" + indexStr + "'. need a positive integer value", 0);
}
diff --git a/vdslib/src/main/java/com/yahoo/vdslib/state/NodeType.java b/vdslib/src/main/java/com/yahoo/vdslib/state/NodeType.java
index 1472525a1ea..8e7bce3503c 100644
--- a/vdslib/src/main/java/com/yahoo/vdslib/state/NodeType.java
+++ b/vdslib/src/main/java/com/yahoo/vdslib/state/NodeType.java
@@ -1,13 +1,15 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vdslib.state;
+import java.util.List;
+
public enum NodeType {
STORAGE("storage"),
DISTRIBUTOR("distributor");
private final String serializeAs;
- private NodeType(String serializeAs) {
+ NodeType(String serializeAs) {
this.serializeAs = serializeAs;
}
@@ -16,17 +18,12 @@ public enum NodeType {
}
public static NodeType get(String serialized) {
- for(NodeType type : values()) {
+ for (NodeType type : values()) {
if (type.serializeAs.equals(serialized)) return type;
}
throw new IllegalArgumentException("Unknown node type '" + serialized + "'. Legal values are 'storage' and 'distributor'.");
}
- public static NodeType[] getTypes() {
- NodeType types[] = new NodeType[2];
- types[0] = STORAGE;
- types[1] = DISTRIBUTOR;
- return types;
- }
+ public static List<NodeType> getTypes() { return List.of(STORAGE, DISTRIBUTOR); }
}