use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class DocTableInfo method getRouting.
@Override
public Routing getRouting(final WhereClause whereClause, @Nullable final String preference) {
Routing routing = getRouting(clusterService.state(), whereClause, preference, new ArrayList<ShardId>(0));
if (routing != null)
return routing;
ClusterStateObserver observer = new ClusterStateObserver(clusterService, routingFetchTimeout, logger);
final SettableFuture<Routing> routingSettableFuture = SettableFuture.create();
observer.waitForNextChange(new FetchRoutingListener(routingSettableFuture, whereClause, preference), new ClusterStateObserver.ChangePredicate() {
@Override
public boolean apply(ClusterState previousState, ClusterState.ClusterStateStatus previousStatus, ClusterState newState, ClusterState.ClusterStateStatus newStatus) {
return validate(newState);
}
@Override
public boolean apply(ClusterChangedEvent changedEvent) {
return validate(changedEvent.state());
}
private boolean validate(ClusterState state) {
final Map<String, Map<String, List<Integer>>> locations = new TreeMap<>();
GroupShardsIterator shardIterators;
try {
shardIterators = getShardIterators(whereClause, preference, state);
} catch (IndexNotFoundException e) {
return true;
}
final List<ShardId> missingShards = new ArrayList<>(0);
fillLocationsFromShardIterators(locations, shardIterators, missingShards);
return missingShards.isEmpty();
}
});
try {
return routingSettableFuture.get();
} catch (ExecutionException e) {
throw Throwables.propagate(e.getCause());
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class InternalBlobTableInfoFactory method resolveIndexMetaData.
private IndexMetaData resolveIndexMetaData(String tableName, ClusterState state) {
String index = BlobIndex.fullIndexName(tableName);
String[] concreteIndices;
try {
concreteIndices = indexNameExpressionResolver.concreteIndices(state, IndicesOptions.strictExpandOpen(), index);
} catch (IndexNotFoundException ex) {
throw new TableUnknownException(index, ex);
}
return state.metaData().index(concreteIndices[0]);
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class DropTableTask method deleteESIndex.
private void deleteESIndex(String indexOrAlias, final BatchConsumer consumer) {
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indexOrAlias);
if (tableInfo.isPartitioned()) {
deleteIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen());
}
deleteIndexAction.execute(deleteIndexRequest, new ActionListener<DeleteIndexResponse>() {
@Override
public void onResponse(DeleteIndexResponse response) {
if (!response.isAcknowledged()) {
warnNotAcknowledged();
}
consumer.accept(RowsBatchIterator.newInstance(ROW_ONE), null);
}
@Override
public void onFailure(Throwable e) {
if (tableInfo.isPartitioned()) {
logger.warn("Could not (fully) delete all partitions of {}. " + "Some orphaned partitions might still exist, " + "but are not accessible.", e, tableInfo.ident().fqn());
}
if (ifExists && e instanceof IndexNotFoundException) {
consumer.accept(RowsBatchIterator.newInstance(ROW_ZERO), null);
} else {
consumer.accept(null, e);
}
}
});
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class UpsertByIdTask method executeUpsertRequest.
private CompletableFuture<Long> executeUpsertRequest(final UpsertById.Item item) {
ShardId shardId;
try {
shardId = clusterService.operationRouting().indexShards(clusterService.state(), item.index(), Constants.DEFAULT_MAPPING_TYPE, item.id(), item.routing()).shardId();
} catch (IndexNotFoundException e) {
if (PartitionName.isPartition(item.index())) {
return CompletableFuture.completedFuture(0L);
} else {
return CompletableFutures.failedFuture(e);
}
}
ShardUpsertRequest upsertRequest = new ShardUpsertRequest.Builder(false, false, upsertById.updateColumns(), upsertById.insertColumns(), jobId(), false).newRequest(shardId, item.routing());
ShardUpsertRequest.Item requestItem = new ShardUpsertRequest.Item(item.id(), item.updateAssignments(), item.insertValues(), item.version());
upsertRequest.add(0, requestItem);
UpsertByIdContext upsertByIdContext = new UpsertByIdContext(upsertById.executionPhaseId(), upsertRequest, item, transportShardUpsertActionDelegate);
try {
createJobExecutionContext(upsertByIdContext);
jobExecutionContext.start();
} catch (Throwable throwable) {
return CompletableFutures.failedFuture(throwable);
}
return upsertByIdContext.resultFuture();
}
use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.
the class IndexShard method startRecovery.
public void startRecovery(RecoveryState recoveryState, PeerRecoveryTargetService recoveryTargetService, PeerRecoveryTargetService.RecoveryListener recoveryListener, RepositoriesService repositoriesService, BiConsumer<String, MappingMetaData> mappingUpdateConsumer, IndicesService indicesService) {
// }
assert recoveryState.getRecoverySource().equals(shardRouting.recoverySource());
switch(recoveryState.getRecoverySource().getType()) {
case EMPTY_STORE:
case EXISTING_STORE:
// mark the shard as recovering on the cluster state thread
markAsRecovering("from store", recoveryState);
threadPool.generic().execute(() -> {
try {
if (recoverFromStore()) {
recoveryListener.onRecoveryDone(recoveryState);
}
} catch (Exception e) {
recoveryListener.onRecoveryFailure(recoveryState, new RecoveryFailedException(recoveryState, null, e), true);
}
});
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:
// mark the shard as recovering on the cluster state thread
markAsRecovering("from snapshot", recoveryState);
SnapshotRecoverySource recoverySource = (SnapshotRecoverySource) recoveryState.getRecoverySource();
threadPool.generic().execute(() -> {
try {
final Repository repository = repositoriesService.repository(recoverySource.snapshot().getRepository());
if (restoreFromRepository(repository)) {
recoveryListener.onRecoveryDone(recoveryState);
}
} catch (Exception e) {
recoveryListener.onRecoveryFailure(recoveryState, new RecoveryFailedException(recoveryState, null, e), true);
}
});
break;
case LOCAL_SHARDS:
final IndexMetaData indexMetaData = indexSettings().getIndexMetaData();
final Index mergeSourceIndex = indexMetaData.getMergeSourceIndex();
final List<IndexShard> startedShards = new ArrayList<>();
final IndexService sourceIndexService = indicesService.indexService(mergeSourceIndex);
final int numShards = sourceIndexService != null ? sourceIndexService.getIndexSettings().getNumberOfShards() : -1;
if (sourceIndexService != null) {
for (IndexShard shard : sourceIndexService) {
if (shard.state() == IndexShardState.STARTED) {
startedShards.add(shard);
}
}
}
if (numShards == startedShards.size()) {
// mark the shard as recovering on the cluster state thread
markAsRecovering("from local shards", recoveryState);
threadPool.generic().execute(() -> {
try {
final Set<ShardId> shards = IndexMetaData.selectShrinkShards(shardId().id(), sourceIndexService.getMetaData(), +indexMetaData.getNumberOfShards());
if (recoverFromLocalShards(mappingUpdateConsumer, startedShards.stream().filter((s) -> shards.contains(s.shardId())).collect(Collectors.toList()))) {
recoveryListener.onRecoveryDone(recoveryState);
}
} catch (Exception e) {
recoveryListener.onRecoveryFailure(recoveryState, new RecoveryFailedException(recoveryState, null, e), true);
}
});
} else {
final RuntimeException e;
if (numShards == -1) {
e = new IndexNotFoundException(mergeSourceIndex);
} else {
e = new IllegalStateException("not all shards from index " + mergeSourceIndex + " 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