Search in sources :

Example 6 with CoordinationMetadata

use of org.elasticsearch.cluster.coordination.CoordinationMetadata in project crate by crate.

the class TransportAddVotingConfigExclusionsActionTests method testSucceedsEvenIfAllExclusionsAlreadyAdded.

public void testSucceedsEvenIfAllExclusionsAlreadyAdded() throws InterruptedException {
    final ClusterState state = clusterService.state();
    final ClusterState.Builder builder = builder(state);
    builder.metadata(Metadata.builder(state.metadata()).coordinationMetadata(CoordinationMetadata.builder(state.coordinationMetadata()).addVotingConfigExclusion(otherNode1Exclusion).build()));
    setState(clusterService, builder);
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, new AddVotingConfigExclusionsRequest(new String[] { "other1" }), expectSuccess(r -> {
        assertNotNull(r);
        countDownLatch.countDown();
    }));
    assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
    assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(), contains(otherNode1Exclusion));
}
Also used : Builder(org.elasticsearch.cluster.node.DiscoveryNodes.Builder) Listener(org.elasticsearch.cluster.ClusterStateObserver.Listener) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) CoordinationMetadata(org.elasticsearch.cluster.coordination.CoordinationMetadata) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateUpdateTask(org.elasticsearch.cluster.ClusterStateUpdateTask) Settings(org.elasticsearch.common.settings.Settings) VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ClusterName(org.elasticsearch.cluster.ClusterName) ClusterStateObserver(org.elasticsearch.cluster.ClusterStateObserver) AfterClass(org.junit.AfterClass) Set(java.util.Set) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) CountDownLatch(java.util.concurrent.CountDownLatch) Version(org.elasticsearch.Version) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) TimeValue(io.crate.common.unit.TimeValue) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) DiscoveryNodeRole(org.elasticsearch.cluster.node.DiscoveryNodeRole) TransportException(org.elasticsearch.transport.TransportException) BeforeClass(org.junit.BeforeClass) ClusterService(org.elasticsearch.cluster.service.ClusterService) ClusterState.builder(org.elasticsearch.cluster.ClusterState.builder) Names(org.elasticsearch.threadpool.ThreadPool.Names) HashSet(java.util.HashSet) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) Metadata(org.elasticsearch.cluster.metadata.Metadata) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING(org.elasticsearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction.MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) SetOnce(org.apache.lucene.util.SetOnce) Collections.emptySet(java.util.Collections.emptySet) MockTransport(org.elasticsearch.test.transport.MockTransport) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) StreamInput(org.elasticsearch.common.io.stream.StreamInput) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) ClusterServiceUtils.setState(org.elasticsearch.test.ClusterServiceUtils.setState) ClusterState(org.elasticsearch.cluster.ClusterState) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 7 with CoordinationMetadata

use of org.elasticsearch.cluster.coordination.CoordinationMetadata in project crate by crate.

the class TransportClearVotingConfigExclusionsActionTests method setupForTest.

@Before
public void setupForTest() {
    final MockTransport transport = new MockTransport();
    transportService = transport.createTransportService(Settings.EMPTY, threadPool, boundTransportAddress -> localNode, null);
    new TransportClearVotingConfigExclusionsAction(transportService, clusterService, threadPool, // registers action
    new IndexNameExpressionResolver());
    transportService.start();
    transportService.acceptIncomingRequests();
    final ClusterState.Builder builder = builder(new ClusterName("cluster")).nodes(new Builder().add(localNode).add(otherNode1).add(otherNode2).localNodeId(localNode.getId()).masterNodeId(localNode.getId()));
    builder.metadata(Metadata.builder().coordinationMetadata(CoordinationMetadata.builder().addVotingConfigExclusion(otherNode1Exclusion).addVotingConfigExclusion(otherNode2Exclusion).build()));
    setState(clusterService, builder);
}
Also used : Builder(org.elasticsearch.cluster.node.DiscoveryNodes.Builder) BeforeClass(org.junit.BeforeClass) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) ClusterService(org.elasticsearch.cluster.service.ClusterService) ClusterState.builder(org.elasticsearch.cluster.ClusterState.builder) CoordinationMetadata(org.elasticsearch.cluster.coordination.CoordinationMetadata) Names(org.elasticsearch.threadpool.ThreadPool.Names) ElasticsearchTimeoutException(org.elasticsearch.ElasticsearchTimeoutException) ClusterState(org.elasticsearch.cluster.ClusterState) Metadata(org.elasticsearch.cluster.metadata.Metadata) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) VotingConfigExclusion(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ClusterName(org.elasticsearch.cluster.ClusterName) ESTestCase(org.elasticsearch.test.ESTestCase) TransportService(org.elasticsearch.transport.TransportService) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) AfterClass(org.junit.AfterClass) Matchers.empty(org.hamcrest.Matchers.empty) SetOnce(org.apache.lucene.util.SetOnce) Collections.emptySet(java.util.Collections.emptySet) MockTransport(org.elasticsearch.test.transport.MockTransport) IOException(java.io.IOException) Matchers.startsWith(org.hamcrest.Matchers.startsWith) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) CountDownLatch(java.util.concurrent.CountDownLatch) Version(org.elasticsearch.Version) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) StreamInput(org.elasticsearch.common.io.stream.StreamInput) TimeValue(io.crate.common.unit.TimeValue) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) TransportException(org.elasticsearch.transport.TransportException) ClusterServiceUtils.setState(org.elasticsearch.test.ClusterServiceUtils.setState) ClusterState(org.elasticsearch.cluster.ClusterState) MockTransport(org.elasticsearch.test.transport.MockTransport) Builder(org.elasticsearch.cluster.node.DiscoveryNodes.Builder) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Before(org.junit.Before)

Example 8 with CoordinationMetadata

use of org.elasticsearch.cluster.coordination.CoordinationMetadata in project crate by crate.

the class GatewayMetaStatePersistedStateTests method testSetLastAcceptedState.

public void testSetLastAcceptedState() throws IOException {
    CoordinationState.PersistedState gateway = null;
    try {
        gateway = newGatewayPersistedState();
        final long term = randomNonNegativeLong();
        for (int i = 0; i < randomIntBetween(1, 5); i++) {
            final long version = randomNonNegativeLong();
            final String indexName = randomAlphaOfLength(10);
            final IndexMetadata indexMetadata = createIndexMetadata(indexName, randomIntBetween(1, 5), randomNonNegativeLong());
            final Metadata metadata = Metadata.builder().persistentSettings(Settings.builder().put(randomAlphaOfLength(10), randomAlphaOfLength(10)).build()).coordinationMetadata(createCoordinationMetadata(term)).put(indexMetadata, false).build();
            ClusterState state = createClusterState(version, metadata);
            gateway.setLastAcceptedState(state);
            gateway = maybeNew(gateway);
            ClusterState lastAcceptedState = gateway.getLastAcceptedState();
            assertClusterStateEqual(state, lastAcceptedState);
        }
    } finally {
        IOUtils.close(gateway);
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) CoordinationMetadata(org.elasticsearch.cluster.coordination.CoordinationMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) CoordinationState(org.elasticsearch.cluster.coordination.CoordinationState) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata)

Example 9 with CoordinationMetadata

use of org.elasticsearch.cluster.coordination.CoordinationMetadata in project crate by crate.

the class GatewayMetaStatePersistedStateTests method testMarkAcceptedConfigAsCommitted.

public void testMarkAcceptedConfigAsCommitted() throws IOException {
    CoordinationState.PersistedState gateway = null;
    try {
        gateway = newGatewayPersistedState();
        // generate random coordinationMetadata with different lastAcceptedConfiguration and lastCommittedConfiguration
        CoordinationMetadata coordinationMetadata;
        do {
            coordinationMetadata = createCoordinationMetadata(randomNonNegativeLong());
        } while (coordinationMetadata.getLastAcceptedConfiguration().equals(coordinationMetadata.getLastCommittedConfiguration()));
        ClusterState state = createClusterState(randomNonNegativeLong(), Metadata.builder().coordinationMetadata(coordinationMetadata).clusterUUID(randomAlphaOfLength(10)).build());
        gateway.setLastAcceptedState(state);
        gateway = maybeNew(gateway);
        assertThat(gateway.getLastAcceptedState().getLastAcceptedConfiguration(), not(equalTo(gateway.getLastAcceptedState().getLastCommittedConfiguration())));
        gateway.markLastAcceptedStateAsCommitted();
        CoordinationMetadata expectedCoordinationMetadata = CoordinationMetadata.builder(coordinationMetadata).lastCommittedConfiguration(coordinationMetadata.getLastAcceptedConfiguration()).build();
        ClusterState expectedClusterState = ClusterState.builder(state).metadata(Metadata.builder().coordinationMetadata(expectedCoordinationMetadata).clusterUUID(state.metadata().clusterUUID()).clusterUUIDCommitted(true).build()).build();
        gateway = maybeNew(gateway);
        assertClusterStateEqual(expectedClusterState, gateway.getLastAcceptedState());
        gateway.markLastAcceptedStateAsCommitted();
        gateway = maybeNew(gateway);
        assertClusterStateEqual(expectedClusterState, gateway.getLastAcceptedState());
    } finally {
        IOUtils.close(gateway);
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) CoordinationMetadata(org.elasticsearch.cluster.coordination.CoordinationMetadata) CoordinationState(org.elasticsearch.cluster.coordination.CoordinationState)

Example 10 with CoordinationMetadata

use of org.elasticsearch.cluster.coordination.CoordinationMetadata in project crate by crate.

the class GatewayMetaStatePersistedStateTests method testStatePersistenceWithIOIssues.

public void testStatePersistenceWithIOIssues() throws IOException {
    final AtomicReference<Double> ioExceptionRate = new AtomicReference<>(0.01d);
    final List<MockDirectoryWrapper> list = new ArrayList<>();
    final PersistedClusterStateService persistedClusterStateService = new PersistedClusterStateService(nodeEnvironment, xContentRegistry(), BigArrays.NON_RECYCLING_INSTANCE, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L) {

        @Override
        Directory createDirectory(Path path) {
            final MockDirectoryWrapper wrapper = newMockFSDirectory(path);
            wrapper.setAllowRandomFileNotFoundException(randomBoolean());
            wrapper.setRandomIOExceptionRate(ioExceptionRate.get());
            wrapper.setRandomIOExceptionRateOnOpen(ioExceptionRate.get());
            list.add(wrapper);
            return wrapper;
        }
    };
    ClusterState state = createClusterState(randomNonNegativeLong(), Metadata.builder().clusterUUID(randomAlphaOfLength(10)).build());
    long currentTerm = 42L;
    try (GatewayMetaState.LucenePersistedState persistedState = new GatewayMetaState.LucenePersistedState(persistedClusterStateService, currentTerm, state)) {
        try {
            if (randomBoolean()) {
                final ClusterState newState = createClusterState(randomNonNegativeLong(), Metadata.builder().clusterUUID(randomAlphaOfLength(10)).build());
                persistedState.setLastAcceptedState(newState);
                state = newState;
            } else {
                final long newTerm = currentTerm + 1;
                persistedState.setCurrentTerm(newTerm);
                currentTerm = newTerm;
            }
        } catch (IOError | Exception e) {
            assertNotNull(ExceptionsHelper.unwrap(e, IOException.class));
        }
        ioExceptionRate.set(0.0d);
        for (MockDirectoryWrapper wrapper : list) {
            wrapper.setRandomIOExceptionRate(ioExceptionRate.get());
            wrapper.setRandomIOExceptionRateOnOpen(ioExceptionRate.get());
        }
        for (int i = 0; i < randomIntBetween(1, 5); i++) {
            if (randomBoolean()) {
                final long version = randomNonNegativeLong();
                final String indexName = randomAlphaOfLength(10);
                final IndexMetadata indexMetadata = createIndexMetadata(indexName, randomIntBetween(1, 5), randomNonNegativeLong());
                final Metadata metadata = Metadata.builder().persistentSettings(Settings.builder().put(randomAlphaOfLength(10), randomAlphaOfLength(10)).build()).coordinationMetadata(createCoordinationMetadata(1L)).put(indexMetadata, false).build();
                state = createClusterState(version, metadata);
                persistedState.setLastAcceptedState(state);
            } else {
                currentTerm += 1;
                persistedState.setCurrentTerm(currentTerm);
            }
        }
        assertEquals(state, persistedState.getLastAcceptedState());
        assertEquals(currentTerm, persistedState.getCurrentTerm());
    } catch (IOError | Exception e) {
        if (ioExceptionRate.get() == 0.0d) {
            throw e;
        }
        assertNotNull(ExceptionsHelper.unwrap(e, IOException.class));
        return;
    }
    nodeEnvironment.close();
    // verify that the freshest state was rewritten to each data path
    for (Path path : nodeEnvironment.nodeDataPaths()) {
        Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath()).put(Environment.PATH_DATA_SETTING.getKey(), path.toString()).build();
        try (NodeEnvironment nodeEnvironment = new NodeEnvironment(settings, TestEnvironment.newEnvironment(settings))) {
            final PersistedClusterStateService newPersistedClusterStateService = new PersistedClusterStateService(nodeEnvironment, xContentRegistry(), BigArrays.NON_RECYCLING_INSTANCE, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L);
            final PersistedClusterStateService.OnDiskState onDiskState = newPersistedClusterStateService.loadBestOnDiskState();
            assertFalse(onDiskState.empty());
            assertThat(onDiskState.currentTerm, equalTo(currentTerm));
            assertClusterStateEqual(state, ClusterState.builder(ClusterName.DEFAULT).version(onDiskState.lastAcceptedVersion).metadata(onDiskState.metadata).build());
        }
    }
}
Also used : MockDirectoryWrapper(org.apache.lucene.store.MockDirectoryWrapper) Path(java.nio.file.Path) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) ArrayList(java.util.ArrayList) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) CoordinationMetadata(org.elasticsearch.cluster.coordination.CoordinationMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) IOError(java.io.IOError) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings)

Aggregations

CoordinationMetadata (org.elasticsearch.cluster.coordination.CoordinationMetadata)14 ClusterState (org.elasticsearch.cluster.ClusterState)11 Metadata (org.elasticsearch.cluster.metadata.Metadata)10 IOException (java.io.IOException)8 Settings (org.elasticsearch.common.settings.Settings)8 VotingConfigExclusion (org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion)7 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)7 TimeValue (io.crate.common.unit.TimeValue)6 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)6 Version (org.elasticsearch.Version)6 ClusterName (org.elasticsearch.cluster.ClusterName)6 Collections.emptyMap (java.util.Collections.emptyMap)5 Collections.emptySet (java.util.Collections.emptySet)5 Set (java.util.Set)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 TimeUnit (java.util.concurrent.TimeUnit)5 Consumer (java.util.function.Consumer)5 SetOnce (org.apache.lucene.util.SetOnce)5 ClusterState.builder (org.elasticsearch.cluster.ClusterState.builder)5 IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)5