@Override public boolean equals(Object o) { if (!(o instanceof DiskState)) { return false; } DiskState other = (DiskState) o; if (state.equals(other.state) && Math.abs(capacity - other.capacity) < 0.00000001) { return true; } return false; }
private boolean metaInformationSimilarTo(final ClusterState other) { if (version != other.version || !state.equals(other.state)) { return false; } if (distributionBits != other.distributionBits) { return false; } return nodeCount.equals(other.nodeCount); }
@Override public boolean equals(Object o) { if (!(o instanceof ClusterState)) { return false; } ClusterState other = (ClusterState) o; if (version != other.version || !state.equals(other.state) || distributionBits != other.distributionBits || !nodeCount.equals(other.nodeCount) || !nodeStates.equals(other.nodeStates)) { return false; } return true; }
private void updateAnyDiskDownFlag() { boolean anyDown = false; for (DiskState ds : diskStates) { if (!ds.getState().equals(State.UP)) { anyDown = true; break; } } anyDiskDown = anyDown; }
public String serialize(String prefix, boolean includeDescription) { boolean empty = true; StringBuilder sb = new StringBuilder(); if (!state.equals(State.UP) || prefix.length() < 2) { sb.append(prefix).append("s:").append(state.serialize()); empty = false; } if (Math.abs(capacity - 1.0) > 0.000000001) { if (empty) { empty = false; } else { sb.append(' '); } sb.append(prefix).append("c:").append(capacity); } if (includeDescription && description.length() > 0) { if (!empty) { sb.append(' '); } sb.append(prefix).append("m:").append(StringUtilities.escape(description, ' ')); } return sb.toString(); }
private boolean similarToImpl(final ClusterState other, final NodeStateCmp nodeStateCmp) { if (other == this) { return true; // We're definitely similar to ourselves. } // Two cluster states are considered similar if they are both down. When clusters // are down, their individual node states do not matter to ideal state computations // and content nodes therefore do not need to observe them. if (state.equals(State.DOWN) && other.state.equals(State.DOWN)) { return true; } if (!metaInformationSimilarTo(other)) { return false; } // TODO verify behavior of C++ impl against this for (Node node : unionNodeSetWith(other.nodeStates.keySet())) { final NodeState lhs = nodeStates.get(node); final NodeState rhs = other.nodeStates.get(node); if (!nodeStateCmp.similar(node.getType(), lhs, rhs)) { return false; } } return true; }
private void removeLastNodesDownWithoutReason() { for (NodeType nodeType : NodeType.values()) { for (int index = nodeCount.get(nodeType.ordinal()) - 1; index >= 0; --index) { Node node = new Node(nodeType, index); NodeState nodeState = nodeStates.get(node); if (nodeState == null) break; // Node not existing is up if ( ! nodeState.getState().equals(State.DOWN)) break; // Node not down can not be removed if (nodeState.hasDescription()) break; // Node have reason to be down. Don't remove node as we will forget reason nodeStates.remove(node); nodeCount.set(nodeType.ordinal(), node.getIndex()); } } }
sb.append(compact ? ", r " : ", reliability ").append(reliability); if (state.equals(State.INITIALIZING)) { sb.append(compact ? ", i " : ", init progress ").append(compact ? String.format(Locale.ENGLISH, "%.3g", initProgress) : initProgress); if (type.equals(NodeType.STORAGE)) {
if (!state.equals(State.UP)) { sb.append(" cluster:").append(state.serialize()); while (distributorNodeCount > 0 && getNodeState(new Node(NodeType.DISTRIBUTOR, distributorNodeCount - 1)).getState().equals(State.DOWN)) --distributorNodeCount; while (storageNodeCount > 0 && getNodeState(new Node(NodeType.STORAGE, storageNodeCount - 1)).getState().equals(State.DOWN)) --storageNodeCount;
public Diff getDiff(NodeState other) { Diff diff = new Diff(); if (!state.equals(other.state)) { diff.add(new Diff.Entry("", state, other.state).bold()); diff.add(new Diff.Entry("minUsedBits", minUsedBits, other.minUsedBits)); if (Math.abs(initProgress - other.initProgress) > 0.000000001 && state.equals(State.INITIALIZING) && other.state.equals(State.INITIALIZING)) { diff.add(new Diff.Entry("initProgress", initProgress, other.initProgress));
private void updateCachedRoutingStateFromWrongDistribution(MessageContext context, ClusterState newState) { if (cachedClusterState == null || newState.getVersion() >= cachedClusterState.getVersion()) { cachedClusterState = newState; if (newState.getClusterState().equals(State.UP)) { hostFetcher.updateValidTargets(newState); } } else if (newState.getVersion() + 2000000000 < cachedClusterState.getVersion()) { cachedClusterState = null; } else if (context.calculatedDistributor != null) { persistentFailureChecker.addFailure(context.calculatedDistributor); } }
/** * Set the node state of the given node. * * Automatically adjusts number of nodes of that given type if out of range of current nodes seen. */ public void setNodeState(Node node, NodeState newState) { newState.verifyValidInSystemState(node.getType()); if (node.getIndex() >= nodeCount.get(node.getType().ordinal())) { for (int i= nodeCount.get(node.getType().ordinal()); i<node.getIndex(); ++i) { nodeStates.put(new Node(node.getType(), i), new NodeState(node.getType(), State.DOWN)); } nodeCount.set(node.getType().ordinal(), node.getIndex() + 1); } if (newState.equals(new NodeState(node.getType(), State.UP))) { nodeStates.remove(node); } else { nodeStates.put(node, newState); } if (newState.getState().equals(State.DOWN)) { // We might be setting the last node down, so we can remove some states removeLastNodesDownWithoutReason(); } }
public Diff getDiff(ClusterState other) { Diff diff = new Diff(); if (version != other.version) { diff.add(new Diff.Entry("version", version, other.version)); } if (!state.equals(other.state)) { diff.add(new Diff.Entry("cluster", state, other.state)); } if (distributionBits != other.distributionBits) { diff.add(new Diff.Entry("bits", distributionBits, other.distributionBits)); } if (official != other.official) { diff.add(new Diff.Entry("official", official, other.official)); } for (NodeType type : NodeType.getTypes()) { Diff typeDiff = new Diff(); int maxCount = Math.max(getNodeCount(type), other.getNodeCount(type)); for (int i = 0; i < maxCount; i++) { Node n = new Node(type, i); Diff d = getNodeState(n).getDiff(other.getNodeState(n)); if (d.differs()) { typeDiff.add(new Diff.Entry(i, d)); } } if (typeDiff.differs()) { diff.add(new Diff.Entry(type, typeDiff).splitLine()); } } return diff; }