Search in sources :

Example 1 with IntIndexedContainer

use of com.carrotsearch.hppc.IntIndexedContainer in project graphhopper by graphhopper.

the class PrepareRoutingSubnetworks method keepLargeNetworks.

/**
 * Deletes all but the largest subnetworks.
 */
int keepLargeNetworks(PrepEdgeFilter filter, List<IntArrayList> components) {
    if (components.size() <= 1)
        return 0;
    int maxCount = -1;
    IntIndexedContainer oldComponent = null;
    int allRemoved = 0;
    FlagEncoder encoder = filter.getEncoder();
    EdgeExplorer explorer = ghStorage.createEdgeExplorer(filter);
    for (IntArrayList component : components) {
        if (maxCount < 0) {
            maxCount = component.size();
            oldComponent = component;
            continue;
        }
        int removedEdges;
        if (maxCount < component.size()) {
            // new biggest area found. remove old
            removedEdges = removeEdges(explorer, encoder, oldComponent, minNetworkSize);
            maxCount = component.size();
            oldComponent = component;
        } else {
            removedEdges = removeEdges(explorer, encoder, component, minNetworkSize);
        }
        allRemoved += removedEdges;
    }
    if (allRemoved > ghStorage.getAllEdges().getMaxId() / 2)
        throw new IllegalStateException("Too many total edges were removed: " + allRemoved + ", all edges:" + ghStorage.getAllEdges().getMaxId());
    return allRemoved;
}
Also used : FlagEncoder(com.graphhopper.routing.util.FlagEncoder) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) GHIntArrayList(com.graphhopper.coll.GHIntArrayList) IntArrayList(com.carrotsearch.hppc.IntArrayList)

Example 2 with IntIndexedContainer

use of com.carrotsearch.hppc.IntIndexedContainer in project crate by crate.

the class ShardCollectSource method createMultiShardScoreDocCollector.

private CompletableFuture<BatchIterator<Row>> createMultiShardScoreDocCollector(RoutedCollectPhase collectPhase, boolean supportMoveToStart, CollectTask collectTask, String localNodeId) {
    Map<String, Map<String, IntIndexedContainer>> locations = collectPhase.routing().locations();
    SharedShardContexts sharedShardContexts = collectTask.sharedShardContexts();
    Map<String, IntIndexedContainer> indexShards = locations.get(localNodeId);
    List<CompletableFuture<OrderedDocCollector>> orderedDocCollectors = new ArrayList<>();
    Metadata metadata = clusterService.state().metadata();
    for (Map.Entry<String, IntIndexedContainer> entry : indexShards.entrySet()) {
        String indexName = entry.getKey();
        Index index = metadata.index(indexName).getIndex();
        for (IntCursor shard : entry.getValue()) {
            ShardId shardId = new ShardId(index, shard.value);
            try {
                SharedShardContext context = sharedShardContexts.getOrCreateContext(shardId);
                ShardCollectorProvider shardCollectorProvider = getCollectorProviderSafe(shardId);
                orderedDocCollectors.add(shardCollectorProvider.getFutureOrderedCollector(collectPhase, context, collectTask, supportMoveToStart));
            } catch (ShardNotFoundException | IllegalIndexShardStateException e) {
                throw e;
            } catch (IndexNotFoundException e) {
                if (IndexParts.isPartitioned(indexName)) {
                    break;
                }
                throw e;
            }
        }
    }
    List<DataType<?>> columnTypes = Symbols.typeView(collectPhase.toCollect());
    OrderBy orderBy = collectPhase.orderBy();
    assert orderBy != null : "orderBy must not be null";
    return CompletableFutures.allAsList(orderedDocCollectors).thenApply(collectors -> OrderedLuceneBatchIteratorFactory.newInstance(collectors, OrderingByPosition.rowOrdering(OrderByPositionVisitor.orderByPositions(orderBy.orderBySymbols(), collectPhase.toCollect()), orderBy.reverseFlags(), orderBy.nullsFirst()), new RowAccountingWithEstimators(columnTypes, collectTask.getRamAccounting()), executor, availableThreads, supportMoveToStart));
}
Also used : OrderBy(io.crate.analyze.OrderBy) ArrayList(java.util.ArrayList) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) Index(org.elasticsearch.index.Index) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) ShardId(org.elasticsearch.index.shard.ShardId) CompletableFuture(java.util.concurrent.CompletableFuture) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) RowAccountingWithEstimators(io.crate.breaker.RowAccountingWithEstimators) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) ShardCollectorProvider(io.crate.execution.engine.collect.ShardCollectorProvider) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) DataType(io.crate.types.DataType) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SharedShardContext(io.crate.execution.jobs.SharedShardContext)

Example 3 with IntIndexedContainer

use of com.carrotsearch.hppc.IntIndexedContainer in project crate by crate.

the class ShardCollectSource method getShardsIterator.

private Iterable<Row> getShardsIterator(TransactionContext txnCtx, RoutedCollectPhase collectPhase, String localNodeId) {
    Map<String, Map<String, IntIndexedContainer>> locations = collectPhase.routing().locations();
    List<UnassignedShard> unassignedShards = new ArrayList<>();
    List<ShardRowContext> shardRowContexts = new ArrayList<>();
    Map<String, IntIndexedContainer> indexShardsMap = locations.get(localNodeId);
    Metadata metadata = clusterService.state().metadata();
    for (Map.Entry<String, IntIndexedContainer> indexShards : indexShardsMap.entrySet()) {
        String indexName = indexShards.getKey();
        IndexMetadata indexMetadata = metadata.index(indexName);
        if (indexMetadata == null) {
            continue;
        }
        Index index = indexMetadata.getIndex();
        IntIndexedContainer shards = indexShards.getValue();
        IndexService indexService = indicesService.indexService(index);
        if (indexService == null) {
            for (IntCursor shard : shards) {
                unassignedShards.add(toUnassignedShard(index.getName(), UnassignedShard.markAssigned(shard.value)));
            }
            continue;
        }
        for (IntCursor shard : shards) {
            if (UnassignedShard.isUnassigned(shard.value)) {
                unassignedShards.add(toUnassignedShard(index.getName(), UnassignedShard.markAssigned(shard.value)));
                continue;
            }
            ShardId shardId = new ShardId(index, shard.value);
            try {
                ShardCollectorProvider shardCollectorProvider = getCollectorProviderSafe(shardId);
                shardRowContexts.add(shardCollectorProvider.shardRowContext());
            } catch (ShardNotFoundException | IllegalIndexShardStateException e) {
                unassignedShards.add(toUnassignedShard(index.getName(), shard.value));
            }
        }
    }
    Iterable<Row> assignedShardRows = RowsTransformer.toRowsIterable(txnCtx, inputFactory, shardReferenceResolver, collectPhase, shardRowContexts, false);
    Iterable<Row> rows;
    if (unassignedShards.size() > 0) {
        Iterable<Row> unassignedShardRows = RowsTransformer.toRowsIterable(txnCtx, inputFactory, unassignedShardReferenceResolver, collectPhase, unassignedShards, false);
        rows = Iterables.concat(assignedShardRows, unassignedShardRows);
    } else {
        rows = assignedShardRows;
    }
    if (collectPhase.orderBy() != null) {
        return RowsTransformer.sortRows(Iterables.transform(rows, Row::materialize), collectPhase);
    }
    return rows;
}
Also used : IndexService(org.elasticsearch.index.IndexService) ArrayList(java.util.ArrayList) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) Index(org.elasticsearch.index.Index) UnassignedShard(io.crate.metadata.shard.unassigned.UnassignedShard) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) ShardId(org.elasticsearch.index.shard.ShardId) ShardRowContext(io.crate.expression.reference.sys.shard.ShardRowContext) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) ShardCollectorProvider(io.crate.execution.engine.collect.ShardCollectorProvider) 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 4 with IntIndexedContainer

use of com.carrotsearch.hppc.IntIndexedContainer in project crate by crate.

the class InternalCountOperation method count.

@Override
public CompletableFuture<Long> count(TransactionContext txnCtx, Map<String, IntIndexedContainer> indexShardMap, Symbol filter) {
    List<CompletableFuture<Supplier<Long>>> futureSuppliers = new ArrayList<>();
    Metadata metadata = clusterService.state().getMetadata();
    for (Map.Entry<String, IntIndexedContainer> entry : indexShardMap.entrySet()) {
        String indexName = entry.getKey();
        IndexMetadata indexMetadata = metadata.index(indexName);
        if (indexMetadata == null) {
            if (IndexParts.isPartitioned(indexName)) {
                continue;
            }
            throw new IndexNotFoundException(indexName);
        }
        final Index index = indexMetadata.getIndex();
        for (IntCursor shardCursor : entry.getValue()) {
            int shardValue = shardCursor.value;
            futureSuppliers.add(prepareGetCount(txnCtx, index, shardValue, filter));
        }
    }
    MergePartialCountFunction mergeFunction = new MergePartialCountFunction();
    return CompletableFutures.allAsList(futureSuppliers).thenCompose(suppliers -> ThreadPools.runWithAvailableThreads(executor, ThreadPools.numIdleThreads(executor, numProcessors), suppliers)).thenApply(mergeFunction);
}
Also used : IndexParts(io.crate.metadata.IndexParts) TransactionContext(io.crate.metadata.TransactionContext) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) RelationName(io.crate.metadata.RelationName) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) ClusterService(org.elasticsearch.cluster.service.ClusterService) LuceneQueryBuilder(io.crate.lucene.LuceneQueryBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) Index(org.elasticsearch.index.Index) Operation(io.crate.metadata.table.Operation) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Inject(org.elasticsearch.common.inject.Inject) ArrayList(java.util.ArrayList) Metadata(org.elasticsearch.cluster.metadata.Metadata) Settings(org.elasticsearch.common.settings.Settings) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) IndicesService(org.elasticsearch.indices.IndicesService) DocTableInfo(io.crate.metadata.doc.DocTableInfo) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) JobKilledException(io.crate.exceptions.JobKilledException) EsExecutors(org.elasticsearch.common.util.concurrent.EsExecutors) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IOException(java.io.IOException) CompletableFutures(io.crate.concurrent.CompletableFutures) Engine(org.elasticsearch.index.engine.Engine) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Symbol(io.crate.expression.symbol.Symbol) Singleton(org.elasticsearch.common.inject.Singleton) Schemas(io.crate.metadata.Schemas) ThreadPools(io.crate.execution.support.ThreadPools) ArrayList(java.util.ArrayList) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) Index(org.elasticsearch.index.Index) CompletableFuture(java.util.concurrent.CompletableFuture) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Map(java.util.Map)

Example 5 with IntIndexedContainer

use of com.carrotsearch.hppc.IntIndexedContainer in project crate by crate.

the class RoutingBuilder method buildReaderAllocations.

ReaderAllocations buildReaderAllocations() {
    Map<RelationName, Collection<String>> indicesByTable = new HashMap<>();
    IndexBaseBuilder indexBaseBuilder = new IndexBaseBuilder();
    Map<String, Map<Integer, String>> shardNodes = new HashMap<>();
    Map<RelationName, List<Routing>> routingListByTable = routingListByTableStack.removeLast();
    assert routingListByTable != null : "Call to `buildReaderAllocations` without prior `newAllocations` call";
    for (var tableRouting : routingListByTable.entrySet()) {
        RelationName table = tableRouting.getKey();
        List<Routing> routingList = tableRouting.getValue();
        for (Routing routing : routingList) {
            allocateRoutingNodes(shardNodes, routing.locations());
            for (Map.Entry<String, Map<String, IntIndexedContainer>> entry : routing.locations().entrySet()) {
                Map<String, IntIndexedContainer> shardsByIndex = entry.getValue();
                Collection<String> indices = indicesByTable.computeIfAbsent(table, ignored -> new ArrayList<>());
                indices.addAll(shardsByIndex.keySet());
                for (Map.Entry<String, IntIndexedContainer> shardsByIndexEntry : shardsByIndex.entrySet()) {
                    indexBaseBuilder.allocate(shardsByIndexEntry.getKey(), shardsByIndexEntry.getValue());
                }
            }
        }
    }
    return new ReaderAllocations(indexBaseBuilder.build(), shardNodes, indicesByTable);
}
Also used : HashMap(java.util.HashMap) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) Routing(io.crate.metadata.Routing) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) IndexBaseBuilder(io.crate.planner.fetch.IndexBaseBuilder) RelationName(io.crate.metadata.RelationName) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)30 Map (java.util.Map)17 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)10 ArrayList (java.util.ArrayList)10 TreeMap (java.util.TreeMap)7 Index (org.elasticsearch.index.Index)7 IntArrayList (com.carrotsearch.hppc.IntArrayList)6 RelationName (io.crate.metadata.RelationName)6 List (java.util.List)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)6 Metadata (org.elasticsearch.cluster.metadata.Metadata)6 ShardId (org.elasticsearch.index.shard.ShardId)6 Test (org.junit.Test)6 Routing (io.crate.metadata.Routing)5 ClusterService (org.elasticsearch.cluster.service.ClusterService)5 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)5 ShardCollectorProvider (io.crate.execution.engine.collect.ShardCollectorProvider)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 IllegalIndexShardStateException (org.elasticsearch.index.shard.IllegalIndexShardStateException)4