use of org.elasticsearch.index.shard.ShardNotFoundException in project crate by crate.
the class ShardCollectSource method createMultiShardScoreDocCollector.
private CrateCollector createMultiShardScoreDocCollector(RoutedCollectPhase collectPhase, BatchConsumer consumer, JobCollectContext jobCollectContext, String localNodeId) {
Map<String, Map<String, List<Integer>>> locations = collectPhase.routing().locations();
SharedShardContexts sharedShardContexts = jobCollectContext.sharedShardContexts();
Map<String, List<Integer>> indexShards = locations.get(localNodeId);
List<OrderedDocCollector> orderedDocCollectors = new ArrayList<>();
for (Map.Entry<String, List<Integer>> entry : indexShards.entrySet()) {
String indexName = entry.getKey();
for (Integer shardNum : entry.getValue()) {
ShardId shardId = new ShardId(indexName, shardNum);
SharedShardContext context = sharedShardContexts.getOrCreateContext(shardId);
try {
ShardCollectorProvider shardCollectorProvider = getCollectorProviderSafe(shardId);
orderedDocCollectors.add(shardCollectorProvider.getOrderedCollector(collectPhase, context, jobCollectContext, consumer.requiresScroll()));
} catch (ShardNotFoundException | IllegalIndexShardStateException e) {
throw e;
} catch (IndexNotFoundException e) {
if (PartitionName.isPartition(indexName)) {
break;
}
throw e;
} catch (Throwable t) {
throw new UnhandledServerException(t);
}
}
}
OrderBy orderBy = collectPhase.orderBy();
assert orderBy != null : "orderBy must not be null";
return BatchIteratorCollectorBridge.newInstance(OrderedLuceneBatchIteratorFactory.newInstance(orderedDocCollectors, collectPhase.toCollect().size(), OrderingByPosition.rowOrdering(OrderByPositionVisitor.orderByPositions(orderBy.orderBySymbols(), collectPhase.toCollect()), orderBy.reverseFlags(), orderBy.nullsFirst()), executor, consumer.requiresScroll()), consumer);
}
use of org.elasticsearch.index.shard.ShardNotFoundException in project crate by crate.
the class ShardCollectSource method getShardsCollector.
private CrateCollector getShardsCollector(RoutedCollectPhase collectPhase, RoutedCollectPhase normalizedPhase, String localNodeId, BatchConsumer consumer) {
Map<String, Map<String, List<Integer>>> locations = collectPhase.routing().locations();
List<UnassignedShard> unassignedShards = new ArrayList<>();
List<Object[]> rows = new ArrayList<>();
Map<String, List<Integer>> indexShardsMap = locations.get(localNodeId);
for (Map.Entry<String, List<Integer>> indexShards : indexShardsMap.entrySet()) {
String indexName = indexShards.getKey();
List<Integer> shards = indexShards.getValue();
IndexService indexService = indicesService.indexService(indexName);
if (indexService == null) {
for (Integer shard : shards) {
unassignedShards.add(toUnassignedShard(new ShardId(indexName, UnassignedShard.markAssigned(shard))));
}
continue;
}
for (Integer shard : shards) {
if (UnassignedShard.isUnassigned(shard)) {
unassignedShards.add(toUnassignedShard(new ShardId(indexName, UnassignedShard.markAssigned(shard))));
continue;
}
ShardId shardId = new ShardId(indexName, shard);
try {
ShardCollectorProvider shardCollectorProvider = getCollectorProviderSafe(shardId);
Object[] row = shardCollectorProvider.getRowForShard(normalizedPhase);
if (row != null) {
rows.add(row);
}
} catch (ShardNotFoundException | IllegalIndexShardStateException e) {
unassignedShards.add(toUnassignedShard(shardId));
} catch (Throwable t) {
t.printStackTrace();
throw new UnhandledServerException(t);
}
}
}
if (!unassignedShards.isEmpty()) {
// because otherwise if _node was also selected it would contain something which is wrong
for (Row row : systemCollectSource.toRowsIterableTransformation(collectPhase, false).apply(unassignedShards)) {
rows.add(row.materialize());
}
}
if (collectPhase.orderBy() != null) {
rows.sort(OrderingByPosition.arrayOrdering(collectPhase).reverse());
}
return BatchIteratorCollectorBridge.newInstance(RowsBatchIterator.newInstance(Iterables.transform(rows, Buckets.arrayToRowFunction()), collectPhase.outputTypes().size()), consumer);
}
use of org.elasticsearch.index.shard.ShardNotFoundException in project elasticsearch by elastic.
the class TransportReplicationActionTests method mockIndexService.
final IndexService mockIndexService(final IndexMetaData indexMetaData, ClusterService clusterService) {
final IndexService indexService = mock(IndexService.class);
when(indexService.getShard(anyInt())).then(invocation -> {
int shard = (Integer) invocation.getArguments()[0];
final ShardId shardId = new ShardId(indexMetaData.getIndex(), shard);
if (shard > indexMetaData.getNumberOfShards()) {
throw new ShardNotFoundException(shardId);
}
return mockIndexShard(shardId, clusterService);
});
return indexService;
}
use of org.elasticsearch.index.shard.ShardNotFoundException in project elasticsearch by elastic.
the class TransportWriteActionTests method mockIndexService.
final IndexService mockIndexService(final IndexMetaData indexMetaData, ClusterService clusterService) {
final IndexService indexService = mock(IndexService.class);
when(indexService.getShard(anyInt())).then(invocation -> {
int shard = (Integer) invocation.getArguments()[0];
final ShardId shardId = new ShardId(indexMetaData.getIndex(), shard);
if (shard > indexMetaData.getNumberOfShards()) {
throw new ShardNotFoundException(shardId);
}
return mockIndexShard(shardId, clusterService);
});
return indexService;
}
use of org.elasticsearch.index.shard.ShardNotFoundException in project crate by crate.
the class BulkRetryCoordinatorPool method coordinator.
public BulkRetryCoordinator coordinator(ShardId shardId) throws IndexNotFoundException, ShardNotFoundException {
synchronized (coordinatorsByShardId) {
BulkRetryCoordinator coordinator = coordinatorsByShardId.get(shardId);
if (coordinator == null) {
IndexRoutingTable indexRoutingTable = clusterService.state().routingTable().index(shardId.getIndex());
if (indexRoutingTable == null) {
throw new IndexNotFoundException("cannot find index " + shardId.index());
}
IndexShardRoutingTable shardRoutingTable = indexRoutingTable.shard(shardId.id());
if (shardRoutingTable == null) {
throw new ShardNotFoundException(shardId);
}
String nodeId = shardRoutingTable.primaryShard().currentNodeId();
// wow, that is a long comment!
synchronized (coordinatorsByNodeId) {
coordinator = coordinatorsByNodeId.get(nodeId);
if (coordinator == null) {
LOGGER.debug("create new coordinator for node {} and shard {}", nodeId, shardId);
coordinator = new BulkRetryCoordinator(threadPool);
coordinatorsByNodeId.put(nodeId, coordinator);
}
}
coordinatorsByShardId.put(shardId, coordinator);
}
return coordinator;
}
}
Aggregations