use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class ShardCollectSource method getIterators.
private List<CompletableFuture<BatchIterator<Row>>> getIterators(CollectTask collectTask, RoutedCollectPhase collectPhase, boolean requiresScroll, Map<String, IntIndexedContainer> indexShards) {
Metadata metadata = clusterService.state().metadata();
List<CompletableFuture<BatchIterator<Row>>> iterators = new ArrayList<>();
for (Map.Entry<String, IntIndexedContainer> entry : indexShards.entrySet()) {
String indexName = entry.getKey();
IndexMetadata indexMD = metadata.index(indexName);
if (indexMD == null) {
if (IndexParts.isPartitioned(indexName)) {
continue;
}
throw new IndexNotFoundException(indexName);
}
Index index = indexMD.getIndex();
try {
indicesService.indexServiceSafe(index);
} catch (IndexNotFoundException e) {
if (IndexParts.isPartitioned(indexName)) {
continue;
}
throw e;
}
for (IntCursor shardCursor : entry.getValue()) {
ShardId shardId = new ShardId(index, shardCursor.value);
try {
ShardCollectorProvider shardCollectorProvider = getCollectorProviderSafe(shardId);
CompletableFuture<BatchIterator<Row>> iterator = shardCollectorProvider.getFutureIterator(collectPhase, requiresScroll, collectTask);
iterators.add(iterator);
} catch (ShardNotFoundException | IllegalIndexShardStateException e) {
// and the reader required in the fetchPhase would be missing.
if (Symbols.containsColumn(collectPhase.toCollect(), DocSysColumns.FETCHID)) {
throw e;
}
iterators.add(remoteCollectorFactory.createCollector(shardId, collectPhase, collectTask, shardCollectorProviderFactory));
} catch (IndexNotFoundException e) {
// Prevent wrapping this to not break retry-detection
throw e;
} catch (Throwable t) {
Exceptions.rethrowRuntimeException(t);
}
}
}
return iterators;
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class DocTableInfoBuilder method docIndexMetadata.
private DocIndexMetadata docIndexMetadata() {
DocIndexMetadata docIndexMetadata;
String templateName = PartitionName.templateName(ident.schema(), ident.name());
if (metadata.getTemplates().containsKey(templateName)) {
docIndexMetadata = buildDocIndexMetadataFromTemplate(ident.indexNameOrAlias(), templateName);
// We need all concrete indices, regardless of their state, for operations such as reopening.
concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), ident.indexNameOrAlias());
// We need all concrete open indices, as closed indices must not appear in the routing.
concreteOpenIndices = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.fromOptions(true, true, true, false, IndicesOptions.strictExpandOpenAndForbidClosed()), ident.indexNameOrAlias());
} else {
try {
concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.strictExpandOpen(), ident.indexNameOrAlias());
concreteOpenIndices = concreteIndices;
if (concreteIndices.length == 0) {
// no matching index found
throw new RelationUnknown(ident);
}
docIndexMetadata = buildDocIndexMetadata(concreteIndices[0]);
} catch (IndexNotFoundException ex) {
throw new RelationUnknown(ident.fqn(), ex);
}
}
return docIndexMetadata;
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class RetryOnFailureResultReceiverTest method testRetryIsInvokedOnIndexNotFoundException.
@Test
public void testRetryIsInvokedOnIndexNotFoundException() throws Exception {
AtomicInteger numRetries = new AtomicInteger(0);
BaseResultReceiver resultReceiver = new BaseResultReceiver();
ClusterState initialState = clusterService.state();
RetryOnFailureResultReceiver retryOnFailureResultReceiver = new RetryOnFailureResultReceiver(clusterService, initialState, indexName -> true, resultReceiver, UUID.randomUUID(), (newJobId, receiver) -> numRetries.incrementAndGet());
// Must have a different cluster state then the initial state to trigger a retry
clusterService.submitStateUpdateTask("dummy", new DummyUpdate());
assertBusy(() -> assertThat(initialState, Matchers.not(sameInstance(clusterService.state()))));
retryOnFailureResultReceiver.fail(new IndexNotFoundException("t1"));
assertThat(numRetries.get(), is(1));
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class DropTablePlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
TableInfo table = dropTable.table();
DropTableRequest request;
if (table == null) {
if (dropTable.maybeCorrupt()) {
// setting isPartitioned=true should be safe.
// It will delete a template if it exists, and if there is no template it shouldn't do any harm
request = new DropTableRequest(dropTable.tableName(), true);
} else {
// no-op, table is already gone
assert dropTable.dropIfExists() : "If table is null, IF EXISTS flag must have been present";
consumer.accept(InMemoryBatchIterator.of(ROW_ZERO, SENTINEL), null);
return;
}
} else {
boolean isPartitioned = table instanceof DocTableInfo && ((DocTableInfo) table).isPartitioned();
request = new DropTableRequest(table.ident(), isPartitioned);
}
dependencies.transportDropTableAction().execute(request, new ActionListener<>() {
@Override
public void onResponse(AcknowledgedResponse response) {
if (!response.isAcknowledged() && LOGGER.isWarnEnabled()) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("Dropping table {} was not acknowledged. This could lead to inconsistent state.", dropTable.tableName());
}
}
consumer.accept(InMemoryBatchIterator.of(ROW_ONE, SENTINEL), null);
}
@Override
public void onFailure(Exception e) {
if (dropTable.dropIfExists() && e instanceof IndexNotFoundException) {
consumer.accept(InMemoryBatchIterator.of(ROW_ZERO, SENTINEL), null);
} else {
consumer.accept(null, e);
}
}
});
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class IndexShard method startRecovery.
public void startRecovery(RecoveryState recoveryState, PeerRecoveryTargetService recoveryTargetService, PeerRecoveryTargetService.RecoveryListener recoveryListener, RepositoriesService repositoriesService, Consumer<MappingMetadata> mappingUpdateConsumer, IndicesService indicesService) {
// }
assert recoveryState.getRecoverySource().equals(shardRouting.recoverySource());
switch(recoveryState.getRecoverySource().getType()) {
case EMPTY_STORE:
case EXISTING_STORE:
executeRecovery("from store", recoveryState, recoveryListener, this::recoverFromStore);
break;
case PEER:
try {
markAsRecovering("from " + recoveryState.getSourceNode(), recoveryState);
recoveryTargetService.startRecovery(this, recoveryState.getSourceNode(), recoveryListener);
} catch (Exception e) {
failShard("corrupted preexisting index", e);
recoveryListener.onRecoveryFailure(recoveryState, new RecoveryFailedException(recoveryState, null, e), true);
}
break;
case SNAPSHOT:
final String repo = ((SnapshotRecoverySource) recoveryState.getRecoverySource()).snapshot().getRepository();
executeRecovery("from snapshot", recoveryState, recoveryListener, l -> restoreFromRepository(repositoriesService.repository(repo), l));
break;
case LOCAL_SHARDS:
final IndexMetadata indexMetadata = indexSettings().getIndexMetadata();
final Index resizeSourceIndex = indexMetadata.getResizeSourceIndex();
final List<IndexShard> startedShards = new ArrayList<>();
final IndexService sourceIndexService = indicesService.indexService(resizeSourceIndex);
final Set<ShardId> requiredShards;
final int numShards;
if (sourceIndexService != null) {
requiredShards = IndexMetadata.selectRecoverFromShards(shardId().id(), sourceIndexService.getMetadata(), indexMetadata.getNumberOfShards());
for (IndexShard shard : sourceIndexService) {
if (shard.state() == IndexShardState.STARTED && requiredShards.contains(shard.shardId())) {
startedShards.add(shard);
}
}
numShards = requiredShards.size();
} else {
numShards = -1;
requiredShards = Collections.emptySet();
}
if (numShards == startedShards.size()) {
assert requiredShards.isEmpty() == false;
executeRecovery("from local shards", recoveryState, recoveryListener, l -> recoverFromLocalShards(mappingUpdateConsumer, startedShards.stream().filter((s) -> requiredShards.contains(s.shardId())).collect(Collectors.toList()), l));
} else {
final RuntimeException e;
if (numShards == -1) {
e = new IndexNotFoundException(resizeSourceIndex);
} else {
e = new IllegalStateException("not all required shards of index " + resizeSourceIndex + " are started yet, expected " + numShards + " found " + startedShards.size() + " can't recover shard " + shardId());
}
throw e;
}
break;
default:
throw new IllegalArgumentException("Unknown recovery source " + recoveryState.getRecoverySource());
}
}
Aggregations