Search in sources :

Example 1 with CloseIndexRequest

use of org.elasticsearch.action.admin.indices.close.CloseIndexRequest in project crate by crate.

the class PartitionedTableIntegrationTest method testInsertIntoClosedPartition.

@Test
public void testInsertIntoClosedPartition() throws Exception {
    execute("create table t (n integer) partitioned by (n)");
    ensureYellow();
    execute("insert into t (n) values (1)");
    ensureYellow();
    String[] indices = client().admin().indices().getIndex(new GetIndexRequest()).actionGet().getIndices();
    client().admin().indices().close(new CloseIndexRequest(indices[0])).actionGet();
    expectedException.expect(SQLActionException.class);
    expectedException.expectMessage(String.format("Unable to access the partition %s, it is closed", indices[0]));
    execute("insert into t (n) values (1)");
}
Also used : CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) GetIndexRequest(org.elasticsearch.action.admin.indices.get.GetIndexRequest) Test(org.junit.Test)

Example 2 with CloseIndexRequest

use of org.elasticsearch.action.admin.indices.close.CloseIndexRequest in project crate by crate.

the class PartitionedTableIntegrationTest method testSelectFromClosedPartition.

@Test
public void testSelectFromClosedPartition() throws Exception {
    execute("create table t (n integer) partitioned by (n)");
    ensureYellow();
    execute("insert into t (n) values (1)");
    ensureGreen();
    String[] indices = client().admin().indices().getIndex(new GetIndexRequest()).actionGet().getIndices();
    client().admin().indices().close(new CloseIndexRequest(indices[0])).actionGet();
    expectedException.expect(SQLActionException.class);
    expectedException.expectMessage(String.format("Unable to access the partition %s, it is closed", indices[0]));
    execute("select count(*) from t");
}
Also used : CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) GetIndexRequest(org.elasticsearch.action.admin.indices.get.GetIndexRequest) Test(org.junit.Test)

Example 3 with CloseIndexRequest

use of org.elasticsearch.action.admin.indices.close.CloseIndexRequest in project elasticsearch by elastic.

the class IndicesClusterStateServiceRandomUpdatesTests method randomlyUpdateClusterState.

public ClusterState randomlyUpdateClusterState(ClusterState state, Map<DiscoveryNode, IndicesClusterStateService> clusterStateServiceMap, Supplier<MockIndicesService> indicesServiceSupplier) {
    // randomly create new indices (until we have 200 max)
    for (int i = 0; i < randomInt(5); i++) {
        if (state.metaData().indices().size() > 200) {
            break;
        }
        String name = "index_" + randomAsciiOfLength(15).toLowerCase(Locale.ROOT);
        Settings.Builder settingsBuilder = Settings.builder().put(SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 3)).put(SETTING_NUMBER_OF_REPLICAS, randomInt(2));
        if (randomBoolean()) {
            settingsBuilder.put(IndexMetaData.SETTING_SHADOW_REPLICAS, true).put(IndexMetaData.SETTING_SHARED_FILESYSTEM, true);
        }
        CreateIndexRequest request = new CreateIndexRequest(name, settingsBuilder.build()).waitForActiveShards(ActiveShardCount.NONE);
        state = cluster.createIndex(state, request);
        assertTrue(state.metaData().hasIndex(name));
    }
    // randomly delete indices
    Set<String> indicesToDelete = new HashSet<>();
    int numberOfIndicesToDelete = randomInt(Math.min(2, state.metaData().indices().size()));
    for (String index : randomSubsetOf(numberOfIndicesToDelete, state.metaData().indices().keys().toArray(String.class))) {
        indicesToDelete.add(state.metaData().index(index).getIndex().getName());
    }
    if (indicesToDelete.isEmpty() == false) {
        DeleteIndexRequest deleteRequest = new DeleteIndexRequest(indicesToDelete.toArray(new String[indicesToDelete.size()]));
        state = cluster.deleteIndices(state, deleteRequest);
        for (String index : indicesToDelete) {
            assertFalse(state.metaData().hasIndex(index));
        }
    }
    // randomly close indices
    int numberOfIndicesToClose = randomInt(Math.min(1, state.metaData().indices().size()));
    for (String index : randomSubsetOf(numberOfIndicesToClose, state.metaData().indices().keys().toArray(String.class))) {
        CloseIndexRequest closeIndexRequest = new CloseIndexRequest(state.metaData().index(index).getIndex().getName());
        state = cluster.closeIndices(state, closeIndexRequest);
    }
    // randomly open indices
    int numberOfIndicesToOpen = randomInt(Math.min(1, state.metaData().indices().size()));
    for (String index : randomSubsetOf(numberOfIndicesToOpen, state.metaData().indices().keys().toArray(String.class))) {
        OpenIndexRequest openIndexRequest = new OpenIndexRequest(state.metaData().index(index).getIndex().getName());
        state = cluster.openIndices(state, openIndexRequest);
    }
    // randomly update settings
    Set<String> indicesToUpdate = new HashSet<>();
    boolean containsClosedIndex = false;
    int numberOfIndicesToUpdate = randomInt(Math.min(2, state.metaData().indices().size()));
    for (String index : randomSubsetOf(numberOfIndicesToUpdate, state.metaData().indices().keys().toArray(String.class))) {
        indicesToUpdate.add(state.metaData().index(index).getIndex().getName());
        if (state.metaData().index(index).getState() == IndexMetaData.State.CLOSE) {
            containsClosedIndex = true;
        }
    }
    if (indicesToUpdate.isEmpty() == false) {
        UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(indicesToUpdate.toArray(new String[indicesToUpdate.size()]));
        Settings.Builder settings = Settings.builder();
        if (containsClosedIndex == false) {
            settings.put(SETTING_NUMBER_OF_REPLICAS, randomInt(2));
        }
        settings.put("index.refresh_interval", randomIntBetween(1, 5) + "s");
        updateSettingsRequest.settings(settings.build());
        state = cluster.updateSettings(state, updateSettingsRequest);
    }
    // randomly reroute
    if (rarely()) {
        state = cluster.reroute(state, new ClusterRerouteRequest());
    }
    // randomly start and fail allocated shards
    List<ShardRouting> startedShards = new ArrayList<>();
    List<FailedShard> failedShards = new ArrayList<>();
    for (DiscoveryNode node : state.nodes()) {
        IndicesClusterStateService indicesClusterStateService = clusterStateServiceMap.get(node);
        MockIndicesService indicesService = (MockIndicesService) indicesClusterStateService.indicesService;
        for (MockIndexService indexService : indicesService) {
            for (MockIndexShard indexShard : indexService) {
                ShardRouting persistedShardRouting = indexShard.routingEntry();
                if (persistedShardRouting.initializing() && randomBoolean()) {
                    startedShards.add(persistedShardRouting);
                } else if (rarely()) {
                    failedShards.add(new FailedShard(persistedShardRouting, "fake shard failure", new Exception()));
                }
            }
        }
    }
    state = cluster.applyFailedShards(state, failedShards);
    state = cluster.applyStartedShards(state, startedShards);
    // randomly add and remove nodes (except current master)
    if (rarely()) {
        if (randomBoolean()) {
            // add node
            if (state.nodes().getSize() < 10) {
                DiscoveryNodes newNodes = DiscoveryNodes.builder(state.nodes()).add(createNode()).build();
                state = ClusterState.builder(state).nodes(newNodes).build();
                // always reroute after node leave
                state = cluster.reroute(state, new ClusterRerouteRequest());
                updateNodes(state, clusterStateServiceMap, indicesServiceSupplier);
            }
        } else {
            // remove node
            if (state.nodes().getDataNodes().size() > 3) {
                DiscoveryNode discoveryNode = randomFrom(state.nodes().getNodes().values().toArray(DiscoveryNode.class));
                if (discoveryNode.equals(state.nodes().getMasterNode()) == false) {
                    DiscoveryNodes newNodes = DiscoveryNodes.builder(state.nodes()).remove(discoveryNode.getId()).build();
                    state = ClusterState.builder(state).nodes(newNodes).build();
                    state = cluster.deassociateDeadNodes(state, true, "removed and added a node");
                    updateNodes(state, clusterStateServiceMap, indicesServiceSupplier);
                }
                if (randomBoolean()) {
                    // and add it back
                    DiscoveryNodes newNodes = DiscoveryNodes.builder(state.nodes()).add(discoveryNode).build();
                    state = ClusterState.builder(state).nodes(newNodes).build();
                    state = cluster.reroute(state, new ClusterRerouteRequest());
                    updateNodes(state, clusterStateServiceMap, indicesServiceSupplier);
                }
            }
        }
    }
    return state;
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) ArrayList(java.util.ArrayList) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) ClusterRerouteRequest(org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest) Settings(org.elasticsearch.common.settings.Settings) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) HashSet(java.util.HashSet) OpenIndexRequest(org.elasticsearch.action.admin.indices.open.OpenIndexRequest) FailedShard(org.elasticsearch.cluster.routing.allocation.FailedShard) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 4 with CloseIndexRequest

use of org.elasticsearch.action.admin.indices.close.CloseIndexRequest in project elasticsearch by elastic.

the class RestCloseIndexAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    CloseIndexRequest closeIndexRequest = new CloseIndexRequest(Strings.splitStringByCommaToArray(request.param("index")));
    closeIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", closeIndexRequest.masterNodeTimeout()));
    closeIndexRequest.timeout(request.paramAsTime("timeout", closeIndexRequest.timeout()));
    closeIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, closeIndexRequest.indicesOptions()));
    return channel -> client.admin().indices().close(closeIndexRequest, new AcknowledgedRestListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) Settings(org.elasticsearch.common.settings.Settings) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest)

Example 5 with CloseIndexRequest

use of org.elasticsearch.action.admin.indices.close.CloseIndexRequest in project elasticsearch by elastic.

the class IndicesRequestIT method testCloseIndex.

public void testCloseIndex() {
    interceptTransportActions(CloseIndexAction.NAME);
    CloseIndexRequest closeIndexRequest = new CloseIndexRequest(randomUniqueIndicesOrAliases());
    internalCluster().coordOnlyNodeClient().admin().indices().close(closeIndexRequest).actionGet();
    clearInterceptedActions();
    assertSameIndices(closeIndexRequest, CloseIndexAction.NAME);
}
Also used : CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest)

Aggregations

CloseIndexRequest (org.elasticsearch.action.admin.indices.close.CloseIndexRequest)6 GetIndexRequest (org.elasticsearch.action.admin.indices.get.GetIndexRequest)2 Settings (org.elasticsearch.common.settings.Settings)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ClusterRerouteRequest (org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest)1 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)1 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)1 OpenIndexRequest (org.elasticsearch.action.admin.indices.open.OpenIndexRequest)1 UpdateSettingsRequest (org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest)1 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)1 PlainActionFuture (org.elasticsearch.action.support.PlainActionFuture)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 ClusterBlockLevel (org.elasticsearch.cluster.block.ClusterBlockLevel)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)1 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)1 FailedShard (org.elasticsearch.cluster.routing.allocation.FailedShard)1