Search in sources :

Example 1 with StaleShard

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

the class ShardFailedClusterStateTaskExecutorTests method testTriviallySuccessfulTasksBatchedWithFailingTasks.

public void testTriviallySuccessfulTasksBatchedWithFailingTasks() throws Exception {
    String reason = "test trivially successful tasks batched with failing tasks";
    ClusterState currentState = createClusterStateWithStartedShards(reason);
    List<ShardStateAction.ShardEntry> failingTasks = createExistingShards(currentState, reason);
    List<ShardStateAction.ShardEntry> nonExistentTasks = createNonExistentShards(currentState, reason);
    ShardStateAction.ShardFailedClusterStateTaskExecutor failingExecutor = new ShardStateAction.ShardFailedClusterStateTaskExecutor(allocationService, null, logger) {

        @Override
        ClusterState applyFailedShards(ClusterState currentState, List<FailedShard> failedShards, List<StaleShard> staleShards) {
            throw new RuntimeException("simulated applyFailedShards failure");
        }
    };
    List<ShardStateAction.ShardEntry> tasks = new ArrayList<>();
    tasks.addAll(failingTasks);
    tasks.addAll(nonExistentTasks);
    ClusterStateTaskExecutor.ClusterTasksResult<ShardStateAction.ShardEntry> result = failingExecutor.execute(currentState, tasks);
    Map<ShardStateAction.ShardEntry, ClusterStateTaskExecutor.TaskResult> taskResultMap = failingTasks.stream().collect(Collectors.toMap(Function.identity(), task -> ClusterStateTaskExecutor.TaskResult.failure(new RuntimeException("simulated applyFailedShards failure"))));
    taskResultMap.putAll(nonExistentTasks.stream().collect(Collectors.toMap(Function.identity(), task -> ClusterStateTaskExecutor.TaskResult.success())));
    assertTaskResults(taskResultMap, result, currentState, false);
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) ShardId(org.elasticsearch.index.shard.ShardId) IntStream(java.util.stream.IntStream) ESAllocationTestCase(org.elasticsearch.cluster.ESAllocationTestCase) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) Index(org.elasticsearch.index.Index) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) Function(java.util.function.Function) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) GroupShardsIterator(org.elasticsearch.cluster.routing.GroupShardsIterator) ArrayList(java.util.ArrayList) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) ClusterName(org.elasticsearch.cluster.ClusterName) RoutingNodes(org.elasticsearch.cluster.routing.RoutingNodes) ClusterRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) Before(org.junit.Before) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) UUIDs(org.elasticsearch.common.UUIDs) ClusterStateTaskExecutor(org.elasticsearch.cluster.ClusterStateTaskExecutor) StaleShard(org.elasticsearch.cluster.routing.allocation.StaleShard) ObjectCursor(com.carrotsearch.hppc.cursors.ObjectCursor) Collectors(java.util.stream.Collectors) List(java.util.List) Version(org.elasticsearch.Version) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) FailedShard(org.elasticsearch.cluster.routing.allocation.FailedShard) Collections(java.util.Collections) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) ClusterState(org.elasticsearch.cluster.ClusterState) ArrayList(java.util.ArrayList) ClusterStateTaskExecutor(org.elasticsearch.cluster.ClusterStateTaskExecutor) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ObjectCursor (com.carrotsearch.hppc.cursors.ObjectCursor)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)1 Version (org.elasticsearch.Version)1 ClusterName (org.elasticsearch.cluster.ClusterName)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 ClusterStateTaskExecutor (org.elasticsearch.cluster.ClusterStateTaskExecutor)1 ESAllocationTestCase (org.elasticsearch.cluster.ESAllocationTestCase)1 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)1 MetaData (org.elasticsearch.cluster.metadata.MetaData)1 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)1 GroupShardsIterator (org.elasticsearch.cluster.routing.GroupShardsIterator)1 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)1 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)1