Search in sources :

Example 1 with CoordinationMetadata

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

the class Metadata method readFrom.

public static Metadata readFrom(StreamInput in) throws IOException {
    Builder builder = new Builder();
    builder.version = in.readLong();
    builder.clusterUUID = in.readString();
    builder.clusterUUIDCommitted = in.readBoolean();
    builder.coordinationMetadata(new CoordinationMetadata(in));
    builder.transientSettings(readSettingsFromStream(in));
    builder.persistentSettings(readSettingsFromStream(in));
    int size = in.readVInt();
    for (int i = 0; i < size; i++) {
        builder.put(IndexMetadata.readFrom(in), false);
    }
    size = in.readVInt();
    for (int i = 0; i < size; i++) {
        builder.put(IndexTemplateMetadata.readFrom(in));
    }
    int customSize = in.readVInt();
    for (int i = 0; i < customSize; i++) {
        Custom customIndexMetadata = in.readNamedWriteable(Custom.class);
        builder.putCustom(customIndexMetadata.getWriteableName(), customIndexMetadata);
    }
    return builder.build();
}
Also used : XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) CoordinationMetadata(org.elasticsearch.cluster.coordination.CoordinationMetadata)

Example 2 with CoordinationMetadata

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

the class ClusterState method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    final String TAB = "   ";
    sb.append("cluster uuid: ").append(metadata.clusterUUID()).append(" [committed: ").append(metadata.clusterUUIDCommitted()).append("]").append("\n");
    sb.append("version: ").append(version).append("\n");
    sb.append("state uuid: ").append(stateUUID).append("\n");
    sb.append("from_diff: ").append(wasReadFromDiff).append("\n");
    sb.append("meta data version: ").append(metadata.version()).append("\n");
    sb.append(TAB).append("coordination_metadata:\n");
    sb.append(TAB).append(TAB).append("term: ").append(coordinationMetadata().term()).append("\n");
    sb.append(TAB).append(TAB).append("last_committed_config: ").append(coordinationMetadata().getLastCommittedConfiguration()).append("\n");
    sb.append(TAB).append(TAB).append("last_accepted_config: ").append(coordinationMetadata().getLastAcceptedConfiguration()).append("\n");
    sb.append(TAB).append(TAB).append("voting tombstones: ").append(coordinationMetadata().getVotingConfigExclusions()).append("\n");
    for (IndexMetadata indexMetadata : metadata) {
        sb.append(TAB).append(indexMetadata.getIndex());
        sb.append(": v[").append(indexMetadata.getVersion()).append("], mv[").append(indexMetadata.getMappingVersion()).append("], sv[").append(indexMetadata.getSettingsVersion()).append("]\n");
        for (int shard = 0; shard < indexMetadata.getNumberOfShards(); shard++) {
            sb.append(TAB).append(TAB).append(shard).append(": ");
            sb.append("p_term [").append(indexMetadata.primaryTerm(shard)).append("], ");
            sb.append("isa_ids ").append(indexMetadata.inSyncAllocationIds(shard)).append("\n");
        }
    }
    if (metadata.customs().isEmpty() == false) {
        sb.append("metadata customs:\n");
        for (final ObjectObjectCursor<String, Metadata.Custom> cursor : metadata.customs()) {
            final String type = cursor.key;
            final Metadata.Custom custom = cursor.value;
            sb.append(TAB).append(type).append(": ").append(custom);
        }
        sb.append("\n");
    }
    sb.append(blocks());
    sb.append(nodes());
    sb.append(routingTable());
    sb.append(getRoutingNodes());
    if (customs.isEmpty() == false) {
        sb.append("customs:\n");
        for (ObjectObjectCursor<String, Custom> cursor : customs) {
            final String type = cursor.key;
            final Custom custom = cursor.value;
            sb.append(TAB).append(type).append(": ").append(custom);
        }
    }
    return sb.toString();
}
Also used : IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) CoordinationMetadata(org.elasticsearch.cluster.coordination.CoordinationMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) IndexTemplateMetadata(org.elasticsearch.cluster.metadata.IndexTemplateMetadata) MappingMetadata(org.elasticsearch.cluster.metadata.MappingMetadata) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata)

Example 3 with CoordinationMetadata

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

the class TransportAddVotingConfigExclusionsActionTests method testReturnsImmediatelyIfVoteAlreadyWithdrawn.

public void testReturnsImmediatelyIfVoteAlreadyWithdrawn() throws InterruptedException {
    final ClusterState state = clusterService.state();
    setState(clusterService, builder(state).metadata(Metadata.builder(state.metadata()).coordinationMetadata(CoordinationMetadata.builder(state.coordinationMetadata()).lastCommittedConfiguration(VotingConfiguration.of(localNode, otherNode2)).lastAcceptedConfiguration(VotingConfiguration.of(localNode, otherNode2)).build())));
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    // no observer to reconfigure
    transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, new AddVotingConfigExclusionsRequest(new String[] { "other1" }, TimeValue.ZERO), 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 4 with CoordinationMetadata

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

the class TransportAddVotingConfigExclusionsActionTests method setupForTest.

@Before
public void setupForTest() {
    final MockTransport transport = new MockTransport();
    transportService = transport.createTransportService(Settings.EMPTY, threadPool, boundTransportAddress -> localNode, null);
    new TransportAddVotingConfigExclusionsAction(transportService, clusterService, threadPool, // registers action
    new IndexNameExpressionResolver());
    transportService.start();
    transportService.acceptIncomingRequests();
    final VotingConfiguration allNodesConfig = VotingConfiguration.of(localNode, otherNode1, otherNode2);
    setState(clusterService, builder(new ClusterName("cluster")).nodes(new Builder().add(localNode).add(otherNode1).add(otherNode2).add(otherDataNode).localNodeId(localNode.getId()).masterNodeId(localNode.getId())).metadata(Metadata.builder().coordinationMetadata(CoordinationMetadata.builder().lastAcceptedConfiguration(allNodesConfig).lastCommittedConfiguration(allNodesConfig).build())));
    clusterStateObserver = new ClusterStateObserver(clusterService, null, logger);
}
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) ClusterStateObserver(org.elasticsearch.cluster.ClusterStateObserver) MockTransport(org.elasticsearch.test.transport.MockTransport) Builder(org.elasticsearch.cluster.node.DiscoveryNodes.Builder) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) VotingConfiguration(org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) Before(org.junit.Before)

Example 5 with CoordinationMetadata

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

the class TransportAddVotingConfigExclusionsActionTests method testReturnsErrorIfMaximumExclusionCountExceeded.

public void testReturnsErrorIfMaximumExclusionCountExceeded() throws InterruptedException {
    final Metadata.Builder metadataBuilder = Metadata.builder(clusterService.state().metadata()).persistentSettings(Settings.builder().put(clusterService.state().metadata().persistentSettings()).put(MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING.getKey(), 2).build());
    CoordinationMetadata.Builder coordinationMetadataBuilder = CoordinationMetadata.builder(clusterService.state().coordinationMetadata()).addVotingConfigExclusion(localNodeExclusion);
    final int existingCount, newCount;
    if (randomBoolean()) {
        coordinationMetadataBuilder.addVotingConfigExclusion(otherNode1Exclusion);
        existingCount = 2;
        newCount = 1;
    } else {
        existingCount = 1;
        newCount = 2;
    }
    metadataBuilder.coordinationMetadata(coordinationMetadataBuilder.build());
    final ClusterState.Builder builder = builder(clusterService.state()).metadata(metadataBuilder);
    setState(clusterService, builder);
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    final SetOnce<TransportException> exceptionHolder = new SetOnce<>();
    transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, new AddVotingConfigExclusionsRequest(new String[] { "other*" }), expectError(e -> {
        exceptionHolder.set(e);
        countDownLatch.countDown();
    }));
    assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
    final Throwable rootCause = exceptionHolder.get().getRootCause();
    assertThat(rootCause, instanceOf(IllegalArgumentException.class));
    assertThat(rootCause.getMessage(), equalTo("add voting config exclusions request for [other*] would add [" + newCount + "] exclusions to the existing [" + existingCount + "] which would exceed the maximum of [2] set by [cluster.max_voting_config_exclusions]"));
}
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) SetOnce(org.apache.lucene.util.SetOnce) CoordinationMetadata(org.elasticsearch.cluster.coordination.CoordinationMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) CoordinationMetadata(org.elasticsearch.cluster.coordination.CoordinationMetadata) CountDownLatch(java.util.concurrent.CountDownLatch) TransportException(org.elasticsearch.transport.TransportException)

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