Search in sources :

Example 6 with IndexNotFoundException

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

the class SimpleIndexStateIT method testConsistencyAfterIndexCreationFailure.

public void testConsistencyAfterIndexCreationFailure() {
    logger.info("--> deleting test index....");
    try {
        client().admin().indices().prepareDelete("test").get();
    } catch (IndexNotFoundException ex) {
    // Ignore
    }
    logger.info("--> creating test index with invalid settings ");
    try {
        client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put("number_of_shards", "bad")).get();
        fail();
    } catch (IllegalArgumentException ex) {
        assertEquals("Failed to parse value [bad] for setting [index.number_of_shards]", ex.getMessage());
    // Expected
    }
    logger.info("--> creating test index with valid settings ");
    CreateIndexResponse response = client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put("number_of_shards", 1)).get();
    assertThat(response.isAcknowledged(), equalTo(true));
}
Also used : IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse)

Example 7 with IndexNotFoundException

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

the class TransportClusterHealthAction method prepareResponse.

private boolean prepareResponse(final ClusterHealthRequest request, final ClusterHealthResponse response, ClusterState clusterState, final int waitFor) {
    int waitForCounter = 0;
    if (request.waitForStatus() != null && response.getStatus().value() <= request.waitForStatus().value()) {
        waitForCounter++;
    }
    if (request.waitForNoRelocatingShards() && response.getRelocatingShards() == 0) {
        waitForCounter++;
    }
    if (request.waitForActiveShards().equals(ActiveShardCount.NONE) == false) {
        ActiveShardCount waitForActiveShards = request.waitForActiveShards();
        assert waitForActiveShards.equals(ActiveShardCount.DEFAULT) == false : "waitForActiveShards must not be DEFAULT on the request object, instead it should be NONE";
        if (waitForActiveShards.equals(ActiveShardCount.ALL) && response.getUnassignedShards() == 0 && response.getInitializingShards() == 0) {
            // if we are waiting for all shards to be active, then the num of unassigned and num of initializing shards must be 0
            waitForCounter++;
        } else if (waitForActiveShards.enoughShardsActive(response.getActiveShards())) {
            // there are enough active shards to meet the requirements of the request
            waitForCounter++;
        }
    }
    if (request.indices() != null && request.indices().length > 0) {
        try {
            indexNameExpressionResolver.concreteIndexNames(clusterState, IndicesOptions.strictExpand(), request.indices());
            waitForCounter++;
        } catch (IndexNotFoundException e) {
            // no indices, make sure its RED
            response.setStatus(ClusterHealthStatus.RED);
        // missing indices, wait a bit more...
        }
    }
    if (!request.waitForNodes().isEmpty()) {
        if (request.waitForNodes().startsWith(">=")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(2));
            if (response.getNumberOfNodes() >= expected) {
                waitForCounter++;
            }
        } else if (request.waitForNodes().startsWith("ge(")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(3, request.waitForNodes().length() - 1));
            if (response.getNumberOfNodes() >= expected) {
                waitForCounter++;
            }
        } else if (request.waitForNodes().startsWith("<=")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(2));
            if (response.getNumberOfNodes() <= expected) {
                waitForCounter++;
            }
        } else if (request.waitForNodes().startsWith("le(")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(3, request.waitForNodes().length() - 1));
            if (response.getNumberOfNodes() <= expected) {
                waitForCounter++;
            }
        } else if (request.waitForNodes().startsWith(">")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(1));
            if (response.getNumberOfNodes() > expected) {
                waitForCounter++;
            }
        } else if (request.waitForNodes().startsWith("gt(")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(3, request.waitForNodes().length() - 1));
            if (response.getNumberOfNodes() > expected) {
                waitForCounter++;
            }
        } else if (request.waitForNodes().startsWith("<")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(1));
            if (response.getNumberOfNodes() < expected) {
                waitForCounter++;
            }
        } else if (request.waitForNodes().startsWith("lt(")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(3, request.waitForNodes().length() - 1));
            if (response.getNumberOfNodes() < expected) {
                waitForCounter++;
            }
        } else {
            int expected = Integer.parseInt(request.waitForNodes());
            if (response.getNumberOfNodes() == expected) {
                waitForCounter++;
            }
        }
    }
    return waitForCounter == waitFor;
}
Also used : IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) ActiveShardCount(org.elasticsearch.action.support.ActiveShardCount)

Example 8 with IndexNotFoundException

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

the class CancelAllocationCommand method execute.

@Override
public RerouteExplanation execute(RoutingAllocation allocation, boolean explain) {
    DiscoveryNode discoNode = allocation.nodes().resolveNode(node);
    ShardRouting shardRouting = null;
    RoutingNodes routingNodes = allocation.routingNodes();
    RoutingNode routingNode = routingNodes.node(discoNode.getId());
    IndexMetaData indexMetaData = null;
    if (routingNode != null) {
        indexMetaData = allocation.metaData().index(index());
        if (indexMetaData == null) {
            throw new IndexNotFoundException(index());
        }
        ShardId shardId = new ShardId(indexMetaData.getIndex(), shardId());
        shardRouting = routingNode.getByShardId(shardId);
    }
    if (shardRouting == null) {
        if (explain) {
            return new RerouteExplanation(this, allocation.decision(Decision.NO, "cancel_allocation_command", "can't cancel " + shardId + ", failed to find it on node " + discoNode));
        }
        throw new IllegalArgumentException("[cancel_allocation] can't cancel " + shardId + ", failed to find it on node " + discoNode);
    }
    if (shardRouting.primary() && allowPrimary == false) {
        if ((shardRouting.initializing() && shardRouting.relocatingNodeId() != null) == false) {
            // only allow cancelling initializing shard of primary relocation without allowPrimary flag
            if (explain) {
                return new RerouteExplanation(this, allocation.decision(Decision.NO, "cancel_allocation_command", "can't cancel " + shardId + " on node " + discoNode + ", shard is primary and " + shardRouting.state().name().toLowerCase(Locale.ROOT)));
            }
            throw new IllegalArgumentException("[cancel_allocation] can't cancel " + shardId + " on node " + discoNode + ", shard is primary and " + shardRouting.state().name().toLowerCase(Locale.ROOT));
        }
    }
    routingNodes.failShard(Loggers.getLogger(CancelAllocationCommand.class), shardRouting, new UnassignedInfo(UnassignedInfo.Reason.REROUTE_CANCELLED, null), indexMetaData, allocation.changes());
    return new RerouteExplanation(this, allocation.decision(Decision.YES, "cancel_allocation_command", "shard " + shardId + " on node " + discoNode + " can be cancelled"));
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) RoutingNode(org.elasticsearch.cluster.routing.RoutingNode) RoutingNodes(org.elasticsearch.cluster.routing.RoutingNodes) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) RerouteExplanation(org.elasticsearch.cluster.routing.allocation.RerouteExplanation) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 9 with IndexNotFoundException

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

the class AutoCreateIndexTests method testDynamicMappingDisabled.

public void testDynamicMappingDisabled() {
    Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), randomFrom(true, randomAsciiOfLengthBetween(1, 10))).put(MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey(), false).build();
    AutoCreateIndex autoCreateIndex = newAutoCreateIndex(settings);
    IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> autoCreateIndex.shouldAutoCreate(randomAsciiOfLengthBetween(1, 10), buildClusterState()));
    assertEquals("no such index and [index.mapper.dynamic] is [false]", e.getMessage());
}
Also used : IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 10 with IndexNotFoundException

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

the class SimpleClusterStateIT method testIndicesOptionsOnAllowNoIndicesFalse.

public void testIndicesOptionsOnAllowNoIndicesFalse() throws Exception {
    // empty wildcard expansion throws exception when allowNoIndices is turned off
    IndicesOptions allowNoIndices = IndicesOptions.fromOptions(false, false, true, false);
    try {
        client().admin().cluster().prepareState().clear().setMetaData(true).setIndices("a*").setIndicesOptions(allowNoIndices).get();
        fail("Expected IndexNotFoundException");
    } catch (IndexNotFoundException e) {
        assertThat(e.getMessage(), is("no such index"));
    }
}
Also used : IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) IndicesOptions(org.elasticsearch.action.support.IndicesOptions)

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