/** * Take the distributor nodes as an example. Let X be the highest index of * the distributor nodes added through setNodeState(). Let Y be the number * of suffix nodes for which the state is down and without description. * 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 nodeCount.get(type.ordinal()); }
public boolean validWantedNodeState(NodeType type) { return validWantedNodeState.get(type.ordinal()); } public boolean validCurrentNodeState(NodeType type) { return validCurrentNodeState.get(type.ordinal()); }
public boolean validReportedNodeState(NodeType type) { return validReportedNodeState.get(type.ordinal()); } public boolean validWantedNodeState(NodeType type) { return validWantedNodeState.get(type.ordinal()); }
public boolean validCurrentNodeState(NodeType type) { return validCurrentNodeState.get(type.ordinal()); }
private State(String serialized, boolean validDisk, boolean validDistReported, boolean validStorReported, boolean validDistWanted, boolean validStorWanted, boolean validCluster, boolean validDistCurrent, boolean validStorCurrent) { validDiskState = validDisk; validClusterState = validCluster; assert(NodeType.STORAGE.ordinal() == 0); assert(NodeType.DISTRIBUTOR.ordinal() == 1); validReportedNodeState.add(validStorReported); validReportedNodeState.add(validDistReported); validWantedNodeState.add(validStorWanted); validWantedNodeState.add(validDistWanted); validCurrentNodeState.add(validStorCurrent); validCurrentNodeState.add(validDistCurrent); this.serializedAs = serialized; }
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()); } } }
public void addNodeState() throws ParseException { if (!empty) { NodeState ns = NodeState.deserialize(node.getType(), sb.toString()); if (!ns.equals(defaultUpNodeState(node.getType()))) { nodeStates.put(node, ns); } if (nodeCount.get(node.getType().ordinal()) <= node.getIndex()) { nodeCount.set(node.getType().ordinal(), node.getIndex() + 1); } } empty = true; sb = new StringBuilder(); } }
throw new ParseException("Illegal node count '" + value + "' in state: " + serialized, 0); if (nodeCount > this.nodeCount.get(nodeType.ordinal())) { this.nodeCount.set(nodeType.ordinal(), nodeCount); node = new Node(nodeType, Integer.valueOf(key.substring(dot + 1, dot2))); if (node.getIndex() >= this.nodeCount.get(nodeType.ordinal())) { throw new ParseException("Cannot index " + nodeType + " node " + node.getIndex() + " of " + this.nodeCount.get(nodeType.ordinal()) + " in state: " + serialized, 0);
/** * Returns the state of a node. * If the node is not known this returns a node in the state UP (never null) if it has lower index than the max * and DOWN otherwise. */ public NodeState getNodeState(Node node) { if (node.getIndex() >= nodeCount.get(node.getType().ordinal())) return new NodeState(node.getType(), State.DOWN); return nodeStates.getOrDefault(node, new NodeState(node.getType(), State.UP)); }
/** * 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(); } }