Search in sources :

Example 6 with FailedShard

use of org.elasticsearch.cluster.routing.allocation.FailedShard in project elasticsearch by elastic.

the class PrimaryTermsTests method failSomePrimaries.

private void failSomePrimaries(String index) {
    final IndexRoutingTable indexShardRoutingTable = clusterState.routingTable().index(index);
    Set<Integer> shardIdsToFail = new HashSet<>();
    for (int i = 1 + randomInt(numberOfShards - 1); i > 0; i--) {
        shardIdsToFail.add(randomInt(numberOfShards - 1));
    }
    logger.info("failing primary shards {} for index [{}]", shardIdsToFail, index);
    List<FailedShard> failedShards = new ArrayList<>();
    for (int shard : shardIdsToFail) {
        failedShards.add(new FailedShard(indexShardRoutingTable.shard(shard).primaryShard(), "test", null));
        // the primary failure should increment the primary term;
        incrementPrimaryTerm(index, shard);
    }
    applyRerouteResult(allocationService.applyFailedShards(this.clusterState, failedShards, Collections.emptyList()));
}
Also used : ArrayList(java.util.ArrayList) FailedShard(org.elasticsearch.cluster.routing.allocation.FailedShard) HashSet(java.util.HashSet)

Example 7 with FailedShard

use of org.elasticsearch.cluster.routing.allocation.FailedShard in project elasticsearch by elastic.

the class TestGatewayAllocator method applyFailedShards.

@Override
public void applyFailedShards(RoutingAllocation allocation, List<FailedShard> failedShards) {
    currentNodes = allocation.nodes();
    for (FailedShard failedShard : failedShards) {
        final ShardRouting failedRouting = failedShard.getRoutingEntry();
        Map<ShardId, ShardRouting> nodeAllocations = knownAllocations.get(failedRouting.currentNodeId());
        if (nodeAllocations != null) {
            nodeAllocations.remove(failedRouting.shardId());
            if (nodeAllocations.isEmpty()) {
                knownAllocations.remove(failedRouting.currentNodeId());
            }
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) FailedShard(org.elasticsearch.cluster.routing.allocation.FailedShard) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Aggregations

FailedShard (org.elasticsearch.cluster.routing.allocation.FailedShard)7 ArrayList (java.util.ArrayList)3 ClusterState (org.elasticsearch.cluster.ClusterState)3 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)3 AllocationService (org.elasticsearch.cluster.routing.allocation.AllocationService)3 HashSet (java.util.HashSet)2 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)2 MetaData (org.elasticsearch.cluster.metadata.MetaData)2 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)2 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)2 Settings (org.elasticsearch.common.settings.Settings)2 ObjectCursor (com.carrotsearch.hppc.cursors.ObjectCursor)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1