Search in sources :

Example 36 with IntCursor

use of com.carrotsearch.hppc.cursors.IntCursor in project crate by crate.

the class ShardCollectSource method getIterators.

private List<CompletableFuture<BatchIterator<Row>>> getIterators(CollectTask collectTask, RoutedCollectPhase collectPhase, boolean requiresScroll, Map<String, IntIndexedContainer> indexShards) {
    Metadata metadata = clusterService.state().metadata();
    List<CompletableFuture<BatchIterator<Row>>> iterators = new ArrayList<>();
    for (Map.Entry<String, IntIndexedContainer> entry : indexShards.entrySet()) {
        String indexName = entry.getKey();
        IndexMetadata indexMD = metadata.index(indexName);
        if (indexMD == null) {
            if (IndexParts.isPartitioned(indexName)) {
                continue;
            }
            throw new IndexNotFoundException(indexName);
        }
        Index index = indexMD.getIndex();
        try {
            indicesService.indexServiceSafe(index);
        } catch (IndexNotFoundException e) {
            if (IndexParts.isPartitioned(indexName)) {
                continue;
            }
            throw e;
        }
        for (IntCursor shardCursor : entry.getValue()) {
            ShardId shardId = new ShardId(index, shardCursor.value);
            try {
                ShardCollectorProvider shardCollectorProvider = getCollectorProviderSafe(shardId);
                CompletableFuture<BatchIterator<Row>> iterator = shardCollectorProvider.getFutureIterator(collectPhase, requiresScroll, collectTask);
                iterators.add(iterator);
            } catch (ShardNotFoundException | IllegalIndexShardStateException e) {
                // and the reader required in the fetchPhase would be missing.
                if (Symbols.containsColumn(collectPhase.toCollect(), DocSysColumns.FETCHID)) {
                    throw e;
                }
                iterators.add(remoteCollectorFactory.createCollector(shardId, collectPhase, collectTask, shardCollectorProviderFactory));
            } catch (IndexNotFoundException e) {
                // Prevent wrapping this to not break retry-detection
                throw e;
            } catch (Throwable t) {
                Exceptions.rethrowRuntimeException(t);
            }
        }
    }
    return iterators;
}
Also used : IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) ArrayList(java.util.ArrayList) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) Index(org.elasticsearch.index.Index) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) CompositeBatchIterator(io.crate.data.CompositeBatchIterator) BatchIterator(io.crate.data.BatchIterator) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) ShardId(org.elasticsearch.index.shard.ShardId) CompletableFuture(java.util.concurrent.CompletableFuture) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) ShardCollectorProvider(io.crate.execution.engine.collect.ShardCollectorProvider) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Row(io.crate.data.Row) SentinelRow(io.crate.data.SentinelRow) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 37 with IntCursor

use of com.carrotsearch.hppc.cursors.IntCursor in project crate by crate.

the class PlanPrinter method xContentSafeRoutingLocations.

/**
 * Converts the shardId's of each node->table from a {@link IntIndexedContainer} to a list of Integers as custom
 * classes are not supported by the {@link org.elasticsearch.common.xcontent.XContentBuilder}.
 */
private static Map<String, Map<String, List<Integer>>> xContentSafeRoutingLocations(Map<String, Map<String, IntIndexedContainer>> locations) {
    HashMap<String, Map<String, List<Integer>>> safeLocations = new HashMap<>(locations.size(), 1f);
    for (Map.Entry<String, Map<String, IntIndexedContainer>> nodeEntry : locations.entrySet()) {
        HashMap<String, List<Integer>> tableShards = new HashMap<>(nodeEntry.getValue().size(), 1f);
        for (Map.Entry<String, IntIndexedContainer> tableEntry : nodeEntry.getValue().entrySet()) {
            ArrayList<Integer> shardList = new ArrayList<>(tableEntry.getValue().size());
            for (IntCursor cursor : tableEntry.getValue()) {
                shardList.add(cursor.value);
            }
            // ensure a deterministic shard list by sorting it (important for test assertions but maybe also for apps)
            shardList.sort(Integer::compareTo);
            tableShards.put(tableEntry.getKey(), shardList);
        }
        safeLocations.put(nodeEntry.getKey(), tableShards);
    }
    return safeLocations;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

IntCursor (com.carrotsearch.hppc.cursors.IntCursor)37 Map (java.util.Map)11 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)8 ArrayList (java.util.ArrayList)7 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)5 HashMap (java.util.HashMap)5 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)5 Index (org.elasticsearch.index.Index)5 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)5 IntArrayList (com.carrotsearch.hppc.IntArrayList)4 TreeMap (java.util.TreeMap)4 Metadata (org.elasticsearch.cluster.metadata.Metadata)4 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)3 ConnectedComponents (com.graphhopper.routing.subnetwork.EdgeBasedTarjanSCC.ConnectedComponents)3 GraphBuilder (com.graphhopper.storage.GraphBuilder)3 ShardCollectorProvider (io.crate.execution.engine.collect.ShardCollectorProvider)3 RelationName (io.crate.metadata.RelationName)3 TransactionContext (io.crate.metadata.TransactionContext)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3