Search in sources :

Example 51 with IndexNotFoundException

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);
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateObserver(org.elasticsearch.cluster.ClusterStateObserver) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) UnavailableShardsException(io.crate.exceptions.UnavailableShardsException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) ColumnUnknownException(io.crate.exceptions.ColumnUnknownException) ShardId(org.elasticsearch.index.shard.ShardId) GroupShardsIterator(org.elasticsearch.cluster.routing.GroupShardsIterator) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 52 with IndexNotFoundException

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]);
}
Also used : IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) TableUnknownException(io.crate.exceptions.TableUnknownException)

Example 53 with IndexNotFoundException

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);
            }
        }
    });
}
Also used : DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Example 54 with IndexNotFoundException

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();
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Example 55 with IndexNotFoundException

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());
    }
}
Also used : IndexService(org.elasticsearch.index.IndexService) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) CheckIndex(org.apache.lucene.index.CheckIndex) Index(org.elasticsearch.index.Index) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) ThreadInterruptedException(org.apache.lucene.util.ThreadInterruptedException) RecoveryFailedException(org.elasticsearch.indices.recovery.RecoveryFailedException) EngineException(org.elasticsearch.index.engine.EngineException) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) NoSuchFileException(java.nio.file.NoSuchFileException) TimeoutException(java.util.concurrent.TimeoutException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) RefreshFailedEngineException(org.elasticsearch.index.engine.RefreshFailedEngineException) FileNotFoundException(java.io.FileNotFoundException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Repository(org.elasticsearch.repositories.Repository) SnapshotRecoverySource(org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource) RecoveryFailedException(org.elasticsearch.indices.recovery.RecoveryFailedException) 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