Search in sources :

Example 31 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.

the class InternalCountOperation method count.

@Override
public CompletableFuture<Long> count(TransactionContext txnCtx, Map<String, IntIndexedContainer> indexShardMap, Symbol filter) {
    List<CompletableFuture<Supplier<Long>>> futureSuppliers = new ArrayList<>();
    Metadata metadata = clusterService.state().getMetadata();
    for (Map.Entry<String, IntIndexedContainer> entry : indexShardMap.entrySet()) {
        String indexName = entry.getKey();
        IndexMetadata indexMetadata = metadata.index(indexName);
        if (indexMetadata == null) {
            if (IndexParts.isPartitioned(indexName)) {
                continue;
            }
            throw new IndexNotFoundException(indexName);
        }
        final Index index = indexMetadata.getIndex();
        for (IntCursor shardCursor : entry.getValue()) {
            int shardValue = shardCursor.value;
            futureSuppliers.add(prepareGetCount(txnCtx, index, shardValue, filter));
        }
    }
    MergePartialCountFunction mergeFunction = new MergePartialCountFunction();
    return CompletableFutures.allAsList(futureSuppliers).thenCompose(suppliers -> ThreadPools.runWithAvailableThreads(executor, ThreadPools.numIdleThreads(executor, numProcessors), suppliers)).thenApply(mergeFunction);
}
Also used : IndexParts(io.crate.metadata.IndexParts) TransactionContext(io.crate.metadata.TransactionContext) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) RelationName(io.crate.metadata.RelationName) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) ClusterService(org.elasticsearch.cluster.service.ClusterService) LuceneQueryBuilder(io.crate.lucene.LuceneQueryBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) Index(org.elasticsearch.index.Index) Operation(io.crate.metadata.table.Operation) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Inject(org.elasticsearch.common.inject.Inject) ArrayList(java.util.ArrayList) Metadata(org.elasticsearch.cluster.metadata.Metadata) Settings(org.elasticsearch.common.settings.Settings) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) IndicesService(org.elasticsearch.indices.IndicesService) DocTableInfo(io.crate.metadata.doc.DocTableInfo) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) JobKilledException(io.crate.exceptions.JobKilledException) EsExecutors(org.elasticsearch.common.util.concurrent.EsExecutors) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IOException(java.io.IOException) CompletableFutures(io.crate.concurrent.CompletableFutures) Engine(org.elasticsearch.index.engine.Engine) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Symbol(io.crate.expression.symbol.Symbol) Singleton(org.elasticsearch.common.inject.Singleton) Schemas(io.crate.metadata.Schemas) ThreadPools(io.crate.execution.support.ThreadPools) ArrayList(java.util.ArrayList) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) Index(org.elasticsearch.index.Index) CompletableFuture(java.util.concurrent.CompletableFuture) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Map(java.util.Map)

Example 32 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.

the class InternalCountOperation method prepareGetCount.

public CompletableFuture<Supplier<Long>> prepareGetCount(TransactionContext txnCtx, Index index, int shardId, Symbol filter) {
    IndexService indexService;
    try {
        indexService = indicesService.indexServiceSafe(index);
    } catch (IndexNotFoundException e) {
        if (IndexParts.isPartitioned(index.getName())) {
            return CompletableFuture.completedFuture(() -> 0L);
        } else {
            return CompletableFuture.failedFuture(e);
        }
    }
    IndexShard indexShard = indexService.getShard(shardId);
    CompletableFuture<Supplier<Long>> futureCount = new CompletableFuture<>();
    indexShard.awaitShardSearchActive(b -> {
        try {
            futureCount.complete(() -> syncCount(indexService, indexShard, txnCtx, filter));
        } catch (Throwable t) {
            futureCount.completeExceptionally(t);
        }
    });
    return futureCount;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Supplier(java.util.function.Supplier)

Example 33 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.

the class PKLookupOperation method lookup.

public BatchIterator<Row> lookup(UUID jobId, TransactionContext txnCtx, Supplier<RamAccounting> ramAccountingSupplier, Supplier<MemoryManager> memoryManagerSupplier, boolean ignoreMissing, Map<ShardId, List<PKAndVersion>> idsByShard, Collection<? extends Projection> projections, boolean requiresScroll, Function<Doc, Row> resultToRow) {
    ArrayList<BatchIterator<Row>> iterators = new ArrayList<>(idsByShard.size());
    for (Map.Entry<ShardId, List<PKAndVersion>> idsByShardEntry : idsByShard.entrySet()) {
        ShardId shardId = idsByShardEntry.getKey();
        IndexService indexService = indicesService.indexService(shardId.getIndex());
        if (indexService == null) {
            if (ignoreMissing) {
                continue;
            }
            throw new IndexNotFoundException(shardId.getIndex());
        }
        IndexShard shard = indexService.getShardOrNull(shardId.id());
        if (shard == null) {
            if (ignoreMissing) {
                continue;
            }
            throw new ShardNotFoundException(shardId);
        }
        Stream<Row> rowStream = idsByShardEntry.getValue().stream().map(pkAndVersion -> lookupDoc(shard, pkAndVersion.id(), pkAndVersion.version(), VersionType.EXTERNAL, pkAndVersion.seqNo(), pkAndVersion.primaryTerm())).filter(Objects::nonNull).map(resultToRow);
        if (projections.isEmpty()) {
            final Iterable<Row> rowIterable = requiresScroll ? rowStream.map(row -> new RowN(row.materialize())).collect(Collectors.toList()) : rowStream::iterator;
            iterators.add(InMemoryBatchIterator.of(rowIterable, SentinelRow.SENTINEL, true));
        } else {
            ProjectorFactory projectorFactory;
            try {
                projectorFactory = shardCollectSource.getProjectorFactory(shardId);
            } catch (ShardNotFoundException e) {
                if (ignoreMissing) {
                    continue;
                }
                throw e;
            }
            Projectors projectors = new Projectors(projections, jobId, txnCtx, ramAccountingSupplier.get(), memoryManagerSupplier.get(), projectorFactory);
            final Iterable<Row> rowIterable = requiresScroll && !projectors.providesIndependentScroll() ? rowStream.map(row -> new RowN(row.materialize())).collect(Collectors.toList()) : rowStream::iterator;
            iterators.add(projectors.wrap(InMemoryBatchIterator.of(rowIterable, SentinelRow.SENTINEL, true)));
        }
    }
    // noinspection unchecked
    return CompositeBatchIterator.seqComposite(iterators.toArray(new BatchIterator[0]));
}
Also used : IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) ArrayList(java.util.ArrayList) BatchIterator(io.crate.data.BatchIterator) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) CompositeBatchIterator(io.crate.data.CompositeBatchIterator) ShardId(org.elasticsearch.index.shard.ShardId) Projectors(io.crate.execution.engine.pipeline.Projectors) RowN(io.crate.data.RowN) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) ProjectorFactory(io.crate.execution.engine.pipeline.ProjectorFactory) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) Row(io.crate.data.Row) SentinelRow(io.crate.data.SentinelRow) Map(java.util.Map)

Example 34 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.

the class HttpBlobHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    if (cause instanceof ClosedChannelException) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("channel closed: {}", cause.toString());
        }
        return;
    } else if (cause instanceof IOException) {
        String message = cause.getMessage();
        if (message != null && message.contains("Connection reset by peer")) {
            LOGGER.debug(message);
        } else if (cause instanceof NotSslRecordException) {
            // Raised when clients try to send unencrypted data over an encrypted channel
            // This can happen when old instances of the Admin UI are running because the
            // ports of HTTP/HTTPS are the same.
            LOGGER.debug("Received unencrypted message from '{}'", ctx.channel().remoteAddress());
        } else {
            LOGGER.warn(message, cause);
        }
        return;
    }
    HttpResponseStatus status;
    String body = null;
    if (cause instanceof DigestMismatchException || cause instanceof BlobsDisabledException || cause instanceof IllegalArgumentException) {
        status = HttpResponseStatus.BAD_REQUEST;
        body = String.format(Locale.ENGLISH, "Invalid request sent: %s", cause.getMessage());
    } else if (cause instanceof DigestNotFoundException || cause instanceof IndexNotFoundException) {
        status = HttpResponseStatus.NOT_FOUND;
    } else if (cause instanceof EsRejectedExecutionException) {
        status = HttpResponseStatus.TOO_MANY_REQUESTS;
        body = String.format(Locale.ENGLISH, "Rejected execution: %s", cause.getMessage());
    } else {
        status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
        body = String.format(Locale.ENGLISH, "Unhandled exception: %s", cause);
    }
    if (body != null) {
        LOGGER.debug(body);
    }
    simpleResponse(null, status, body);
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) NotSslRecordException(io.netty.handler.ssl.NotSslRecordException) DigestNotFoundException(io.crate.blob.exceptions.DigestNotFoundException) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) DigestMismatchException(io.crate.blob.exceptions.DigestMismatchException) IOException(java.io.IOException) BlobsDisabledException(io.crate.blob.v2.BlobsDisabledException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)

Example 35 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.

the class ShardRequestExecutor method addRequests.

private int addRequests(int location, Row parameters, Map<ShardId, Req> requests, SubQueryResults subQueryResults) {
    for (DocKeys.DocKey docKey : docKeys) {
        String id = docKey.getId(txnCtx, nodeCtx, parameters, subQueryResults);
        if (id == null) {
            continue;
        }
        String routing = docKey.getRouting(txnCtx, nodeCtx, parameters, subQueryResults);
        List<String> partitionValues = docKey.getPartitionValues(txnCtx, nodeCtx, parameters, subQueryResults);
        final String indexName;
        if (partitionValues == null) {
            indexName = table.ident().indexNameOrAlias();
        } else {
            indexName = IndexParts.toIndexName(table.ident(), PartitionName.encodeIdent(partitionValues));
        }
        final ShardId shardId;
        try {
            shardId = getShardId(clusterService, indexName, id, routing);
        } catch (IndexNotFoundException e) {
            if (table.isPartitioned()) {
                continue;
            }
            throw e;
        }
        Req request = requests.get(shardId);
        if (request == null) {
            request = grouper.newRequest(shardId);
            requests.put(shardId, request);
        }
        Long version = docKey.version(txnCtx, nodeCtx, parameters, subQueryResults).orElse(null);
        Long seqNo = docKey.sequenceNo(txnCtx, nodeCtx, parameters, subQueryResults).orElse(null);
        Long primaryTerm = docKey.primaryTerm(txnCtx, nodeCtx, parameters, subQueryResults).orElse(null);
        grouper.addItem(request, location, id, version, seqNo, primaryTerm);
        location++;
    }
    return location;
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) DocKeys(io.crate.analyze.where.DocKeys) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Aggregations

IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)92 ClusterState (org.elasticsearch.cluster.ClusterState)22 ShardNotFoundException (org.elasticsearch.index.shard.ShardNotFoundException)21 ShardId (org.elasticsearch.index.shard.ShardId)19 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)16 Index (org.elasticsearch.index.Index)16 Map (java.util.Map)15 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)13 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)12 List (java.util.List)11 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)11 ClusterName (org.elasticsearch.cluster.ClusterName)9 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)9 Settings (org.elasticsearch.common.settings.Settings)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 HashMap (java.util.HashMap)8 Nullable (javax.annotation.Nullable)8 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)8 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)8