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

The following examples show how to use org.elasticsearch.cluster.routing.ShardRouting#allocatedPostIndexCreate() . 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: PrimaryShardAllocator.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Does the shard need to find a primary copy?
 */
boolean needToFindPrimaryCopy(ShardRouting shard) {
    if (shard.primary() == false) {
        return false;
    }

    // this is an API allocation, ignore since we know there is no data...
    if (shard.allocatedPostIndexCreate() == false) {
        return false;
    }

    return true;
}
 
Example 2
Source File: DisableAllocationDecider.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
    if (allocation.ignoreDisable()) {
        return allocation.decision(Decision.YES, NAME, "allocation disabling is ignored");
    }
    Settings indexSettings = allocation.routingNodes().metaData().index(shardRouting.index()).getSettings();
    if (shardRouting.primary() && shardRouting.allocatedPostIndexCreate() == false) {
        // if its primary, and it hasn't been allocated post API (meaning its a "fresh newly created shard"), only disable allocation
        // on a special disable allocation flag
        if (indexSettings.getAsBoolean(INDEX_ROUTING_ALLOCATION_DISABLE_NEW_ALLOCATION, disableNewAllocation)) {
            return allocation.decision(Decision.NO, NAME, "new primary allocation is disabled");
        } else {
            return allocation.decision(Decision.YES, NAME, "new primary allocation is enabled");
        }
    }
    if (indexSettings.getAsBoolean(INDEX_ROUTING_ALLOCATION_DISABLE_ALLOCATION, disableAllocation)) {
        return allocation.decision(Decision.NO, NAME, "all allocation is disabled");
    }
    if (indexSettings.getAsBoolean(INDEX_ROUTING_ALLOCATION_DISABLE_REPLICA_ALLOCATION, disableReplicaAllocation)) {
        if (shardRouting.primary()) {
            return allocation.decision(Decision.YES, NAME, "primary allocation is enabled");
        } else {
            return allocation.decision(Decision.NO, NAME, "replica allocation is disabled");
        }
    }
    return allocation.decision(Decision.YES, NAME, "all allocation is enabled");
}
 
Example 3
Source File: EnableAllocationDecider.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) {
    if (allocation.ignoreDisable()) {
        return allocation.decision(Decision.YES, NAME, "allocation disabling is ignored");
    }

    Settings indexSettings = allocation.routingNodes().metaData().index(shardRouting.index()).getSettings();
    String enableIndexValue = indexSettings.get(INDEX_ROUTING_ALLOCATION_ENABLE);
    final Allocation enable;
    if (enableIndexValue != null) {
        enable = Allocation.parse(enableIndexValue);
    } else {
        enable = this.enableAllocation;
    }
    switch (enable) {
        case ALL:
            return allocation.decision(Decision.YES, NAME, "all allocations are allowed");
        case NONE:
            return allocation.decision(Decision.NO, NAME, "no allocations are allowed");
        case NEW_PRIMARIES:
            if (shardRouting.primary() && shardRouting.allocatedPostIndexCreate() == false) {
                return allocation.decision(Decision.YES, NAME, "new primary allocations are allowed");
            } else {
                return allocation.decision(Decision.NO, NAME, "non-new primary allocations are forbidden");
            }
        case PRIMARIES:
            if (shardRouting.primary()) {
                return allocation.decision(Decision.YES, NAME, "primary allocations are allowed");
            } else {
                return allocation.decision(Decision.NO, NAME, "replica allocations are forbidden");
            }
        default:
            throw new IllegalStateException("Unknown allocation option");
    }
}