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