Search in sources :

Example 1 with CoordinationMetadata

use of org.opensearch.cluster.coordination.CoordinationMetadata in project OpenSearch by opensearch-project.

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("], av[").append(indexMetadata.getAliasesVersion()).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 : Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata)

Example 2 with CoordinationMetadata

use of org.opensearch.cluster.coordination.CoordinationMetadata in project OpenSearch by opensearch-project.

the class TransportAddVotingConfigExclusionsActionTests method testReturnsErrorIfMaximumExclusionCountExceeded.

public void testReturnsErrorIfMaximumExclusionCountExceeded() throws InterruptedException {
    final Metadata.Builder metadataBuilder = Metadata.builder(clusterService.state().metadata());
    CoordinationMetadata.Builder coordinationMetadataBuilder = CoordinationMetadata.builder(clusterService.state().coordinationMetadata()).addVotingConfigExclusion(localNodeExclusion);
    final int actualMaximum;
    if (randomBoolean()) {
        actualMaximum = staticMaximum;
    } else {
        actualMaximum = between(2, 15);
        clusterSettings.applySettings(Settings.builder().put(clusterService.state().metadata().persistentSettings()).put(MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING.getKey(), actualMaximum).build());
    }
    for (int i = 2; i < actualMaximum; i++) {
        coordinationMetadataBuilder.addVotingConfigExclusion(new VotingConfigExclusion(randomAlphaOfLength(10), randomAlphaOfLength(10)));
    }
    final int existingCount, newCount;
    if (randomBoolean()) {
        coordinationMetadataBuilder.addVotingConfigExclusion(otherNode1Exclusion);
        existingCount = actualMaximum;
        newCount = 1;
    } else {
        existingCount = actualMaximum - 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, makeRequestWithNodeDescriptions("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 [" + actualMaximum + "] set by [cluster.max_voting_config_exclusions]"));
    assertWarnings(AddVotingConfigExclusionsRequest.DEPRECATION_MESSAGE);
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) Metadata(org.opensearch.cluster.metadata.Metadata) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) ClusterServiceUtils.setState(org.opensearch.test.ClusterServiceUtils.setState) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) Strings(org.opensearch.common.Strings) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Collections.singleton(java.util.Collections.singleton) AfterClass(org.junit.AfterClass) TimeValue(org.opensearch.common.unit.TimeValue) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) TransportService(org.opensearch.transport.TransportService) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ActionFilters(org.opensearch.action.support.ActionFilters) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterStateUpdateTask(org.opensearch.cluster.ClusterStateUpdateTask) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder) TransportException(org.opensearch.transport.TransportException) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Names(org.opensearch.threadpool.ThreadPool.Names) BeforeClass(org.junit.BeforeClass) ThreadPool(org.opensearch.threadpool.ThreadPool) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING(org.opensearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction.MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) MockTransport(org.opensearch.test.transport.MockTransport) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) Collections.emptyMap(java.util.Collections.emptyMap) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) SetOnce(org.apache.lucene.util.SetOnce) VotingConfiguration(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) Collections.emptySet(java.util.Collections.emptySet) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) IOException(java.io.IOException) ClusterState.builder(org.opensearch.cluster.ClusterState.builder) Listener(org.opensearch.cluster.ClusterStateObserver.Listener) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ClusterService(org.opensearch.cluster.service.ClusterService) ClusterName(org.opensearch.cluster.ClusterName) ClusterState(org.opensearch.cluster.ClusterState) SetOnce(org.apache.lucene.util.SetOnce) Metadata(org.opensearch.cluster.metadata.Metadata) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) CountDownLatch(java.util.concurrent.CountDownLatch) TransportException(org.opensearch.transport.TransportException)

Example 3 with CoordinationMetadata

use of org.opensearch.cluster.coordination.CoordinationMetadata in project OpenSearch by opensearch-project.

the class TransportAddVotingConfigExclusionsActionTests method testExcludeByNodeIdSucceedsEvenIfAllExclusionsAlreadyAdded.

public void testExcludeByNodeIdSucceedsEvenIfAllExclusionsAlreadyAdded() 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(Strings.EMPTY_ARRAY, new String[] { "other1" }, Strings.EMPTY_ARRAY, TimeValue.timeValueSeconds(30)), expectSuccess(r -> {
        assertNotNull(r);
        countDownLatch.countDown();
    }));
    assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
    assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(), contains(otherNode1Exclusion));
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) Metadata(org.opensearch.cluster.metadata.Metadata) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) ClusterServiceUtils.setState(org.opensearch.test.ClusterServiceUtils.setState) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) Strings(org.opensearch.common.Strings) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Collections.singleton(java.util.Collections.singleton) AfterClass(org.junit.AfterClass) TimeValue(org.opensearch.common.unit.TimeValue) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) TransportService(org.opensearch.transport.TransportService) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ActionFilters(org.opensearch.action.support.ActionFilters) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterStateUpdateTask(org.opensearch.cluster.ClusterStateUpdateTask) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder) TransportException(org.opensearch.transport.TransportException) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Names(org.opensearch.threadpool.ThreadPool.Names) BeforeClass(org.junit.BeforeClass) ThreadPool(org.opensearch.threadpool.ThreadPool) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING(org.opensearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction.MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) MockTransport(org.opensearch.test.transport.MockTransport) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) Collections.emptyMap(java.util.Collections.emptyMap) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) SetOnce(org.apache.lucene.util.SetOnce) VotingConfiguration(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) Collections.emptySet(java.util.Collections.emptySet) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) IOException(java.io.IOException) ClusterState.builder(org.opensearch.cluster.ClusterState.builder) Listener(org.opensearch.cluster.ClusterStateObserver.Listener) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ClusterService(org.opensearch.cluster.service.ClusterService) ClusterName(org.opensearch.cluster.ClusterName) ClusterState(org.opensearch.cluster.ClusterState) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 4 with CoordinationMetadata

use of org.opensearch.cluster.coordination.CoordinationMetadata in project OpenSearch by opensearch-project.

the class TransportAddVotingConfigExclusionsActionTests method testExcludeByNodeNameSucceedsEvenIfAllExclusionsAlreadyAdded.

public void testExcludeByNodeNameSucceedsEvenIfAllExclusionsAlreadyAdded() 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("other1"), expectSuccess(r -> {
        assertNotNull(r);
        countDownLatch.countDown();
    }));
    assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
    assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(), contains(otherNode1Exclusion));
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) Metadata(org.opensearch.cluster.metadata.Metadata) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) ClusterServiceUtils.setState(org.opensearch.test.ClusterServiceUtils.setState) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) Strings(org.opensearch.common.Strings) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Collections.singleton(java.util.Collections.singleton) AfterClass(org.junit.AfterClass) TimeValue(org.opensearch.common.unit.TimeValue) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) TransportService(org.opensearch.transport.TransportService) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ActionFilters(org.opensearch.action.support.ActionFilters) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterStateUpdateTask(org.opensearch.cluster.ClusterStateUpdateTask) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder) TransportException(org.opensearch.transport.TransportException) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Names(org.opensearch.threadpool.ThreadPool.Names) BeforeClass(org.junit.BeforeClass) ThreadPool(org.opensearch.threadpool.ThreadPool) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING(org.opensearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction.MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) MockTransport(org.opensearch.test.transport.MockTransport) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) Collections.emptyMap(java.util.Collections.emptyMap) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) SetOnce(org.apache.lucene.util.SetOnce) VotingConfiguration(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) Collections.emptySet(java.util.Collections.emptySet) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) IOException(java.io.IOException) ClusterState.builder(org.opensearch.cluster.ClusterState.builder) Listener(org.opensearch.cluster.ClusterStateObserver.Listener) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ClusterService(org.opensearch.cluster.service.ClusterService) ClusterName(org.opensearch.cluster.ClusterName) ClusterState(org.opensearch.cluster.ClusterState) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 5 with CoordinationMetadata

use of org.opensearch.cluster.coordination.CoordinationMetadata in project OpenSearch by opensearch-project.

the class MetadataTests method testXContentWithCoordinationMetadata.

public void testXContentWithCoordinationMetadata() throws IOException {
    CoordinationMetadata originalMeta = new CoordinationMetadata(randomNonNegativeLong(), randomVotingConfig(), randomVotingConfig(), randomVotingConfigExclusions());
    Metadata metadata = Metadata.builder().coordinationMetadata(originalMeta).build();
    final XContentBuilder builder = JsonXContent.contentBuilder();
    builder.startObject();
    Metadata.FORMAT.toXContent(builder, metadata);
    builder.endObject();
    try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) {
        final CoordinationMetadata fromXContentMeta = Metadata.fromXContent(parser).coordinationMetadata();
        assertThat(fromXContentMeta, equalTo(originalMeta));
    }
}
Also used : CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser)

Aggregations

CoordinationMetadata (org.opensearch.cluster.coordination.CoordinationMetadata)21 ClusterState (org.opensearch.cluster.ClusterState)15 Metadata (org.opensearch.cluster.metadata.Metadata)14 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)11 IOException (java.io.IOException)10 VotingConfigExclusion (org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion)10 Settings (org.opensearch.common.settings.Settings)10 ClusterName (org.opensearch.cluster.ClusterName)9 ClusterSettings (org.opensearch.common.settings.ClusterSettings)9 OpenSearchTimeoutException (org.opensearch.OpenSearchTimeoutException)8 Version (org.opensearch.Version)8 Builder (org.opensearch.cluster.node.DiscoveryNodes.Builder)8 ClusterService (org.opensearch.cluster.service.ClusterService)8 TimeValue (org.opensearch.common.unit.TimeValue)8 TestThreadPool (org.opensearch.threadpool.TestThreadPool)8 Collections.emptyMap (java.util.Collections.emptyMap)7 Collections.emptySet (java.util.Collections.emptySet)7 HashSet (java.util.HashSet)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 TimeUnit (java.util.concurrent.TimeUnit)7