Search in sources :

Example 6 with UnhandledServerException

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());
}
Also used : NestableInput(io.crate.expression.NestableInput) DocTableInfo(io.crate.metadata.doc.DocTableInfo) Reference(io.crate.metadata.Reference) ResourceUnknownException(io.crate.exceptions.ResourceUnknownException) ResourceUnknownException(io.crate.exceptions.ResourceUnknownException) UnhandledServerException(io.crate.exceptions.UnhandledServerException) PartitionName(io.crate.metadata.PartitionName) ColumnIdent(io.crate.metadata.ColumnIdent) MapBackedRefResolver(io.crate.metadata.MapBackedRefResolver) UnhandledServerException(io.crate.exceptions.UnhandledServerException) RelationName(io.crate.metadata.RelationName)

Example 7 with UnhandledServerException

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;
}
Also used : LuceneQueryBuilder(io.crate.lucene.LuceneQueryBuilder) ArrayList(java.util.ArrayList) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) ShardId(org.elasticsearch.index.shard.ShardId) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) UnhandledServerException(io.crate.exceptions.UnhandledServerException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 8 with UnhandledServerException

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);
}
Also used : OrderBy(io.crate.analyze.OrderBy) ArrayList(java.util.ArrayList) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) OrderedDocCollector(io.crate.operation.collect.collectors.OrderedDocCollector) ShardId(org.elasticsearch.index.shard.ShardId) SharedShardContexts(io.crate.action.job.SharedShardContexts) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) UnhandledServerException(io.crate.exceptions.UnhandledServerException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SharedShardContext(io.crate.action.job.SharedShardContext)

Example 9 with UnhandledServerException

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);
}
Also used : IndexService(org.elasticsearch.index.IndexService) ArrayList(java.util.ArrayList) UnassignedShard(io.crate.metadata.shard.unassigned.UnassignedShard) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) ShardId(org.elasticsearch.index.shard.ShardId) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) UnhandledServerException(io.crate.exceptions.UnhandledServerException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 10 with UnhandledServerException

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());
    }
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) PartitionedColumnExpression(io.crate.operation.reference.partitioned.PartitionedColumnExpression) UnhandledServerException(io.crate.exceptions.UnhandledServerException) ResourceUnknownException(io.crate.exceptions.ResourceUnknownException)

Aggregations

UnhandledServerException (io.crate.exceptions.UnhandledServerException)13 IOException (java.io.IOException)4 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 IllegalIndexShardStateException (org.elasticsearch.index.shard.IllegalIndexShardStateException)3 ShardId (org.elasticsearch.index.shard.ShardId)3 ShardNotFoundException (org.elasticsearch.index.shard.ShardNotFoundException)3 ResourceUnknownException (io.crate.exceptions.ResourceUnknownException)2 ColumnIdent (io.crate.metadata.ColumnIdent)2 DocTableInfo (io.crate.metadata.doc.DocTableInfo)2 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)2 Settings (org.elasticsearch.common.settings.Settings)2 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)2 Test (org.junit.Test)2 SharedShardContext (io.crate.action.job.SharedShardContext)1 SharedShardContexts (io.crate.action.job.SharedShardContexts)1 OrderBy (io.crate.analyze.OrderBy)1