Search in sources :

Example 1 with ClusterBlockLevel

use of org.elasticsearch.cluster.block.ClusterBlockLevel in project elasticsearch by elastic.

the class TransportReplicationActionTests method testBlocks.

public void testBlocks() throws ExecutionException, InterruptedException {
    Request request = new Request();
    PlainActionFuture<TestResponse> listener = new PlainActionFuture<>();
    ReplicationTask task = maybeTask();
    TestAction action = new TestAction(Settings.EMPTY, "testActionWithBlocks", transportService, clusterService, shardStateAction, threadPool) {

        @Override
        protected ClusterBlockLevel globalBlockLevel() {
            return ClusterBlockLevel.WRITE;
        }
    };
    ClusterBlocks.Builder block = ClusterBlocks.builder().addGlobalBlock(new ClusterBlock(1, "non retryable", false, true, RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL));
    setState(clusterService, ClusterState.builder(clusterService.state()).blocks(block));
    TestAction.ReroutePhase reroutePhase = action.new ReroutePhase(task, request, listener);
    reroutePhase.run();
    assertListenerThrows("primary phase should fail operation", listener, ClusterBlockException.class);
    assertPhase(task, "failed");
    block = ClusterBlocks.builder().addGlobalBlock(new ClusterBlock(1, "retryable", true, true, RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL));
    setState(clusterService, ClusterState.builder(clusterService.state()).blocks(block));
    listener = new PlainActionFuture<>();
    reroutePhase = action.new ReroutePhase(task, new Request().timeout("5ms"), listener);
    reroutePhase.run();
    assertListenerThrows("failed to timeout on retryable block", listener, ClusterBlockException.class);
    assertPhase(task, "failed");
    assertFalse(request.isRetrySet.get());
    listener = new PlainActionFuture<>();
    reroutePhase = action.new ReroutePhase(task, request = new Request(), listener);
    reroutePhase.run();
    assertFalse("primary phase should wait on retryable block", listener.isDone());
    assertPhase(task, "waiting_for_retry");
    assertTrue(request.isRetrySet.get());
    block = ClusterBlocks.builder().addGlobalBlock(new ClusterBlock(1, "non retryable", false, true, RestStatus.SERVICE_UNAVAILABLE, ClusterBlockLevel.ALL));
    setState(clusterService, ClusterState.builder(clusterService.state()).blocks(block));
    assertListenerThrows("primary phase should fail operation when moving from a retryable block to a non-retryable one", listener, ClusterBlockException.class);
    assertIndexShardUninitialized();
    action = new TestAction(Settings.EMPTY, "testActionWithNoBlocks", transportService, clusterService, shardStateAction, threadPool) {

        @Override
        protected ClusterBlockLevel globalBlockLevel() {
            return null;
        }
    };
    listener = new PlainActionFuture<>();
    reroutePhase = action.new ReroutePhase(task, new Request().timeout("5ms"), listener);
    reroutePhase.run();
    assertListenerThrows("should fail with an IndexNotFoundException when no blocks checked", listener, IndexNotFoundException.class);
}
Also used : ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) TransportRequest(org.elasticsearch.transport.TransportRequest) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) ClusterBlockLevel(org.elasticsearch.cluster.block.ClusterBlockLevel) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture)

Example 2 with ClusterBlockLevel

use of org.elasticsearch.cluster.block.ClusterBlockLevel in project crate by crate.

the class TransportReplicationAction method blockExceptions.

private ClusterBlockException blockExceptions(final ClusterState state, final String indexName) {
    ClusterBlockLevel globalBlockLevel = globalBlockLevel();
    if (globalBlockLevel != null) {
        ClusterBlockException blockException = state.blocks().globalBlockedException(globalBlockLevel);
        if (blockException != null) {
            return blockException;
        }
    }
    ClusterBlockLevel indexBlockLevel = indexBlockLevel();
    if (indexBlockLevel != null) {
        ClusterBlockException blockException = state.blocks().indexBlockedException(indexBlockLevel, indexName);
        if (blockException != null) {
            return blockException;
        }
    }
    return null;
}
Also used : ClusterBlockLevel(org.elasticsearch.cluster.block.ClusterBlockLevel) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException)

Example 3 with ClusterBlockLevel

use of org.elasticsearch.cluster.block.ClusterBlockLevel in project crate by crate.

the class AbstractDisruptionTestCase method assertNoMaster.

void assertNoMaster(final String node, @Nullable final ClusterBlock expectedBlocks, TimeValue maxWaitTime) throws Exception {
    assertBusy(() -> {
        ClusterState state = getNodeClusterState(node);
        final DiscoveryNodes nodes = state.nodes();
        assertNull("node [" + node + "] still has [" + nodes.getMasterNode() + "] as master", nodes.getMasterNode());
        if (expectedBlocks != null) {
            for (ClusterBlockLevel level : expectedBlocks.levels()) {
                assertTrue("node [" + node + "] does have level [" + level + "] in it's blocks", state.getBlocks().hasGlobalBlockWithLevel(level));
            }
        }
    }, maxWaitTime.getMillis(), TimeUnit.MILLISECONDS);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterBlockLevel(org.elasticsearch.cluster.block.ClusterBlockLevel) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 4 with ClusterBlockLevel

use of org.elasticsearch.cluster.block.ClusterBlockLevel in project elasticsearch by elastic.

the class TransportReplicationActionTests method testClosedIndexOnReroute.

public void testClosedIndexOnReroute() throws InterruptedException {
    final String index = "test";
    // no replicas in oder to skip the replication part
    setState(clusterService, new ClusterStateChanges(xContentRegistry(), threadPool).closeIndices(state(index, true, ShardRoutingState.UNASSIGNED), new CloseIndexRequest(index)));
    logger.debug("--> using initial state:\n{}", clusterService.state());
    Request request = new Request(new ShardId("test", "_na_", 0)).timeout("1ms");
    PlainActionFuture<TestResponse> listener = new PlainActionFuture<>();
    ReplicationTask task = maybeTask();
    ClusterBlockLevel indexBlockLevel = randomBoolean() ? ClusterBlockLevel.WRITE : null;
    TestAction action = new TestAction(Settings.EMPTY, "testActionWithBlocks", transportService, clusterService, shardStateAction, threadPool) {

        @Override
        protected ClusterBlockLevel indexBlockLevel() {
            return indexBlockLevel;
        }
    };
    TestAction.ReroutePhase reroutePhase = action.new ReroutePhase(task, request, listener);
    reroutePhase.run();
    if (indexBlockLevel == ClusterBlockLevel.WRITE) {
        assertListenerThrows("must throw block exception", listener, ClusterBlockException.class);
    } else {
        assertListenerThrows("must throw index closed exception", listener, IndexClosedException.class);
    }
    assertPhase(task, "failed");
    assertFalse(request.isRetrySet.get());
}
Also used : TransportRequest(org.elasticsearch.transport.TransportRequest) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) ClusterStateChanges(org.elasticsearch.indices.cluster.ClusterStateChanges) ShardId(org.elasticsearch.index.shard.ShardId) ClusterBlockLevel(org.elasticsearch.cluster.block.ClusterBlockLevel) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) PlainActionFuture(org.elasticsearch.action.support.PlainActionFuture)

Aggregations

ClusterBlockLevel (org.elasticsearch.cluster.block.ClusterBlockLevel)4 CloseIndexRequest (org.elasticsearch.action.admin.indices.close.CloseIndexRequest)2 PlainActionFuture (org.elasticsearch.action.support.PlainActionFuture)2 TransportRequest (org.elasticsearch.transport.TransportRequest)2 ClusterState (org.elasticsearch.cluster.ClusterState)1 ClusterBlock (org.elasticsearch.cluster.block.ClusterBlock)1 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)1 ClusterBlocks (org.elasticsearch.cluster.block.ClusterBlocks)1 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)1 ShardId (org.elasticsearch.index.shard.ShardId)1 ClusterStateChanges (org.elasticsearch.indices.cluster.ClusterStateChanges)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Matchers.anyString (org.mockito.Matchers.anyString)1