@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (allocateDecision.isDecisionTaken()) { allocateDecision.toXContent(builder, params); } if (moveDecision.isDecisionTaken()) { moveDecision.toXContent(builder, params); } return builder; }
/** * Returns the {@link AllocationDecision} denoting the result of an allocation attempt. * If {@link #isDecisionTaken()} returns {@code false}, then invoking this method will * throw an {@code IllegalStateException}. */ public AllocationDecision getAllocationDecision() { checkDecisionState(); return AllocationDecision.fromAllocationStatus(allocationStatus); }
/** * Returns {@code true} if either an allocation decision or a move decision was taken * for the shard. If no decision was taken, as in the case of initializing or relocating * shards, then this method returns {@code false}. */ public boolean isDecisionTaken() { return allocateDecision.isDecisionTaken() || moveDecision.isDecisionTaken(); }
public ShardAllocationDecision(StreamInput in) throws IOException { allocateDecision = new AllocateUnassignedDecision(in); moveDecision = new MoveDecision(in); }
/** * Returns {@code true} if the shard cannot remain on its current node and can be moved, * returns {@code false} otherwise. If {@link #isDecisionTaken()} returns {@code false}, * then invoking this method will throw an {@code IllegalStateException}. */ public boolean forceMove() { checkDecisionState(); return canRemain() == false && allocationDecision == AllocationDecision.YES; }
/** * Reroutes the routing table based on the live nodes. * <p> * If the same instance of ClusterState is returned, then no change has been made. */ public ClusterState reroute(ClusterState clusterState, String reason) { return reroute(clusterState, reason, false); }
/** * Gets the remaining delay for allocating the replica shard when a node holding the replica left * the cluster and the deciders are waiting to see if the node returns before allocating the replica * elsewhere. Only returns a meaningful positive value if {@link #getAllocationStatus()} returns * {@link AllocationStatus#DELAYED_ALLOCATION}. If {@link #isDecisionTaken()} returns {@code false}, * then invoking this method will throw an {@code IllegalStateException}. */ public long getRemainingDelayInMillis() { checkDecisionState(); return remainingDelayInMillis; }
/** * Returns the decision for the shard being allowed to remain on its current node. If {@link #isDecisionTaken()} * returns {@code false}, then invoking this method will throw an {@code IllegalStateException}. */ public Decision getCanRemainDecision() { checkDecisionState(); return canRemainDecision; }
/** * Returns updated {@link MetaData} based on the changes that were made to the routing nodes */ public MetaData updateMetaDataWithRoutingChanges(RoutingTable newRoutingTable) { return indexMetaDataUpdater.applyChanges(metaData, newRoutingTable); }
/** * Returns true iff changes were made to the routing nodes */ public boolean routingNodesChanged() { return nodesChangedObserver.isChanged(); }
public DiskThresholdMonitor(Settings settings, Supplier<ClusterState> clusterStateSupplier, ClusterSettings clusterSettings, Client client) { this.clusterStateSupplier = clusterStateSupplier; this.diskThresholdSettings = new DiskThresholdSettings(settings, clusterSettings); this.client = client; }
/** * Attempts to parse the watermark into a {@link ByteSizeValue}, returning * a ByteSizeValue of 0 bytes if the value cannot be parsed. */ private static ByteSizeValue thresholdBytesFromWatermark(String watermark, String settingName) { return thresholdBytesFromWatermark(watermark, settingName, true); }
/** * Creates a move decision for when rebalancing the shard is not allowed. */ public static MoveDecision cannotRebalance(Decision canRebalanceDecision, AllocationDecision allocationDecision, int currentNodeRanking, List<NodeAllocationResult> nodeDecisions) { return new MoveDecision(null, canRebalanceDecision, allocationDecision, null, nodeDecisions, currentNodeRanking); }
/** * Attempts to parse the watermark into a percentage, returning 100.0% if * it cannot be parsed. */ private static double thresholdPercentageFromWatermark(String watermark) { return thresholdPercentageFromWatermark(watermark, true); }
/** * Increase primary term for this shard id */ private void increasePrimaryTerm(ShardId shardId) { changes(shardId).increaseTerm = true; }
/** * Remove the allocation id of the provided shard from the set of in-sync shard copies */ public void removeAllocationId(ShardRouting shardRouting) { indexMetaDataUpdater.removeAllocationId(shardRouting); }
public AllocationService(AllocationDeciders allocationDeciders, GatewayAllocator gatewayAllocator, ShardsAllocator shardsAllocator, ClusterInfoService clusterInfoService) { this(allocationDeciders, shardsAllocator, clusterInfoService); setGatewayAllocator(gatewayAllocator); }
/** * Gets the total configured delay for allocating the replica shard when a node holding the replica left * the cluster and the deciders are waiting to see if the node returns before allocating the replica * elsewhere. Only returns a meaningful positive value if {@link #getAllocationStatus()} returns * {@link AllocationStatus#DELAYED_ALLOCATION}. If {@link #isDecisionTaken()} returns {@code false}, * then invoking this method will throw an {@code IllegalStateException}. */ public long getConfiguredDelayInMillis() { checkDecisionState(); return configuredDelayInMillis; }
/** * Gets the current ranking of the node to which the shard is currently assigned, relative to the * other nodes in the cluster as reported in {@link NodeAllocationResult#getWeightRanking()}. The * ranking will only return a meaningful positive integer if {@link #getClusterRebalanceDecision()} returns * a non-null value; otherwise, 0 will be returned. If {@link #isDecisionTaken()} returns * {@code false}, then invoking this method will throw an {@code IllegalStateException}. */ public int getCurrentNodeRanking() { checkDecisionState(); return currentNodeRanking; }