public void updateValidTargets(ClusterState state) { List<Integer> validRandomTargets = new ArrayList<>(); for (int i=0; i<state.getNodeCount(NodeType.DISTRIBUTOR); ++i) { if (state.getNodeState(new Node(NodeType.DISTRIBUTOR, i)).getState().oneOf(upStates)) validRandomTargets.add(i); } this.validRandomTargets = validRandomTargets; this.totalTargets = state.getNodeCount(NodeType.DISTRIBUTOR); } public abstract String getTargetSpec(Integer distributor, RoutingContext context);
/** * 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)); }
public ClusterState clone() { try{ ClusterState state = (ClusterState) super.clone(); state.nodeStates = new TreeMap<>(); for (Map.Entry<Node, NodeState> entry : nodeStates.entrySet()) { state.nodeStates.put(entry.getKey(), entry.getValue().clone()); } state.nodeCount = new ArrayList<>(2); state.nodeCount.add(nodeCount.get(0)); state.nodeCount.add(nodeCount.get(1)); return state; } catch (CloneNotSupportedException e) { assert(false); // Should never happen return null; } }
if (nodeState.getDiskCount() < 2) { if (nodeState.getDiskCount() == 1) { return 0; for (int i=0, n=nodeState.getDiskCount(); i<n; ++i) { double score = randomizer.nextDouble(); DiskState diskState = (nodeState.getDiskState(i)); if (diskState.getCapacity() != 1.0) { score = Math.pow(score,
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(); } }
NodeState newState = new NodeState(type, State.UP); StringTokenizer st = new StringTokenizer(serialized, " \t\r\f\n", false); DiskData diskData = new DiskData(); case 's': if (key.length() > 1) break; newState.setState(State.get(value)); continue; case 'b': if (key.length() > 1) break; newState.setMinUsedBits(Integer.parseInt(value)); continue; case 'c': if (type != null && !type.equals(NodeType.STORAGE)) break; try{ newState.setCapacity(Double.valueOf(value)); } catch (Exception e) { throw new ParseException("Illegal capacity '" + value + "'. Capacity must be a positive floating point number", 0); if (type != null && !type.equals(NodeType.STORAGE)) break; try{ newState.setReliability(Integer.valueOf(value)); } catch (Exception e) { throw new ParseException("Illegal reliability '" + value + "'. Reliability must be a positive integer number", 0); if (key.length() > 1) break; try{ newState.setInitProgress(Double.valueOf(value));
if (!nodeState.getState().oneOf(upStates)) { continue; if (nodeState.isAnyDiskDown()) { int idealDiskIndex = getIdealDisk(nodeState, configuredNode.index(), bucket); if (nodeState.getDiskState(idealDiskIndex).getState() != State.UP) { continue; if (nodeState.getCapacity() != 1.0) { score = Math.pow(score, 1.0 / nodeState.getCapacity()); tmpResults.add(i, new ScoredNode(configuredNode.index(), nodeState.getReliability(), score)); break;
/** * 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(); } }
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; for (Map.Entry<Node, NodeState> entry : nodeStates.entrySet()) { if (entry.getKey().getType().equals(NodeType.DISTRIBUTOR) && entry.getKey().getIndex() < distributorNodeCount) { String nodeState = entry.getValue().serialize(entry.getKey().getIndex(), verbose); if (!nodeState.isEmpty()) { sb.append(' ').append(nodeState); for (Map.Entry<Node, NodeState> entry : nodeStates.entrySet()) { if (entry.getKey().getType().equals(NodeType.STORAGE) && entry.getKey().getIndex() < storageNodeCount) { String nodeState = entry.getValue().serialize(entry.getKey().getIndex(), verbose); if (!nodeState.isEmpty()) { sb.append(' ').append(nodeState);
for (ConfiguredNode configuredNode : configuredNodes) { NodeState nodeState = state.getNodeState(new Node(NodeType.DISTRIBUTOR, configuredNode.index())); if (!nodeState.getState().oneOf(upStates)) continue; if (configuredNode.index() != randomIndex) { if (configuredNode.index() < randomIndex) { if (Math.abs(nodeState.getCapacity() - 1.0) > 0.0000001) { score = Math.pow(score, 1.0 / nodeState.getCapacity());
public String getTextualDifference(NodeState other) { return getDiff(other).toString(); }
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; }
@Override public boolean nodeUp() { return !clusterUp() && clusterState.getNodeState(new Node(NodeType.STORAGE, clusterIndex)).getState().oneOf("uir"); } }
private static boolean allDistributorsDown(Group g, ClusterState clusterState) { if (g.isLeafGroup()) { for (ConfiguredNode node : g.getNodes()) { NodeState ns = clusterState.getNodeState(new Node(NodeType.DISTRIBUTOR, node.index())); if (ns.getState().oneOf("ui")) return false; } } else { for (Group childGroup : g.getSubgroups().values()) { if (!allDistributorsDown(childGroup, clusterState)) return false; } } return true; } private Group getIdealDistributorGroup(BucketId bucket, ClusterState clusterState, Group parent, int redundancy) {