summaryrefslogtreecommitdiffstats
path: root/vdslib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-09-23 13:19:18 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2021-09-23 13:19:18 +0200
commit928df53fa2a72eb9b8d46d189e72775fdbad0d2f (patch)
tree37f10b69601051e3d29eb943b254ded8b840a7d2 /vdslib
parent3284fab4a327451876de4046abae49d43d6aa3ea (diff)
Update comments and use better naming.
Diffstat (limited to 'vdslib')
-rw-r--r--vdslib/src/main/java/com/yahoo/vdslib/state/ClusterState.java32
-rw-r--r--vdslib/src/main/java/com/yahoo/vdslib/state/NodeState.java2
2 files changed, 17 insertions, 17 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 154941fb5c0..8704b11fdfb 100644
--- a/vdslib/src/main/java/com/yahoo/vdslib/state/ClusterState.java
+++ b/vdslib/src/main/java/com/yahoo/vdslib/state/ClusterState.java
@@ -23,11 +23,11 @@ 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 dows 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 differs from defaultUp
* and defaultDown are store explicit in a hash map.
*/
private static class Nodes {
- private int maxIndex;
+ private int logicalNodeCount;
private final NodeType type;
private final BitSet upNodes;
private final Map<Integer, NodeState> nodeStates = new HashMap<>();
@@ -36,25 +36,25 @@ public class ClusterState implements Cloneable {
upNodes = new BitSet();
}
Nodes(Nodes b) {
- maxIndex = b.maxIndex;
+ logicalNodeCount = b.logicalNodeCount;
type = b.type;
upNodes = (BitSet) b.upNodes.clone();
b.nodeStates.forEach((key, value) -> nodeStates.put(key, value.clone()));
}
void updateMaxIndex(int index) {
- if (index > maxIndex) {
- upNodes.set(maxIndex, index);
- maxIndex = index;
+ if (index > logicalNodeCount) {
+ upNodes.set(logicalNodeCount, index);
+ logicalNodeCount = index;
}
}
- int getMaxIndex() { return maxIndex; }
+ int getLogicalNodeCount() { return logicalNodeCount; }
NodeState getNodeState(int index) {
NodeState ns = nodeStates.get(index);
if (ns != null) return ns;
- return (index >= getMaxIndex() || ! upNodes.get(index))
+ return (index >= getLogicalNodeCount() || ! upNodes.get(index))
? new NodeState(type, State.DOWN)
: new NodeState(type, State.UP);
}
@@ -69,8 +69,8 @@ public class ClusterState implements Cloneable {
void setNodeState(Node node, NodeState ns) {
validateInput(node, ns);
int index = node.getIndex();
- if (index >= maxIndex) {
- maxIndex = index + 1;
+ if (index >= logicalNodeCount) {
+ logicalNodeCount = index + 1;
}
setNodeStateInternal(index, ns);
}
@@ -83,7 +83,7 @@ public class ClusterState implements Cloneable {
}
private static boolean equalsWithDescription(NodeState a, NodeState b) {
- // TODO Why does not NodeState.equals consider description.
+ // This is due to NodeState.equals considers semantic equality, and description is not part of that.
return a.equals(b) && ((a.getState() != State.DOWN) || a.getDescription().equals(b.getDescription()));
}
@@ -104,7 +104,7 @@ public class ClusterState implements Cloneable {
boolean similarToImpl(Nodes other, final NodeStateCmp nodeStateCmp) {
// TODO verify behavior of C++ impl against this
- if (maxIndex != other.maxIndex) return false;
+ if (logicalNodeCount != other.logicalNodeCount) return false;
if (type != other.type) return false;
if ( ! upNodes.equals(other.upNodes)) return false;
for (Integer node : unionNodeSetWith(other.nodeStates.keySet())) {
@@ -129,7 +129,7 @@ public class ClusterState implements Cloneable {
String toString(boolean verbose) {
StringBuilder sb = new StringBuilder();
- int nodeCount = verbose ? getMaxIndex() : upNodes.length();
+ int nodeCount = verbose ? getLogicalNodeCount() : upNodes.length();
if ( nodeCount > 0 ) {
sb.append(type == NodeType.DISTRIBUTOR ? " distributor:" : " storage:").append(nodeCount);
for (int i = 0; i < nodeCount; i++) {
@@ -146,7 +146,7 @@ public class ClusterState implements Cloneable {
public boolean equals(Object obj) {
if (! (obj instanceof Nodes)) return false;
Nodes b = (Nodes) obj;
- if (maxIndex != b.maxIndex) return false;
+ if (logicalNodeCount != b.logicalNodeCount) return false;
if (type != b.type) return false;
if (!upNodes.equals(b.upNodes)) return false;
if (!nodeStates.equals(b.nodeStates)) return false;
@@ -155,7 +155,7 @@ public class ClusterState implements Cloneable {
@Override
public int hashCode() {
- return Objects.hash(maxIndex, type, nodeStates, upNodes);
+ return Objects.hash(logicalNodeCount, type, nodeStates, upNodes);
}
private NodeState defaultDown() {
return type == NodeType.STORAGE
@@ -489,7 +489,7 @@ public class ClusterState implements Cloneable {
* E.g. if node X is down and without description, but nodex X-1 is up, then Y is 1.
* The node count for distributors is then X + 1 - Y.
*/
- public int getNodeCount(NodeType type) { return getNodes(type).getMaxIndex(); }
+ public int getNodeCount(NodeType type) { return getNodes(type).getLogicalNodeCount(); }
/**
* Returns the state of a node.
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 efff1933b0b..80cf87b7597 100644
--- a/vdslib/src/main/java/com/yahoo/vdslib/state/NodeState.java
+++ b/vdslib/src/main/java/com/yahoo/vdslib/state/NodeState.java
@@ -51,7 +51,7 @@ public class NodeState implements Cloneable {
public boolean equals(Object o) {
if (!(o instanceof NodeState)) { return false; }
NodeState ns = (NodeState) o;
- // Note that 'description' is not considered. Intentional ?
+ // Note that 'description' is not considered as it carries semantics.
if (state != ns.state
|| Math.abs(capacity - ns.capacity) > 0.0000000001
|| Math.abs(initProgress - ns.initProgress) > 0.0000000001