Search in sources :

Example 21 with ShardNotFoundException

use of org.elasticsearch.index.shard.ShardNotFoundException in project crate by crate.

the class ShardCollectSource method createMultiShardScoreDocCollector.

private CrateCollector createMultiShardScoreDocCollector(RoutedCollectPhase collectPhase, BatchConsumer consumer, JobCollectContext jobCollectContext, String localNodeId) {
    Map<String, Map<String, List<Integer>>> locations = collectPhase.routing().locations();
    SharedShardContexts sharedShardContexts = jobCollectContext.sharedShardContexts();
    Map<String, List<Integer>> indexShards = locations.get(localNodeId);
    List<OrderedDocCollector> orderedDocCollectors = new ArrayList<>();
    for (Map.Entry<String, List<Integer>> entry : indexShards.entrySet()) {
        String indexName = entry.getKey();
        for (Integer shardNum : entry.getValue()) {
            ShardId shardId = new ShardId(indexName, shardNum);
            SharedShardContext context = sharedShardContexts.getOrCreateContext(shardId);
            try {
                ShardCollectorProvider shardCollectorProvider = getCollectorProviderSafe(shardId);
                orderedDocCollectors.add(shardCollectorProvider.getOrderedCollector(collectPhase, context, jobCollectContext, consumer.requiresScroll()));
            } catch (ShardNotFoundException | IllegalIndexShardStateException e) {
                throw e;
            } catch (IndexNotFoundException e) {
                if (PartitionName.isPartition(indexName)) {
                    break;
                }
                throw e;
            } catch (Throwable t) {
                throw new UnhandledServerException(t);
            }
        }
    }
    OrderBy orderBy = collectPhase.orderBy();
    assert orderBy != null : "orderBy must not be null";
    return BatchIteratorCollectorBridge.newInstance(OrderedLuceneBatchIteratorFactory.newInstance(orderedDocCollectors, collectPhase.toCollect().size(), OrderingByPosition.rowOrdering(OrderByPositionVisitor.orderByPositions(orderBy.orderBySymbols(), collectPhase.toCollect()), orderBy.reverseFlags(), orderBy.nullsFirst()), executor, consumer.requiresScroll()), consumer);
}
Also used : OrderBy(io.crate.analyze.OrderBy) ArrayList(java.util.ArrayList) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) OrderedDocCollector(io.crate.operation.collect.collectors.OrderedDocCollector) ShardId(org.elasticsearch.index.shard.ShardId) SharedShardContexts(io.crate.action.job.SharedShardContexts) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) UnhandledServerException(io.crate.exceptions.UnhandledServerException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SharedShardContext(io.crate.action.job.SharedShardContext)

Example 22 with ShardNotFoundException

use of org.elasticsearch.index.shard.ShardNotFoundException in project crate by crate.

the class ShardCollectSource method getShardsCollector.

private CrateCollector getShardsCollector(RoutedCollectPhase collectPhase, RoutedCollectPhase normalizedPhase, String localNodeId, BatchConsumer consumer) {
    Map<String, Map<String, List<Integer>>> locations = collectPhase.routing().locations();
    List<UnassignedShard> unassignedShards = new ArrayList<>();
    List<Object[]> rows = new ArrayList<>();
    Map<String, List<Integer>> indexShardsMap = locations.get(localNodeId);
    for (Map.Entry<String, List<Integer>> indexShards : indexShardsMap.entrySet()) {
        String indexName = indexShards.getKey();
        List<Integer> shards = indexShards.getValue();
        IndexService indexService = indicesService.indexService(indexName);
        if (indexService == null) {
            for (Integer shard : shards) {
                unassignedShards.add(toUnassignedShard(new ShardId(indexName, UnassignedShard.markAssigned(shard))));
            }
            continue;
        }
        for (Integer shard : shards) {
            if (UnassignedShard.isUnassigned(shard)) {
                unassignedShards.add(toUnassignedShard(new ShardId(indexName, UnassignedShard.markAssigned(shard))));
                continue;
            }
            ShardId shardId = new ShardId(indexName, shard);
            try {
                ShardCollectorProvider shardCollectorProvider = getCollectorProviderSafe(shardId);
                Object[] row = shardCollectorProvider.getRowForShard(normalizedPhase);
                if (row != null) {
                    rows.add(row);
                }
            } catch (ShardNotFoundException | IllegalIndexShardStateException e) {
                unassignedShards.add(toUnassignedShard(shardId));
            } catch (Throwable t) {
                t.printStackTrace();
                throw new UnhandledServerException(t);
            }
        }
    }
    if (!unassignedShards.isEmpty()) {
        // because otherwise if _node was also selected it would contain something which is wrong
        for (Row row : systemCollectSource.toRowsIterableTransformation(collectPhase, false).apply(unassignedShards)) {
            rows.add(row.materialize());
        }
    }
    if (collectPhase.orderBy() != null) {
        rows.sort(OrderingByPosition.arrayOrdering(collectPhase).reverse());
    }
    return BatchIteratorCollectorBridge.newInstance(RowsBatchIterator.newInstance(Iterables.transform(rows, Buckets.arrayToRowFunction()), collectPhase.outputTypes().size()), consumer);
}
Also used : IndexService(org.elasticsearch.index.IndexService) ArrayList(java.util.ArrayList) UnassignedShard(io.crate.metadata.shard.unassigned.UnassignedShard) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) ShardId(org.elasticsearch.index.shard.ShardId) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) UnhandledServerException(io.crate.exceptions.UnhandledServerException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 23 with ShardNotFoundException

use of org.elasticsearch.index.shard.ShardNotFoundException in project elasticsearch by elastic.

the class TransportReplicationActionTests method mockIndexService.

final IndexService mockIndexService(final IndexMetaData indexMetaData, ClusterService clusterService) {
    final IndexService indexService = mock(IndexService.class);
    when(indexService.getShard(anyInt())).then(invocation -> {
        int shard = (Integer) invocation.getArguments()[0];
        final ShardId shardId = new ShardId(indexMetaData.getIndex(), shard);
        if (shard > indexMetaData.getNumberOfShards()) {
            throw new ShardNotFoundException(shardId);
        }
        return mockIndexShard(shardId, clusterService);
    });
    return indexService;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ShardId(org.elasticsearch.index.shard.ShardId) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) IndexService(org.elasticsearch.index.IndexService)

Example 24 with ShardNotFoundException

use of org.elasticsearch.index.shard.ShardNotFoundException in project elasticsearch by elastic.

the class TransportWriteActionTests method mockIndexService.

final IndexService mockIndexService(final IndexMetaData indexMetaData, ClusterService clusterService) {
    final IndexService indexService = mock(IndexService.class);
    when(indexService.getShard(anyInt())).then(invocation -> {
        int shard = (Integer) invocation.getArguments()[0];
        final ShardId shardId = new ShardId(indexMetaData.getIndex(), shard);
        if (shard > indexMetaData.getNumberOfShards()) {
            throw new ShardNotFoundException(shardId);
        }
        return mockIndexShard(shardId, clusterService);
    });
    return indexService;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ShardId(org.elasticsearch.index.shard.ShardId) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) IndexService(org.elasticsearch.index.IndexService)

Example 25 with ShardNotFoundException

use of org.elasticsearch.index.shard.ShardNotFoundException in project crate by crate.

the class BulkRetryCoordinatorPool method coordinator.

public BulkRetryCoordinator coordinator(ShardId shardId) throws IndexNotFoundException, ShardNotFoundException {
    synchronized (coordinatorsByShardId) {
        BulkRetryCoordinator coordinator = coordinatorsByShardId.get(shardId);
        if (coordinator == null) {
            IndexRoutingTable indexRoutingTable = clusterService.state().routingTable().index(shardId.getIndex());
            if (indexRoutingTable == null) {
                throw new IndexNotFoundException("cannot find index " + shardId.index());
            }
            IndexShardRoutingTable shardRoutingTable = indexRoutingTable.shard(shardId.id());
            if (shardRoutingTable == null) {
                throw new ShardNotFoundException(shardId);
            }
            String nodeId = shardRoutingTable.primaryShard().currentNodeId();
            // wow, that is a long comment!
            synchronized (coordinatorsByNodeId) {
                coordinator = coordinatorsByNodeId.get(nodeId);
                if (coordinator == null) {
                    LOGGER.debug("create new coordinator for node {} and shard {}", nodeId, shardId);
                    coordinator = new BulkRetryCoordinator(threadPool);
                    coordinatorsByNodeId.put(nodeId, coordinator);
                }
            }
            coordinatorsByShardId.put(shardId, coordinator);
        }
        return coordinator;
    }
}
Also used : IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Aggregations

ShardNotFoundException (org.elasticsearch.index.shard.ShardNotFoundException)33 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)23 ShardId (org.elasticsearch.index.shard.ShardId)16 ArrayList (java.util.ArrayList)9 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)9 Map (java.util.Map)8 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)8 IllegalIndexShardStateException (org.elasticsearch.index.shard.IllegalIndexShardStateException)8 ElasticsearchException (org.elasticsearch.ElasticsearchException)7 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)7 IndexService (org.elasticsearch.index.IndexService)7 IndexShard (org.elasticsearch.index.shard.IndexShard)7 IOException (java.io.IOException)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)6 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)6 RerouteExplanation (org.elasticsearch.cluster.routing.allocation.RerouteExplanation)6 List (java.util.List)5 ClusterState (org.elasticsearch.cluster.ClusterState)5 ShardCollectorProvider (io.crate.execution.engine.collect.ShardCollectorProvider)4