Search in sources :

Example 16 with IntCursor

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

the class RoutingBuilder method allocateRoutingNodes.

private static void allocateRoutingNodes(Map<String, Map<Integer, String>> shardNodes, Map<String, Map<String, IntIndexedContainer>> locations) {
    for (Map.Entry<String, Map<String, IntIndexedContainer>> indicesByNodeId : locations.entrySet()) {
        String nodeId = indicesByNodeId.getKey();
        for (Map.Entry<String, IntIndexedContainer> shardsByIndexEntry : indicesByNodeId.getValue().entrySet()) {
            String index = shardsByIndexEntry.getKey();
            IntIndexedContainer shards = shardsByIndexEntry.getValue();
            Map<Integer, String> shardsOnIndex = shardNodes.get(index);
            if (shardsOnIndex == null) {
                shardsOnIndex = new HashMap<>(shards.size());
                shardNodes.put(index, shardsOnIndex);
                for (IntCursor id : shards) {
                    shardsOnIndex.put(id.value, nodeId);
                }
            } else {
                for (IntCursor id : shards) {
                    String allocatedNodeId = shardsOnIndex.get(id.value);
                    assert allocatedNodeId == null || allocatedNodeId.equals(nodeId) : "allocatedNodeId must match nodeId";
                    shardsOnIndex.put(id.value, nodeId);
                }
            }
        }
    }
}
Also used : IntCursor(com.carrotsearch.hppc.cursors.IntCursor) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with IntCursor

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

the class JobSetup method prepareOnRemote.

public List<CompletableFuture<StreamBucket>> prepareOnRemote(SessionSettings sessionInfo, Collection<? extends NodeOperation> nodeOperations, RootTask.Builder contextBuilder, SharedShardContexts sharedShardContexts) {
    Context context = new Context(clusterService.localNode().getId(), sessionInfo, contextBuilder, LOGGER, distributingConsumerFactory, nodeOperations, sharedShardContexts);
    registerContextPhases(nodeOperations, context);
    LOGGER.trace("prepareOnRemote: nodeOperations={}, targetSourceMap={}", nodeOperations, context.opCtx.targetToSourceMap);
    for (IntCursor cursor : context.opCtx.findLeafs()) {
        prepareSourceOperations(cursor.value, context);
    }
    assert context.opCtx.allNodeOperationContextsBuilt() : "some nodeOperations haven't been processed";
    return context.directResponseFutures;
}
Also used : TransactionContext(io.crate.metadata.TransactionContext) NodeContext(io.crate.metadata.NodeContext) IntCursor(com.carrotsearch.hppc.cursors.IntCursor)

Example 18 with IntCursor

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

the class JobSetup method prepareSourceOperations.

/**
 * recursively build all contexts that depend on startPhaseId (excl. startPhaseId)
 * <p>
 * {@link Context#opCtx#targetToSourceMap} will be used to traverse the nodeOperations
 */
private void prepareSourceOperations(int startPhaseId, Context context) {
    IntContainer sourcePhaseIds = context.opCtx.targetToSourceMap.get(startPhaseId);
    if (sourcePhaseIds == null) {
        return;
    }
    for (IntCursor sourcePhaseId : sourcePhaseIds) {
        NodeOperation nodeOperation = context.opCtx.nodeOperationByPhaseId.get(sourcePhaseId.value);
        createContexts(nodeOperation.executionPhase(), context);
        context.opCtx.builtNodeOperations.set(nodeOperation.executionPhase().phaseId());
    }
    for (IntCursor sourcePhaseId : sourcePhaseIds) {
        prepareSourceOperations(sourcePhaseId.value, context);
    }
}
Also used : IntContainer(com.carrotsearch.hppc.IntContainer) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) NodeOperation(io.crate.execution.dsl.phases.NodeOperation)

Example 19 with IntCursor

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

the class FetchTask method start.

@Override
public void start() {
    synchronized (jobId) {
        if (killed != null) {
            result.completeExceptionally(killed);
            return;
        }
        HashMap<String, RelationName> index2TableIdent = new HashMap<>();
        for (Map.Entry<RelationName, Collection<String>> entry : phase.tableIndices().entrySet()) {
            for (String indexName : entry.getValue()) {
                index2TableIdent.put(indexName, entry.getKey());
            }
        }
        Set<RelationName> tablesWithFetchRefs = new HashSet<>();
        for (Reference reference : phase.fetchRefs()) {
            tablesWithFetchRefs.add(reference.ident().tableIdent());
        }
        String source = "fetch-task: " + jobId.toString() + '-' + phase.phaseId() + '-' + phase.name();
        for (Routing routing : routingIterable) {
            Map<String, Map<String, IntIndexedContainer>> locations = routing.locations();
            Map<String, IntIndexedContainer> indexShards = locations.get(localNodeId);
            for (Map.Entry<String, IntIndexedContainer> indexShardsEntry : indexShards.entrySet()) {
                String indexName = indexShardsEntry.getKey();
                Integer base = phase.bases().get(indexName);
                if (base == null) {
                    continue;
                }
                IndexMetadata indexMetadata = metadata.index(indexName);
                if (indexMetadata == null) {
                    if (IndexParts.isPartitioned(indexName)) {
                        continue;
                    }
                    throw new IndexNotFoundException(indexName);
                }
                Index index = indexMetadata.getIndex();
                RelationName ident = index2TableIdent.get(indexName);
                assert ident != null : "no relationName found for index " + indexName;
                tableIdents.put(base, ident);
                toFetch.put(ident, new ArrayList<>());
                for (IntCursor shard : indexShardsEntry.getValue()) {
                    ShardId shardId = new ShardId(index, shard.value);
                    int readerId = base + shardId.id();
                    SharedShardContext shardContext = shardContexts.get(readerId);
                    if (shardContext == null) {
                        try {
                            shardContext = sharedShardContexts.createContext(shardId, readerId);
                            shardContexts.put(readerId, shardContext);
                            if (tablesWithFetchRefs.contains(ident)) {
                                searchers.put(readerId, shardContext.acquireSearcher(source));
                            }
                        } catch (IndexNotFoundException e) {
                            if (!IndexParts.isPartitioned(indexName)) {
                                throw e;
                            }
                        }
                    }
                }
            }
        }
        for (Reference reference : phase.fetchRefs()) {
            Collection<Reference> references = toFetch.get(reference.ident().tableIdent());
            if (references != null) {
                references.add(reference);
            }
        }
    }
    if (searchers.isEmpty() || phase.fetchRefs().isEmpty()) {
        // no fetch references means there will be no fetch requests
        // this context is only here to allow the collectors to generate docids with the right bases
        // the bases are fetched in the prepare phase therefore this context can be closed
        close();
    }
}
Also used : HashMap(java.util.HashMap) IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) Index(org.elasticsearch.index.Index) ShardId(org.elasticsearch.index.shard.ShardId) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) RelationName(io.crate.metadata.RelationName) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) HashSet(java.util.HashSet) Reference(io.crate.metadata.Reference) Routing(io.crate.metadata.Routing) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) Collection(java.util.Collection) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) SharedShardContext(io.crate.execution.jobs.SharedShardContext)

Example 20 with IntCursor

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

the class Routing method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    out.writeVInt(locations.size());
    for (Map.Entry<String, Map<String, IntIndexedContainer>> entry : locations.entrySet()) {
        out.writeString(entry.getKey());
        Map<String, IntIndexedContainer> shardsByIndex = entry.getValue();
        if (shardsByIndex == null) {
            out.writeVInt(0);
        } else {
            out.writeVInt(shardsByIndex.size());
            for (Map.Entry<String, IntIndexedContainer> innerEntry : shardsByIndex.entrySet()) {
                out.writeString(innerEntry.getKey());
                IntIndexedContainer shardIds = innerEntry.getValue();
                if (shardIds == null || shardIds.size() == 0) {
                    out.writeVInt(0);
                } else {
                    out.writeVInt(shardIds.size());
                    for (IntCursor shardId : shardIds) {
                        out.writeVInt(shardId.value);
                    }
                }
            }
        }
    }
}
Also used : IntCursor(com.carrotsearch.hppc.cursors.IntCursor) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

IntCursor (com.carrotsearch.hppc.cursors.IntCursor)38 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