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);
}
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;
}
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());
}
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));
}
}
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));
}
Aggregations