Search in sources :

Example 21 with IntIndexedContainer

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

the class AlternativeRouteCH method tTest.

private boolean tTest(Path path, int vIndex) {
    if (path.getEdgeCount() == 0)
        return true;
    double detourDistance = detourDistance(path);
    double T = 0.5 * localOptimalityFactor * detourDistance;
    int fromNode = getPreviousNodeTMetersAway(path, vIndex, T);
    int toNode = getNextNodeTMetersAway(path, vIndex, T);
    DijkstraBidirectionCH tRouter = new DijkstraBidirectionCH(graph);
    Path tPath = tRouter.calcPath(fromNode, toNode);
    extraVisitedNodes += tRouter.getVisitedNodes();
    IntIndexedContainer tNodes = tPath.calcNodes();
    int v = path.calcNodes().get(vIndex);
    return tNodes.contains(v);
}
Also used : IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer)

Example 22 with IntIndexedContainer

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

the class Routing method numShards.

/**
 * get the number of shards in this routing for a node with given nodeId
 *
 * @return int >= 0
 */
public int numShards(String nodeId) {
    Map<String, IntIndexedContainer> indicesAndShards = locations.get(nodeId);
    if (indicesAndShards == null) {
        return 0;
    }
    int numShards = 0;
    for (IntIndexedContainer shardIds : indicesAndShards.values()) {
        numShards += shardIds.size();
    }
    return numShards;
}
Also used : IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer)

Example 23 with IntIndexedContainer

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

the class RoutingProvider method processShardRouting.

private static void processShardRouting(Map<String, Map<String, IntIndexedContainer>> locations, ShardRouting shardRouting) {
    String node = shardRouting.currentNodeId();
    Map<String, IntIndexedContainer> nodeMap = locations.get(node);
    if (nodeMap == null) {
        nodeMap = new TreeMap<>();
        locations.put(shardRouting.currentNodeId(), nodeMap);
    }
    String indexName = shardRouting.getIndexName();
    IntIndexedContainer shards = nodeMap.get(indexName);
    if (shards == null) {
        shards = new IntArrayList();
        nodeMap.put(indexName, shards);
    }
    shards.add(shardRouting.id());
}
Also used : IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) IntArrayList(com.carrotsearch.hppc.IntArrayList)

Example 24 with IntIndexedContainer

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

the class InternalCountOperationTest method testCount.

@Test
public void testCount() throws Exception {
    execute("create table t (name string) clustered into 1 shards with (number_of_replicas = 0)");
    ensureYellow();
    execute("insert into t (name) values ('Marvin'), ('Arthur'), ('Trillian')");
    execute("refresh table t");
    CountOperation countOperation = internalCluster().getDataNodeInstance(CountOperation.class);
    ClusterService clusterService = internalCluster().getDataNodeInstance(ClusterService.class);
    CoordinatorTxnCtx txnCtx = CoordinatorTxnCtx.systemTransactionContext();
    Metadata metadata = clusterService.state().getMetadata();
    Index index = metadata.index(getFqn("t")).getIndex();
    IntArrayList shards = new IntArrayList(1);
    shards.add(0);
    Map<String, IntIndexedContainer> indexShards = Map.of(index.getName(), shards);
    {
        CompletableFuture<Long> count = countOperation.count(txnCtx, indexShards, Literal.BOOLEAN_TRUE);
        assertThat(count.get(5, TimeUnit.SECONDS), is(3L));
    }
    Schemas schemas = internalCluster().getInstance(Schemas.class);
    TableInfo tableInfo = schemas.getTableInfo(new RelationName(sqlExecutor.getCurrentSchema(), "t"));
    TableRelation tableRelation = new TableRelation(tableInfo);
    Map<RelationName, AnalyzedRelation> tableSources = Map.of(tableInfo.ident(), tableRelation);
    SqlExpressions sqlExpressions = new SqlExpressions(tableSources, tableRelation);
    Symbol filter = sqlExpressions.normalize(sqlExpressions.asSymbol("name = 'Marvin'"));
    {
        CompletableFuture<Long> count = countOperation.count(txnCtx, indexShards, filter);
        assertThat(count.get(5, TimeUnit.SECONDS), is(1L));
    }
}
Also used : CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Symbol(io.crate.expression.symbol.Symbol) Metadata(org.elasticsearch.cluster.metadata.Metadata) Index(org.elasticsearch.index.Index) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) Schemas(io.crate.metadata.Schemas) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) TableRelation(io.crate.analyze.relations.TableRelation) CompletableFuture(java.util.concurrent.CompletableFuture) ClusterService(org.elasticsearch.cluster.service.ClusterService) RelationName(io.crate.metadata.RelationName) TableInfo(io.crate.metadata.table.TableInfo) IntArrayList(com.carrotsearch.hppc.IntArrayList) SqlExpressions(io.crate.testing.SqlExpressions) Test(org.junit.Test)

Example 25 with IntIndexedContainer

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

the class ShardCollectSource method getIterator.

@Override
public CompletableFuture<BatchIterator<Row>> getIterator(TransactionContext txnCtx, CollectPhase phase, CollectTask collectTask, boolean supportMoveToStart) {
    RoutedCollectPhase collectPhase = (RoutedCollectPhase) phase;
    String localNodeId = clusterService.localNode().getId();
    Projectors projectors = new Projectors(collectPhase.projections(), collectPhase.jobId(), collectTask.txnCtx(), collectTask.getRamAccounting(), collectTask.memoryManager(), sharedProjectorFactory);
    boolean requireMoveToStartSupport = supportMoveToStart && !projectors.providesIndependentScroll();
    if (collectPhase.maxRowGranularity() == RowGranularity.SHARD) {
        return CompletableFuture.completedFuture(projectors.wrap(InMemoryBatchIterator.of(getShardsIterator(collectTask.txnCtx(), collectPhase, localNodeId), SentinelRow.SENTINEL, true)));
    }
    OrderBy orderBy = collectPhase.orderBy();
    if (collectPhase.maxRowGranularity() == RowGranularity.DOC && orderBy != null) {
        return createMultiShardScoreDocCollector(collectPhase, requireMoveToStartSupport, collectTask, localNodeId).thenApply(projectors::wrap);
    }
    boolean hasShardProjections = Projections.hasAnyShardProjections(collectPhase.projections());
    Map<String, IntIndexedContainer> indexShards = collectPhase.routing().locations().get(localNodeId);
    List<CompletableFuture<BatchIterator<Row>>> iterators = indexShards == null ? Collections.emptyList() : getIterators(collectTask, collectPhase, requireMoveToStartSupport, indexShards);
    final CompletableFuture<BatchIterator<Row>> result;
    switch(iterators.size()) {
        case 0:
            result = CompletableFuture.completedFuture(InMemoryBatchIterator.empty(SentinelRow.SENTINEL));
            break;
        case 1:
            result = iterators.get(0);
            break;
        default:
            if (hasShardProjections) {
                // use AsyncCompositeBatchIterator for multi-threaded loadNextBatch
                // in order to process shard-based projections concurrently
                // noinspection unchecked
                result = CompletableFutures.allAsList(iterators).thenApply(its -> CompositeBatchIterator.asyncComposite(executor, availableThreads, its.toArray(new BatchIterator[0])));
            } else {
                // noinspection unchecked
                result = CompletableFutures.allAsList(iterators).thenApply(its -> CompositeBatchIterator.seqComposite(its.toArray(new BatchIterator[0])));
            }
    }
    return result.thenApply(it -> projectors.wrap(it));
}
Also used : OrderBy(io.crate.analyze.OrderBy) ShardId(org.elasticsearch.index.shard.ShardId) IndexParts(io.crate.metadata.IndexParts) TransactionContext(io.crate.metadata.TransactionContext) Projections(io.crate.execution.dsl.projection.Projections) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) OrderedDocCollector(io.crate.execution.engine.collect.collectors.OrderedDocCollector) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) NodeLimits(io.crate.execution.jobs.NodeLimits) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) ProjectorFactory(io.crate.execution.engine.pipeline.ProjectorFactory) Settings(org.elasticsearch.common.settings.Settings) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Map(java.util.Map) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ThreadPools.numIdleThreads(io.crate.execution.support.ThreadPools.numIdleThreads) OrderingByPosition(io.crate.execution.engine.sort.OrderingByPosition) ShardRowContext(io.crate.expression.reference.sys.shard.ShardRowContext) DocSysColumns(io.crate.metadata.doc.DocSysColumns) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) NodeContext(io.crate.metadata.NodeContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) OrderedLuceneBatchIteratorFactory(io.crate.execution.engine.collect.collectors.OrderedLuceneBatchIteratorFactory) StaticTableReferenceResolver(io.crate.expression.reference.StaticTableReferenceResolver) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CompletableFutures(io.crate.concurrent.CompletableFutures) RowsTransformer(io.crate.execution.engine.collect.RowsTransformer) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) Iterables(io.crate.common.collections.Iterables) CollectTask(io.crate.execution.engine.collect.CollectTask) SysShardsTableInfo(io.crate.metadata.sys.SysShardsTableInfo) OrderByPositionVisitor(io.crate.planner.consumer.OrderByPositionVisitor) List(java.util.List) Exceptions(io.crate.exceptions.Exceptions) Logger(org.apache.logging.log4j.Logger) OrderBy(io.crate.analyze.OrderBy) Row(io.crate.data.Row) Singleton(org.elasticsearch.common.inject.Singleton) Projectors(io.crate.execution.engine.pipeline.Projectors) SharedShardContext(io.crate.execution.jobs.SharedShardContext) SentinelRow(io.crate.data.SentinelRow) MapBackedRefResolver(io.crate.metadata.MapBackedRefResolver) CompositeBatchIterator(io.crate.data.CompositeBatchIterator) RemoteCollectorFactory(io.crate.execution.engine.collect.RemoteCollectorFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ClusterService(org.elasticsearch.cluster.service.ClusterService) RowAccountingWithEstimators(io.crate.breaker.RowAccountingWithEstimators) CompletableFuture(java.util.concurrent.CompletableFuture) BatchIterator(io.crate.data.BatchIterator) Index(org.elasticsearch.index.Index) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Inject(org.elasticsearch.common.inject.Inject) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) Metadata(org.elasticsearch.cluster.metadata.Metadata) UnassignedShard(io.crate.metadata.shard.unassigned.UnassignedShard) Symbols(io.crate.expression.symbol.Symbols) CollectPhase(io.crate.execution.dsl.phases.CollectPhase) IndicesService(org.elasticsearch.indices.IndicesService) IntSupplier(java.util.function.IntSupplier) Nullable(javax.annotation.Nullable) EsExecutors(org.elasticsearch.common.util.concurrent.EsExecutors) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) Executor(java.util.concurrent.Executor) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) DataType(io.crate.types.DataType) ProjectionToProjectorVisitor(io.crate.execution.engine.pipeline.ProjectionToProjectorVisitor) TransportActionProvider(io.crate.execution.TransportActionProvider) RowGranularity(io.crate.metadata.RowGranularity) ShardCollectorProvider(io.crate.execution.engine.collect.ShardCollectorProvider) Suppliers(io.crate.common.Suppliers) InputFactory(io.crate.expression.InputFactory) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) CompositeBatchIterator(io.crate.data.CompositeBatchIterator) BatchIterator(io.crate.data.BatchIterator) Projectors(io.crate.execution.engine.pipeline.Projectors) CompletableFuture(java.util.concurrent.CompletableFuture) Row(io.crate.data.Row) SentinelRow(io.crate.data.SentinelRow) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase)

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