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);
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()); } } }
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;
@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) {
/** * 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(); } }
if (!nodeState.getState().oneOf(upStates)) { continue;
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) {