Search in sources :

Example 66 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.

the class IndexNameExpressionResolverTests method testIndexOptionsNoExpandWildcards.

public void testIndexOptionsNoExpandWildcards() {
    MetaData.Builder mdBuilder = MetaData.builder().put(indexBuilder("foo").putAlias(AliasMetaData.builder("foofoobar"))).put(indexBuilder("foobar").putAlias(AliasMetaData.builder("foofoobar"))).put(indexBuilder("foofoo-closed").state(IndexMetaData.State.CLOSE)).put(indexBuilder("foofoo").putAlias(AliasMetaData.builder("barbaz")));
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
    //ignore unavailable and allow no indices
    {
        IndicesOptions noExpandLenient = IndicesOptions.fromOptions(true, true, false, false);
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandLenient);
        String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
        assertThat(results, emptyArray());
        results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
        assertEquals(1, results.length);
        assertEquals("foo", results[0]);
        results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
        assertEquals(2, results.length);
        assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
        results = indexNameExpressionResolver.concreteIndexNames(context, (String[]) null);
        assertEquals(0, results.length);
        results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
        assertEquals(0, results.length);
    }
    //ignore unavailable but don't allow no indices
    {
        IndicesOptions noExpandDisallowEmpty = IndicesOptions.fromOptions(true, false, false, false);
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandDisallowEmpty);
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "baz*");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("baz*"));
        }
        String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
        assertEquals(1, results.length);
        assertEquals("foo", results[0]);
        results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
        assertEquals(2, results.length);
        assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
    }
    //error on unavailable but allow no indices
    {
        IndicesOptions noExpandErrorUnavailable = IndicesOptions.fromOptions(false, true, false, false);
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandErrorUnavailable);
        String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*");
        assertThat(results, emptyArray());
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("baz*"));
        }
        results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
        assertEquals(2, results.length);
        assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
    }
    //error on both unavailable and no indices
    {
        IndicesOptions noExpandStrict = IndicesOptions.fromOptions(false, false, false, false);
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandStrict);
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "baz*");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("baz*"));
        }
        try {
            indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
            fail();
        } catch (IndexNotFoundException e) {
            assertThat(e.getIndex().getName(), equalTo("baz*"));
        }
        String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
        assertEquals(2, results.length);
        assertThat(results, arrayContainingInAnyOrder("foo", "foobar"));
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Matchers.containsString(org.hamcrest.Matchers.containsString) IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 67 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project elasticsearch by elastic.

the class IndexNameExpressionResolverTests method testIndexOptionsEmptyCluster.

public void testIndexOptionsEmptyCluster() {
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(MetaData.builder().build()).build();
    IndicesOptions options = IndicesOptions.strictExpandOpen();
    IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options);
    String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    assertThat(results, emptyArray());
    try {
        indexNameExpressionResolver.concreteIndexNames(context, "foo");
        fail();
    } catch (IndexNotFoundException e) {
        assertThat(e.getIndex().getName(), equalTo("foo"));
    }
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
    assertThat(results, emptyArray());
    try {
        indexNameExpressionResolver.concreteIndexNames(context, "foo*", "bar");
        fail();
    } catch (IndexNotFoundException e) {
        assertThat(e.getIndex().getName(), equalTo("bar"));
    }
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen());
    results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    assertThat(results, emptyArray());
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo");
    assertThat(results, emptyArray());
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo*");
    assertThat(results, emptyArray());
    results = indexNameExpressionResolver.concreteIndexNames(context, "foo*", "bar");
    assertThat(results, emptyArray());
    context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, false, true, false));
    try {
        indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY);
    } catch (IndexNotFoundException e) {
        assertThat(e.getResourceId().toString(), equalTo("[_all]"));
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Matchers.containsString(org.hamcrest.Matchers.containsString) IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

Example 68 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.

the class HttpBlobHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    Throwable ex = e.getCause();
    if (ex instanceof ClosedChannelException) {
        LOGGER.trace("channel closed: {}", ex.toString());
        return;
    } else if (ex instanceof IOException) {
        String message = ex.getMessage();
        if (message != null && message.contains("Connection reset by peer")) {
            LOGGER.debug(message);
        } else {
            LOGGER.warn(message, e);
        }
        return;
    }
    HttpResponseStatus status;
    String body = null;
    if (ex instanceof DigestMismatchException || ex instanceof BlobsDisabledException || ex instanceof IllegalArgumentException) {
        status = HttpResponseStatus.BAD_REQUEST;
        body = String.format(Locale.ENGLISH, "Invalid request sent: %s", ex.getMessage());
    } else if (ex instanceof DigestNotFoundException || ex instanceof IndexNotFoundException) {
        status = HttpResponseStatus.NOT_FOUND;
    } else if (ex instanceof EsRejectedExecutionException) {
        status = TOO_MANY_REQUESTS;
        body = String.format(Locale.ENGLISH, "Rejected execution: %s", ex.getMessage());
    } else {
        status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
        body = String.format(Locale.ENGLISH, "Unhandled exception: %s", ex);
    }
    if (body != null) {
        LOGGER.debug(body);
    }
    simpleResponse(status, body);
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) DigestNotFoundException(io.crate.blob.exceptions.DigestNotFoundException) HttpResponseStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) DigestMismatchException(io.crate.blob.exceptions.DigestMismatchException) IOException(java.io.IOException) BlobsDisabledException(io.crate.blob.v2.BlobsDisabledException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)

Example 69 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.

the class FetchContext method innerPrepare.

@Override
public void innerPrepare() {
    HashMap<String, TableIdent> index2TableIdent = new HashMap<>();
    for (Map.Entry<TableIdent, Collection<String>> entry : phase.tableIndices().asMap().entrySet()) {
        for (String indexName : entry.getValue()) {
            index2TableIdent.put(indexName, entry.getKey());
        }
    }
    Set<TableIdent> tablesWithFetchRefs = new HashSet<>();
    for (Reference reference : phase.fetchRefs()) {
        tablesWithFetchRefs.add(reference.ident().tableIdent());
    }
    for (Routing routing : routingIterable) {
        Map<String, Map<String, List<Integer>>> locations = routing.locations();
        Map<String, List<Integer>> indexShards = locations.get(localNodeId);
        for (Map.Entry<String, List<Integer>> indexShardsEntry : indexShards.entrySet()) {
            String index = indexShardsEntry.getKey();
            Integer base = phase.bases().get(index);
            if (base == null) {
                continue;
            }
            TableIdent ident = index2TableIdent.get(index);
            assert ident != null : "no tableIdent found for index " + index;
            tableIdents.put(base, ident);
            toFetch.put(ident, new ArrayList<Reference>());
            for (Integer shard : indexShardsEntry.getValue()) {
                ShardId shardId = new ShardId(index, shard);
                int readerId = base + shardId.id();
                SharedShardContext shardContext = shardContexts.get(readerId);
                if (shardContext == null) {
                    shardContext = sharedShardContexts.createContext(shardId, readerId);
                    shardContexts.put(readerId, shardContext);
                    if (tablesWithFetchRefs.contains(ident)) {
                        try {
                            searchers.put(readerId, shardContext.acquireSearcher());
                        } catch (IndexNotFoundException e) {
                            if (!PartitionName.isPartition(index)) {
                                throw e;
                            }
                        }
                    }
                }
            }
        }
    }
    for (Reference reference : phase.fetchRefs()) {
        Collection<Reference> references = toFetch.get(reference.ident().tableIdent());
        if (references != null) {
            references.add(reference);
        }
    }
}
Also used : IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) Reference(io.crate.metadata.Reference) Routing(io.crate.metadata.Routing) TableIdent(io.crate.metadata.TableIdent) ShardId(org.elasticsearch.index.shard.ShardId) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) SharedShardContext(io.crate.action.job.SharedShardContext)

Example 70 with IndexNotFoundException

use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.

the class BulkRetryCoordinatorPool method coordinator.

public BulkRetryCoordinator coordinator(ShardId shardId) throws IndexNotFoundException, ShardNotFoundException {
    synchronized (coordinatorsByShardId) {
        BulkRetryCoordinator coordinator = coordinatorsByShardId.get(shardId);
        if (coordinator == null) {
            IndexRoutingTable indexRoutingTable = clusterService.state().routingTable().index(shardId.getIndex());
            if (indexRoutingTable == null) {
                throw new IndexNotFoundException("cannot find index " + shardId.index());
            }
            IndexShardRoutingTable shardRoutingTable = indexRoutingTable.shard(shardId.id());
            if (shardRoutingTable == null) {
                throw new ShardNotFoundException(shardId);
            }
            String nodeId = shardRoutingTable.primaryShard().currentNodeId();
            // wow, that is a long comment!
            synchronized (coordinatorsByNodeId) {
                coordinator = coordinatorsByNodeId.get(nodeId);
                if (coordinator == null) {
                    LOGGER.debug("create new coordinator for node {} and shard {}", nodeId, shardId);
                    coordinator = new BulkRetryCoordinator(threadPool);
                    coordinatorsByNodeId.put(nodeId, coordinator);
                }
            }
            coordinatorsByShardId.put(shardId, coordinator);
        }
        return coordinator;
    }
}
Also used : IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) 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