Search in sources :

Example 1 with INTERNAL_SERVER_ERROR

use of io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR in project crate by crate.

the class GatewayIndexStateIT method testRecoverMissingAnalyzer.

/**
 * This test really tests worst case scenario where we have a missing analyzer setting.
 * In that case we now have the ability to check the index on local recovery from disk
 * if it is sane and if we can successfully create an IndexService.
 * This also includes plugins etc.
 */
@Test
public void testRecoverMissingAnalyzer() throws Exception {
    logger.info("--> starting one node");
    internalCluster().startNode();
    var tableName = getFqn("test");
    prepareCreate(tableName).setSettings(Settings.builder().put("index.analysis.analyzer.test.tokenizer", "standard").put("index.number_of_shards", "1")).addMapping("default", "{\n" + "    \"default\": {\n" + "      \"properties\": {\n" + "        \"field1\": {\n" + "          \"type\": \"text\",\n" + "          \"analyzer\": \"test\"\n" + "        }\n" + "      }\n" + "    }\n" + "  }}", XContentType.JSON).get();
    logger.info("--> indexing a simple document");
    execute("insert into test (field1) values ('value one')");
    execute("refresh table test");
    logger.info("--> waiting for green status");
    if (usually()) {
        ensureYellow();
    } else {
        internalCluster().startNode();
        client().admin().cluster().health(Requests.clusterHealthRequest().waitForGreenStatus().waitForEvents(Priority.LANGUID).waitForNoRelocatingShards(true).waitForNodes("2")).actionGet(REQUEST_TIMEOUT);
    }
    ClusterState state = client().admin().cluster().prepareState().get().getState();
    final IndexMetadata metadata = state.getMetadata().index(tableName);
    final IndexMetadata.Builder brokenMeta = IndexMetadata.builder(metadata).settings(metadata.getSettings().filter((s) -> "index.analysis.analyzer.test.tokenizer".equals(s) == false));
    restartNodesOnBrokenClusterState(ClusterState.builder(state).metadata(Metadata.builder(state.getMetadata()).put(brokenMeta)));
    // check that the cluster does not keep reallocating shards
    assertBusy(() -> {
        final RoutingTable routingTable = client().admin().cluster().prepareState().execute().actionGet(REQUEST_TIMEOUT).getState().routingTable();
        final IndexRoutingTable indexRoutingTable = routingTable.index(tableName);
        assertNotNull(indexRoutingTable);
        for (IndexShardRoutingTable shardRoutingTable : indexRoutingTable) {
            assertTrue(shardRoutingTable.primaryShard().unassigned());
            assertEquals(UnassignedInfo.AllocationStatus.DECIDERS_NO, shardRoutingTable.primaryShard().unassignedInfo().getLastAllocationStatus());
            assertThat(shardRoutingTable.primaryShard().unassignedInfo().getNumFailedAllocations(), greaterThan(0));
        }
    }, 60, TimeUnit.SECONDS);
    execute("alter table test close");
    // try to open it with the broken setting - fail again!
    assertThrowsMatches(() -> execute("alter table test open"), isSQLError(is("Failed to verify index " + metadata.getIndex().getName()), INTERNAL_ERROR, INTERNAL_SERVER_ERROR, 5000));
}
Also used : REQUEST_TIMEOUT(io.crate.testing.SQLTransportExecutor.REQUEST_TIMEOUT) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) Scope(org.elasticsearch.test.ESIntegTestCase.Scope) Locale(java.util.Locale) Map(java.util.Map) SQLTransportExecutor(io.crate.testing.SQLTransportExecutor) SQLOperations(io.crate.action.sql.SQLOperations) Priority(org.elasticsearch.common.Priority) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) SETTING_CLUSTER_MAX_SHARDS_PER_NODE(org.elasticsearch.indices.ShardLimitValidator.SETTING_CLUSTER_MAX_SHARDS_PER_NODE) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) RestartCallback(org.elasticsearch.test.InternalTestCluster.RestartCallback) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Version(org.elasticsearch.Version) Stream(java.util.stream.Stream) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) ESIntegTestCase(org.elasticsearch.test.ESIntegTestCase) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TimeValue(io.crate.common.unit.TimeValue) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) INTERNAL_ERROR(io.crate.protocols.postgres.PGErrorStatus.INTERNAL_ERROR) XContentType(org.elasticsearch.common.xcontent.XContentType) INTERNAL_SERVER_ERROR(io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR) SQLIntegrationTestCase(io.crate.integrationtests.SQLIntegrationTestCase) IndexGraveyard(org.elasticsearch.cluster.metadata.IndexGraveyard) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) Function(java.util.function.Function) Asserts.assertThrowsMatches(io.crate.testing.Asserts.assertThrowsMatches) Metadata(org.elasticsearch.cluster.metadata.Metadata) Node(org.elasticsearch.node.Node) Requests(org.elasticsearch.client.Requests) ClusterScope(org.elasticsearch.test.ESIntegTestCase.ClusterScope) Client(org.elasticsearch.client.Client) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) Test(org.junit.Test) IOException(java.io.IOException) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) TimeUnit(java.util.concurrent.TimeUnit) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) SQLErrorMatcher.isSQLError(io.crate.testing.SQLErrorMatcher.isSQLError) PostgresNetty(io.crate.protocols.postgres.PostgresNetty) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) LogManager(org.apache.logging.log4j.LogManager) ClusterState(org.elasticsearch.cluster.ClusterState) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Test(org.junit.Test)

Aggregations

SQLOperations (io.crate.action.sql.SQLOperations)1 TimeValue (io.crate.common.unit.TimeValue)1 SQLIntegrationTestCase (io.crate.integrationtests.SQLIntegrationTestCase)1 INTERNAL_ERROR (io.crate.protocols.postgres.PGErrorStatus.INTERNAL_ERROR)1 PostgresNetty (io.crate.protocols.postgres.PostgresNetty)1 Asserts.assertThrowsMatches (io.crate.testing.Asserts.assertThrowsMatches)1 SQLErrorMatcher.isSQLError (io.crate.testing.SQLErrorMatcher.isSQLError)1 SQLTransportExecutor (io.crate.testing.SQLTransportExecutor)1 REQUEST_TIMEOUT (io.crate.testing.SQLTransportExecutor.REQUEST_TIMEOUT)1 INTERNAL_SERVER_ERROR (io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 LogManager (org.apache.logging.log4j.LogManager)1