use of io.crate.exceptions.UnhandledServerException in project crate by crate.
the class ShardReferenceResolver method createPartitionColumnResolver.
private static ReferenceResolver<NestableInput<?>> createPartitionColumnResolver(Index index, Schemas schemas) {
PartitionName partitionName;
try {
partitionName = PartitionName.fromIndexOrTemplate(index.getName());
} catch (IllegalArgumentException e) {
throw new UnhandledServerException(String.format(Locale.ENGLISH, "Unable to load PARTITIONED BY columns from partition %s", index.getName()), e);
}
RelationName relationName = partitionName.relationName();
MapBuilder<ColumnIdent, NestableInput> builder = MapBuilder.newMapBuilder();
try {
DocTableInfo info = schemas.getTableInfo(relationName);
assert info.isPartitioned() : "table must be partitioned";
int i = 0;
int numPartitionedColumns = info.partitionedByColumns().size();
List<String> partitionValue = partitionName.values();
assert partitionValue.size() == numPartitionedColumns : "invalid number of partitioned columns";
for (Reference partitionedInfo : info.partitionedByColumns()) {
builder.put(partitionedInfo.column(), constant(partitionedInfo.valueType().implicitCast(partitionValue.get(i))));
i++;
}
} catch (Exception e) {
if (e instanceof ResourceUnknownException) {
LOGGER.error("Orphaned partition '{}' with missing table '{}' found", index, relationName.fqn());
} else {
throw e;
}
}
return new MapBackedRefResolver(builder.immutableMap());
}
use of io.crate.exceptions.UnhandledServerException in project crate by crate.
the class ShardCollectSource method getDocCollectors.
private Collection<CrateCollector.Builder> getDocCollectors(JobCollectContext jobCollectContext, RoutedCollectPhase collectPhase, boolean requiresScroll, Map<String, List<Integer>> indexShards) {
List<CrateCollector.Builder> crateCollectors = new ArrayList<>();
for (Map.Entry<String, List<Integer>> entry : indexShards.entrySet()) {
String indexName = entry.getKey();
try {
indicesService.indexServiceSafe(indexName);
} catch (IndexNotFoundException e) {
if (PartitionName.isPartition(indexName)) {
continue;
}
throw e;
}
for (Integer shardNum : entry.getValue()) {
ShardId shardId = new ShardId(indexName, shardNum);
try {
ShardCollectorProvider shardCollectorProvider = getCollectorProviderSafe(shardId);
CrateCollector.Builder collector = shardCollectorProvider.getCollectorBuilder(collectPhase, requiresScroll, jobCollectContext);
crateCollectors.add(collector);
} catch (ShardNotFoundException | IllegalIndexShardStateException e) {
// and the reader required in the fetchPhase would be missing.
if (Symbols.containsColumn(collectPhase.toCollect(), DocSysColumns.FETCHID)) {
throw e;
}
crateCollectors.add(remoteCollectorFactory.createCollector(shardId.getIndex(), shardId.id(), collectPhase, jobCollectContext.queryPhaseRamAccountingContext()));
} catch (InterruptedException e) {
throw Throwables.propagate(e);
} catch (Throwable t) {
throw new UnhandledServerException(t);
}
}
}
return crateCollectors;
}
use of io.crate.exceptions.UnhandledServerException 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 io.crate.exceptions.UnhandledServerException 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 io.crate.exceptions.UnhandledServerException in project crate by crate.
the class ShardReferenceResolver method addPartitions.
private void addPartitions(Index index, Schemas schemas, ImmutableMap.Builder<ReferenceIdent, ReferenceImplementation> builder) {
PartitionName partitionName;
try {
partitionName = PartitionName.fromIndexOrTemplate(index.name());
} catch (IllegalArgumentException e) {
throw new UnhandledServerException(String.format(Locale.ENGLISH, "Unable to load PARTITIONED BY columns from partition %s", index.name()), e);
}
TableIdent tableIdent = partitionName.tableIdent();
try {
DocTableInfo info = (DocTableInfo) schemas.getTableInfo(tableIdent);
if (!schemas.isOrphanedAlias(info)) {
assert info.isPartitioned() : "table must be partitioned";
int i = 0;
int numPartitionedColumns = info.partitionedByColumns().size();
assert partitionName.values().size() == numPartitionedColumns : "invalid number of partitioned columns";
for (Reference partitionedInfo : info.partitionedByColumns()) {
builder.put(partitionedInfo.ident(), new PartitionedColumnExpression(partitionedInfo, partitionName.values().get(i)));
i++;
}
} else {
LOGGER.error("Orphaned partition '{}' with missing table '{}' found", index, tableIdent.fqn());
}
} catch (ResourceUnknownException e) {
LOGGER.error("Orphaned partition '{}' with missing table '{}' found", index, tableIdent.fqn());
}
}
Aggregations