Search in sources :

Example 1 with PendingClusterStatesQueue

use of org.elasticsearch.discovery.zen.PendingClusterStatesQueue in project elasticsearch by elastic.

the class PendingClusterStatesQueueTests method testFailedStateCleansSupersededStatesOnly.

public void testFailedStateCleansSupersededStatesOnly() {
    List<ClusterState> states = randomStates(scaledRandomIntBetween(10, 50), "master1", "master2", "master3", "master4");
    PendingClusterStatesQueue queue = createQueueWithStates(states);
    List<ClusterStateContext> committedContexts = randomCommitStates(queue);
    ClusterState toFail = randomFrom(committedContexts).state;
    queue.markAsFailed(toFail, new ElasticsearchException("boo!"));
    final Map<String, ClusterStateContext> committedContextsById = new HashMap<>();
    for (ClusterStateContext context : committedContexts) {
        committedContextsById.put(context.stateUUID(), context);
    }
    // now check that queue doesn't contain superseded states
    for (ClusterStateContext context : queue.pendingStates) {
        if (context.committed()) {
            assertFalse("found a committed cluster state, which is superseded by a failed state.\nFound:" + context.state + "\nfailed:" + toFail, toFail.supersedes(context.state));
        }
    }
    // check no state has been erroneously removed
    for (ClusterState state : states) {
        ClusterStateContext pendingContext = queue.findState(state.stateUUID());
        if (pendingContext != null) {
            continue;
        }
        if (state.equals(toFail)) {
            continue;
        }
        assertThat("non-committed states should never be removed", committedContextsById, hasKey(state.stateUUID()));
        final ClusterStateContext context = committedContextsById.get(state.stateUUID());
        assertThat("removed state is not superseded by failed state. \nRemoved state:" + context + "\nfailed: " + toFail, toFail.supersedes(context.state), equalTo(true));
        assertThat("removed state was failed with wrong exception", ((MockListener) context.listener).failure, notNullValue());
        assertThat("removed state was failed with wrong exception", ((MockListener) context.listener).failure.getMessage(), containsString("boo"));
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) PendingClusterStatesQueue(org.elasticsearch.discovery.zen.PendingClusterStatesQueue) HashMap(java.util.HashMap) ElasticsearchException(org.elasticsearch.ElasticsearchException) Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterStateContext(org.elasticsearch.discovery.zen.PendingClusterStatesQueue.ClusterStateContext)

Example 2 with PendingClusterStatesQueue

use of org.elasticsearch.discovery.zen.PendingClusterStatesQueue in project elasticsearch by elastic.

the class PendingClusterStatesQueueTests method testSimpleQueueSameMaster.

public void testSimpleQueueSameMaster() {
    final int numUpdates = scaledRandomIntBetween(50, 100);
    List<ClusterState> states = randomStates(numUpdates, "master");
    Collections.shuffle(states, random());
    PendingClusterStatesQueue queue;
    queue = createQueueWithStates(states);
    // no state is committed yet
    assertThat(queue.getNextClusterStateToProcess(), nullValue());
    ClusterState highestCommitted = null;
    for (ClusterStateContext context : randomCommitStates(queue)) {
        if (highestCommitted == null || context.state.supersedes(highestCommitted)) {
            highestCommitted = context.state;
        }
    }
    assertThat(queue.getNextClusterStateToProcess(), sameInstance(highestCommitted));
    queue.markAsProcessed(highestCommitted);
    // now there is nothing more to process
    assertThat(queue.getNextClusterStateToProcess(), nullValue());
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) PendingClusterStatesQueue(org.elasticsearch.discovery.zen.PendingClusterStatesQueue) ClusterStateContext(org.elasticsearch.discovery.zen.PendingClusterStatesQueue.ClusterStateContext)

Example 3 with PendingClusterStatesQueue

use of org.elasticsearch.discovery.zen.PendingClusterStatesQueue in project elasticsearch by elastic.

the class PendingClusterStatesQueueTests method testProcessedStateCleansStatesFromOtherMasters.

public void testProcessedStateCleansStatesFromOtherMasters() {
    List<ClusterState> states = randomStates(scaledRandomIntBetween(10, 300), "master1", "master2", "master3", "master4");
    PendingClusterStatesQueue queue = createQueueWithStates(states);
    List<ClusterStateContext> committedContexts = randomCommitStates(queue);
    ClusterState randomCommitted = randomFrom(committedContexts).state;
    queue.markAsProcessed(randomCommitted);
    final String processedMaster = randomCommitted.nodes().getMasterNodeId();
    // now check that queue doesn't contain anything pending from another master
    for (ClusterStateContext context : queue.pendingStates) {
        final String pendingMaster = context.state.nodes().getMasterNodeId();
        assertThat("found a cluster state from [" + pendingMaster + "], after a state from [" + processedMaster + "] was processed", pendingMaster, equalTo(processedMaster));
    }
    // and check all committed contexts from another master were failed
    for (ClusterStateContext context : committedContexts) {
        if (context.state.nodes().getMasterNodeId().equals(processedMaster) == false) {
            assertThat(((MockListener) context.listener).failure, notNullValue());
        }
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) PendingClusterStatesQueue(org.elasticsearch.discovery.zen.PendingClusterStatesQueue) Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterStateContext(org.elasticsearch.discovery.zen.PendingClusterStatesQueue.ClusterStateContext)

Example 4 with PendingClusterStatesQueue

use of org.elasticsearch.discovery.zen.PendingClusterStatesQueue in project elasticsearch by elastic.

the class PendingClusterStatesQueueTests method testSelectNextStateToProcess_empty.

public void testSelectNextStateToProcess_empty() {
    PendingClusterStatesQueue queue = new PendingClusterStatesQueue(logger, randomIntBetween(1, 200));
    assertThat(queue.getNextClusterStateToProcess(), nullValue());
}
Also used : PendingClusterStatesQueue(org.elasticsearch.discovery.zen.PendingClusterStatesQueue)

Example 5 with PendingClusterStatesQueue

use of org.elasticsearch.discovery.zen.PendingClusterStatesQueue in project elasticsearch by elastic.

the class PendingClusterStatesQueueTests method testQueueStats.

public void testQueueStats() {
    List<ClusterState> states = randomStates(scaledRandomIntBetween(10, 100), "master");
    PendingClusterStatesQueue queue = createQueueWithStates(states);
    assertThat(queue.stats().getTotal(), equalTo(states.size()));
    assertThat(queue.stats().getPending(), equalTo(states.size()));
    assertThat(queue.stats().getCommitted(), equalTo(0));
    List<ClusterStateContext> committedContexts = randomCommitStates(queue);
    assertThat(queue.stats().getTotal(), equalTo(states.size()));
    assertThat(queue.stats().getPending(), equalTo(states.size() - committedContexts.size()));
    assertThat(queue.stats().getCommitted(), equalTo(committedContexts.size()));
    ClusterState highestCommitted = null;
    for (ClusterStateContext context : committedContexts) {
        if (highestCommitted == null || context.state.supersedes(highestCommitted)) {
            highestCommitted = context.state;
        }
    }
    assert highestCommitted != null;
    queue.markAsProcessed(highestCommitted);
    assertThat((long) queue.stats().getTotal(), equalTo(states.size() - (1 + highestCommitted.version())));
    assertThat((long) queue.stats().getPending(), equalTo(states.size() - (1 + highestCommitted.version())));
    assertThat(queue.stats().getCommitted(), equalTo(0));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) PendingClusterStatesQueue(org.elasticsearch.discovery.zen.PendingClusterStatesQueue) ClusterStateContext(org.elasticsearch.discovery.zen.PendingClusterStatesQueue.ClusterStateContext)

Aggregations

PendingClusterStatesQueue (org.elasticsearch.discovery.zen.PendingClusterStatesQueue)8 ClusterState (org.elasticsearch.cluster.ClusterState)7 ClusterStateContext (org.elasticsearch.discovery.zen.PendingClusterStatesQueue.ClusterStateContext)6 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 HashMap (java.util.HashMap)1