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