Search in sources :

Example 16 with ShardNotFoundException

use of org.elasticsearch.index.shard.ShardNotFoundException in project crate by crate.

the class SyncedFlushService method getShardRoutingTable.

final IndexShardRoutingTable getShardRoutingTable(ShardId shardId, ClusterState state) {
    final IndexRoutingTable indexRoutingTable = state.routingTable().index(shardId.getIndexName());
    if (indexRoutingTable == null) {
        IndexMetadata index = state.getMetadata().index(shardId.getIndex());
        if (index != null && index.getState() == IndexMetadata.State.CLOSE) {
            throw new IndexClosedException(shardId.getIndex());
        }
        throw new IndexNotFoundException(shardId.getIndexName());
    }
    final IndexShardRoutingTable shardRoutingTable = indexRoutingTable.shard(shardId.id());
    if (shardRoutingTable == null) {
        throw new ShardNotFoundException(shardId);
    }
    return shardRoutingTable;
}
Also used : IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) IndexClosedException(org.elasticsearch.indices.IndexClosedException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata)

Example 17 with ShardNotFoundException

use of org.elasticsearch.index.shard.ShardNotFoundException in project crate by crate.

the class RandomObjects method randomShardInfoFailure.

/**
 * Returns a tuple that contains a randomized {@link Failure} value (left side) and its corresponding
 * value (right side) after it has been printed out as a {@link ToXContent} and parsed back using a parsing
 * method like {@link ShardInfo.Failure#fromXContent(XContentParser)}.
 *
 * @param random Random generator
 */
private static Tuple<Failure, Failure> randomShardInfoFailure(Random random) {
    String index = randomAsciiLettersOfLength(random, 5);
    String indexUuid = randomAsciiLettersOfLength(random, 5);
    int shardId = randomIntBetween(random, 1, 10);
    String nodeId = randomAsciiLettersOfLength(random, 5);
    RestStatus status = randomFrom(random, RestStatus.INTERNAL_SERVER_ERROR, RestStatus.FORBIDDEN, RestStatus.NOT_FOUND);
    boolean primary = random.nextBoolean();
    ShardId shard = new ShardId(index, indexUuid, shardId);
    Exception actualException;
    ElasticsearchException expectedException;
    int type = randomIntBetween(random, 0, 3);
    switch(type) {
        case 0:
            actualException = new ClusterBlockException(singleton(DiscoverySettings.NO_MASTER_BLOCK_WRITES));
            expectedException = new ElasticsearchException("Elasticsearch exception [type=cluster_block_exception, " + "reason=blocked by: [SERVICE_UNAVAILABLE/2/no master];]");
            break;
        case 1:
            actualException = new ShardNotFoundException(shard);
            expectedException = new ElasticsearchException("Elasticsearch exception [type=shard_not_found_exception, " + "reason=no such shard]");
            expectedException.setShard(shard);
            break;
        case 2:
            actualException = new IllegalArgumentException("Closed resource", new RuntimeException("Resource"));
            expectedException = new ElasticsearchException("Elasticsearch exception [type=illegal_argument_exception, " + "reason=Closed resource]", new ElasticsearchException("Elasticsearch exception [type=runtime_exception, reason=Resource]"));
            break;
        case 3:
            actualException = new IndexShardRecoveringException(shard);
            expectedException = new ElasticsearchException("Elasticsearch exception [type=index_shard_recovering_exception, " + "reason=CurrentState[RECOVERING] Already recovering]");
            expectedException.setShard(shard);
            break;
        default:
            throw new UnsupportedOperationException("No randomized exceptions generated for type [" + type + "]");
    }
    Failure actual = new Failure(shard, nodeId, actualException, status, primary);
    Failure expected = new Failure(new ShardId(index, INDEX_UUID_NA_VALUE, shardId), nodeId, expectedException, status, primary);
    return Tuple.tuple(actual, expected);
}
Also used : IndexShardRecoveringException(org.elasticsearch.index.shard.IndexShardRecoveringException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexShardRecoveringException(org.elasticsearch.index.shard.IndexShardRecoveringException) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) IOException(java.io.IOException) ShardId(org.elasticsearch.index.shard.ShardId) RestStatus(org.elasticsearch.rest.RestStatus) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) Failure(org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo.Failure)

Example 18 with ShardNotFoundException

use of org.elasticsearch.index.shard.ShardNotFoundException in project elasticsearch by elastic.

the class RoutingTable method shardRoutingTable.

/**
     * All shards for the provided index and shard id
     * @return All the shard routing entries for the given index and shard id
     * @throws IndexNotFoundException if provided index does not exist
     * @throws ShardNotFoundException if provided shard id is unknown
     */
public IndexShardRoutingTable shardRoutingTable(String index, int shardId) {
    IndexRoutingTable indexRouting = index(index);
    if (indexRouting == null) {
        throw new IndexNotFoundException(index);
    }
    IndexShardRoutingTable shard = indexRouting.shard(shardId);
    if (shard == null) {
        throw new ShardNotFoundException(new ShardId(indexRouting.getIndex(), shardId));
    }
    return shard;
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Example 19 with ShardNotFoundException

use of org.elasticsearch.index.shard.ShardNotFoundException in project elasticsearch by elastic.

the class TransportReplicationAction method acquirePrimaryShardReference.

/**
     * Tries to acquire reference to {@link IndexShard} to perform a primary operation. Released after performing primary operation locally
     * and replication of the operation to all replica shards is completed / failed (see {@link ReplicationOperation}).
     */
private void acquirePrimaryShardReference(ShardId shardId, String allocationId, ActionListener<PrimaryShardReference> onReferenceAcquired) {
    IndexShard indexShard = getIndexShard(shardId);
    // the replica will take over and a replica will be assigned to the first node.
    if (indexShard.routingEntry().primary() == false) {
        throw new ReplicationOperation.RetryOnPrimaryException(indexShard.shardId(), "actual shard is not a primary " + indexShard.routingEntry());
    }
    final String actualAllocationId = indexShard.routingEntry().allocationId().getId();
    if (actualAllocationId.equals(allocationId) == false) {
        throw new ShardNotFoundException(shardId, "expected aID [{}] but found [{}]", allocationId, actualAllocationId);
    }
    ActionListener<Releasable> onAcquired = new ActionListener<Releasable>() {

        @Override
        public void onResponse(Releasable releasable) {
            onReferenceAcquired.onResponse(new PrimaryShardReference(indexShard, releasable));
        }

        @Override
        public void onFailure(Exception e) {
            onReferenceAcquired.onFailure(e);
        }
    };
    indexShard.acquirePrimaryOperationLock(onAcquired, executor);
}
Also used : ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) ActionListener(org.elasticsearch.action.ActionListener) IndexShard(org.elasticsearch.index.shard.IndexShard) Releasable(org.elasticsearch.common.lease.Releasable) ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexClosedException(org.elasticsearch.indices.IndexClosedException) NodeClosedException(org.elasticsearch.node.NodeClosedException) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) ConnectTransportException(org.elasticsearch.transport.ConnectTransportException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) NoNodeAvailableException(org.elasticsearch.client.transport.NoNodeAvailableException) TransportException(org.elasticsearch.transport.TransportException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) IOException(java.io.IOException) UnavailableShardsException(org.elasticsearch.action.UnavailableShardsException)

Example 20 with ShardNotFoundException

use of org.elasticsearch.index.shard.ShardNotFoundException in project crate by crate.

the class ShardCollectSource method getDocCollectors.

private Collection<CrateCollector.Builder> getDocCollectors(JobCollectContext jobCollectContext, RoutedCollectPhase collectPhase, boolean requiresScroll, Map<String, List<Integer>> indexShards) {
    List<CrateCollector.Builder> crateCollectors = new ArrayList<>();
    for (Map.Entry<String, List<Integer>> entry : indexShards.entrySet()) {
        String indexName = entry.getKey();
        try {
            indicesService.indexServiceSafe(indexName);
        } catch (IndexNotFoundException e) {
            if (PartitionName.isPartition(indexName)) {
                continue;
            }
            throw e;
        }
        for (Integer shardNum : entry.getValue()) {
            ShardId shardId = new ShardId(indexName, shardNum);
            try {
                ShardCollectorProvider shardCollectorProvider = getCollectorProviderSafe(shardId);
                CrateCollector.Builder collector = shardCollectorProvider.getCollectorBuilder(collectPhase, requiresScroll, jobCollectContext);
                crateCollectors.add(collector);
            } catch (ShardNotFoundException | IllegalIndexShardStateException e) {
                // and the reader required in the fetchPhase would be missing.
                if (Symbols.containsColumn(collectPhase.toCollect(), DocSysColumns.FETCHID)) {
                    throw e;
                }
                crateCollectors.add(remoteCollectorFactory.createCollector(shardId.getIndex(), shardId.id(), collectPhase, jobCollectContext.queryPhaseRamAccountingContext()));
            } catch (InterruptedException e) {
                throw Throwables.propagate(e);
            } catch (Throwable t) {
                throw new UnhandledServerException(t);
            }
        }
    }
    return crateCollectors;
}
Also used : LuceneQueryBuilder(io.crate.lucene.LuceneQueryBuilder) ArrayList(java.util.ArrayList) IllegalIndexShardStateException(org.elasticsearch.index.shard.IllegalIndexShardStateException) ShardId(org.elasticsearch.index.shard.ShardId) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) UnhandledServerException(io.crate.exceptions.UnhandledServerException) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

ShardNotFoundException (org.elasticsearch.index.shard.ShardNotFoundException)33 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)23 ShardId (org.elasticsearch.index.shard.ShardId)16 ArrayList (java.util.ArrayList)9 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)9 Map (java.util.Map)8 RoutingNode (org.elasticsearch.cluster.routing.RoutingNode)8 IllegalIndexShardStateException (org.elasticsearch.index.shard.IllegalIndexShardStateException)8 ElasticsearchException (org.elasticsearch.ElasticsearchException)7 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)7 IndexService (org.elasticsearch.index.IndexService)7 IndexShard (org.elasticsearch.index.shard.IndexShard)7 IOException (java.io.IOException)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)6 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)6 RerouteExplanation (org.elasticsearch.cluster.routing.allocation.RerouteExplanation)6 List (java.util.List)5 ClusterState (org.elasticsearch.cluster.ClusterState)5 ShardCollectorProvider (io.crate.execution.engine.collect.ShardCollectorProvider)4