Java Code Examples for org.elasticsearch.cluster.routing.ShardRouting#unassignedInfo()

The following examples show how to use org.elasticsearch.cluster.routing.ShardRouting#unassignedInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaxRetryAllocationDecider.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocation) {
    final UnassignedInfo unassignedInfo = shardRouting.unassignedInfo();
    final Decision decision;
    if (unassignedInfo != null && unassignedInfo.getNumFailedAllocations() > 0) {
        final IndexMetaData indexMetaData = allocation.metaData().getIndexSafe(shardRouting.index());
        final int maxRetry = SETTING_ALLOCATION_MAX_RETRY.get(indexMetaData.getSettings());
        if (unassignedInfo.getNumFailedAllocations() >= maxRetry) {
            decision = allocation.decision(Decision.NO, NAME, "shard has exceeded the maximum number of retries [%d] on " +
                "failed allocation attempts - manually execute 'ALTER CLUSTER REROUTE RETRY FAILED' to retry, [%s]",
                maxRetry, unassignedInfo.toString());
        } else {
            decision = allocation.decision(Decision.YES, NAME, "shard has failed allocating [%d] times but [%d] retries are allowed",
                unassignedInfo.getNumFailedAllocations(), maxRetry);
        }
    } else {
        decision = allocation.decision(Decision.YES, NAME, "shard has no previous failures");
    }
    return decision;
}
 
Example 2
Source File: AllocationService.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Removes delay markers from unassigned shards based on current time stamp.
 */
private void removeDelayMarkers(RoutingAllocation allocation) {
    final RoutingNodes.UnassignedShards.UnassignedIterator unassignedIterator = allocation.routingNodes().unassigned().iterator();
    final MetaData metaData = allocation.metaData();
    while (unassignedIterator.hasNext()) {
        ShardRouting shardRouting = unassignedIterator.next();
        UnassignedInfo unassignedInfo = shardRouting.unassignedInfo();
        if (unassignedInfo.isDelayed()) {
            final long newComputedLeftDelayNanos = unassignedInfo.getRemainingDelay(allocation.getCurrentNanoTime(),
                metaData.getIndexSafe(shardRouting.index()).getSettings());
            if (newComputedLeftDelayNanos == 0) {
                unassignedIterator.updateUnassigned(new UnassignedInfo(unassignedInfo.getReason(), unassignedInfo.getMessage(),
                    unassignedInfo.getFailure(), unassignedInfo.getNumFailedAllocations(), unassignedInfo.getUnassignedTimeInNanos(),
                    unassignedInfo.getUnassignedTimeInMillis(), false, unassignedInfo.getLastAllocationStatus()),
                    shardRouting.recoverySource(), allocation.changes());
            }
        }
    }
}
 
Example 3
Source File: AllocationService.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Reset failed allocation counter for unassigned shards
 */
private void resetFailedAllocationCounter(RoutingAllocation allocation) {
    final RoutingNodes.UnassignedShards.UnassignedIterator unassignedIterator = allocation.routingNodes().unassigned().iterator();
    while (unassignedIterator.hasNext()) {
        ShardRouting shardRouting = unassignedIterator.next();
        UnassignedInfo unassignedInfo = shardRouting.unassignedInfo();
        unassignedIterator.updateUnassigned(new UnassignedInfo(unassignedInfo.getNumFailedAllocations() > 0 ?
            UnassignedInfo.Reason.MANUAL_ALLOCATION : unassignedInfo.getReason(), unassignedInfo.getMessage(),
            unassignedInfo.getFailure(), 0, unassignedInfo.getUnassignedTimeInNanos(),
            unassignedInfo.getUnassignedTimeInMillis(), unassignedInfo.isDelayed(),
            unassignedInfo.getLastAllocationStatus()), shardRouting.recoverySource(), allocation.changes());
    }
}