Search in sources :

Example 1 with VotingConfigExclusion

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

the class TransportClearVotingConfigExclusionsAction method masterOperation.

@Override
protected void masterOperation(ClearVotingConfigExclusionsRequest request, ClusterState initialState, ActionListener<ClearVotingConfigExclusionsResponse> listener) throws Exception {
    final long startTimeMillis = threadPool.relativeTimeInMillis();
    final Predicate<ClusterState> allExclusionsRemoved = newState -> {
        for (VotingConfigExclusion tombstone : initialState.getVotingConfigExclusions()) {
            // NB checking for the existence of any node with this persistent ID, because persistent IDs are how votes are counted.
            if (newState.nodes().nodeExists(tombstone.getNodeId())) {
                return false;
            }
        }
        return true;
    };
    if (request.getWaitForRemoval() && allExclusionsRemoved.test(initialState) == false) {
        final ClusterStateObserver clusterStateObserver = new ClusterStateObserver(initialState, clusterService, request.getTimeout(), logger, threadPool.getThreadContext());
        clusterStateObserver.waitForNextChange(new Listener() {

            @Override
            public void onNewClusterState(ClusterState state) {
                submitClearVotingConfigExclusionsTask(request, startTimeMillis, listener);
            }

            @Override
            public void onClusterServiceClose() {
                listener.onFailure(new OpenSearchException("cluster service closed while waiting for removal of nodes " + initialState.getVotingConfigExclusions()));
            }

            @Override
            public void onTimeout(TimeValue timeout) {
                listener.onFailure(new OpenSearchTimeoutException("timed out waiting for removal of nodes; if nodes should not be removed, set waitForRemoval to false. " + initialState.getVotingConfigExclusions()));
            }
        }, allExclusionsRemoved);
    } else {
        submitClearVotingConfigExclusionsTask(request, startTimeMillis, listener);
    }
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) Metadata(org.opensearch.cluster.metadata.Metadata) ThreadPool(org.opensearch.threadpool.ThreadPool) Priority(org.opensearch.common.Priority) TransportMasterNodeAction(org.opensearch.action.support.master.TransportMasterNodeAction) OpenSearchException(org.opensearch.OpenSearchException) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) ClusterState(org.opensearch.cluster.ClusterState) Inject(org.opensearch.common.inject.Inject) ActionListener(org.opensearch.action.ActionListener) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) StreamInput(org.opensearch.common.io.stream.StreamInput) TimeValue(org.opensearch.common.unit.TimeValue) Predicate(java.util.function.Predicate) ClusterBlockLevel(org.opensearch.cluster.block.ClusterBlockLevel) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) IOException(java.io.IOException) Listener(org.opensearch.cluster.ClusterStateObserver.Listener) TransportService(org.opensearch.transport.TransportService) ActionFilters(org.opensearch.action.support.ActionFilters) Logger(org.apache.logging.log4j.Logger) ClusterStateUpdateTask(org.opensearch.cluster.ClusterStateUpdateTask) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) ClusterService(org.opensearch.cluster.service.ClusterService) LogManager(org.apache.logging.log4j.LogManager) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Names(org.opensearch.threadpool.ThreadPool.Names) VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) ClusterState(org.opensearch.cluster.ClusterState) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) ActionListener(org.opensearch.action.ActionListener) Listener(org.opensearch.cluster.ClusterStateObserver.Listener) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) OpenSearchException(org.opensearch.OpenSearchException) TimeValue(org.opensearch.common.unit.TimeValue)

Example 2 with VotingConfigExclusion

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

the class Coordinator method validVotingConfigExclusionState.

/*
    * Valid Voting Configuration Exclusion state criteria:
    * 1. Every voting config exclusion with an ID of _absent_ should not match any nodes currently in the cluster by name
    * 2. Every voting config exclusion with a name of _absent_ should not match any nodes currently in the cluster by ID
     */
static boolean validVotingConfigExclusionState(ClusterState clusterState) {
    Set<VotingConfigExclusion> votingConfigExclusions = clusterState.getVotingConfigExclusions();
    Set<String> nodeNamesWithAbsentId = votingConfigExclusions.stream().filter(e -> e.getNodeId().equals(VotingConfigExclusion.MISSING_VALUE_MARKER)).map(VotingConfigExclusion::getNodeName).collect(Collectors.toSet());
    Set<String> nodeIdsWithAbsentName = votingConfigExclusions.stream().filter(e -> e.getNodeName().equals(VotingConfigExclusion.MISSING_VALUE_MARKER)).map(VotingConfigExclusion::getNodeId).collect(Collectors.toSet());
    for (DiscoveryNode node : clusterState.getNodes()) {
        if (node.isMasterNode() && (nodeIdsWithAbsentName.contains(node.getId()) || nodeNamesWithAbsentId.contains(node.getName()))) {
            return false;
        }
    }
    return true;
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode)

Example 3 with VotingConfigExclusion

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

the class ClusterStateDiffIT method randomCoordinationMetadata.

private ClusterState.Builder randomCoordinationMetadata(ClusterState clusterState) {
    ClusterState.Builder builder = ClusterState.builder(clusterState);
    CoordinationMetadata.Builder metaBuilder = CoordinationMetadata.builder(clusterState.coordinationMetadata());
    metaBuilder.term(randomNonNegativeLong());
    if (randomBoolean()) {
        metaBuilder.lastCommittedConfiguration(new CoordinationMetadata.VotingConfiguration(Sets.newHashSet(generateRandomStringArray(10, 10, false))));
    }
    if (randomBoolean()) {
        metaBuilder.lastAcceptedConfiguration(new CoordinationMetadata.VotingConfiguration(Sets.newHashSet(generateRandomStringArray(10, 10, false))));
    }
    if (randomBoolean()) {
        metaBuilder.addVotingConfigExclusion(new VotingConfigExclusion(randomNode("node-" + randomAlphaOfLength(10))));
    }
    return builder;
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata)

Example 4 with VotingConfigExclusion

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

the class CoordinationMetadataTests method testVotingTombstoneXContent.

public void testVotingTombstoneXContent() throws IOException {
    VotingConfigExclusion originalTombstone = new VotingConfigExclusion(randomAlphaOfLength(10), randomAlphaOfLength(10));
    final XContentBuilder builder = JsonXContent.contentBuilder();
    originalTombstone.toXContent(builder, ToXContent.EMPTY_PARAMS);
    try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) {
        final VotingConfigExclusion fromXContentTombstone = VotingConfigExclusion.fromXContent(parser);
        assertThat(originalTombstone, equalTo(fromXContentTombstone));
    }
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 5 with VotingConfigExclusion

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

the class CoordinationMetadataTests method testVotingTombstoneSerializationEqualsHashCode.

public void testVotingTombstoneSerializationEqualsHashCode() {
    VotingConfigExclusion tombstone = new VotingConfigExclusion(randomAlphaOfLength(10), randomAlphaOfLength(10));
    // Note: the explicit cast of the CopyFunction is needed for some IDE (specifically Eclipse 4.8.0) to infer the right type
    EqualsHashCodeTestUtils.checkEqualsAndHashCode(tombstone, (CopyFunction<VotingConfigExclusion>) orig -> OpenSearchTestCase.copyWriteable(orig, new NamedWriteableRegistry(Collections.emptyList()), VotingConfigExclusion::new), orig -> randomlyChangeVotingTombstone(orig));
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) VotingConfiguration(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) BytesReference(org.opensearch.common.bytes.BytesReference) ToXContent(org.opensearch.common.xcontent.ToXContent) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) IOException(java.io.IOException) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser) HashSet(java.util.HashSet) Sets(org.opensearch.common.util.set.Sets) Matchers.equalTo(org.hamcrest.Matchers.equalTo) JsonXContent(org.opensearch.common.xcontent.json.JsonXContent) EqualsHashCodeTestUtils(org.opensearch.test.EqualsHashCodeTestUtils) CopyFunction(org.opensearch.test.EqualsHashCodeTestUtils.CopyFunction) Collections(java.util.Collections) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry)

Aggregations

VotingConfigExclusion (org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion)19 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)13 ClusterState (org.opensearch.cluster.ClusterState)11 ClusterName (org.opensearch.cluster.ClusterName)9 CoordinationMetadata (org.opensearch.cluster.coordination.CoordinationMetadata)8 Builder (org.opensearch.cluster.node.DiscoveryNodes.Builder)8 IOException (java.io.IOException)7 Metadata (org.opensearch.cluster.metadata.Metadata)7 HashSet (java.util.HashSet)6 Set (java.util.Set)6 ClusterStateUpdateTask (org.opensearch.cluster.ClusterStateUpdateTask)6 TimeValue (org.opensearch.common.unit.TimeValue)6 BeforeClass (org.junit.BeforeClass)5 OpenSearchTimeoutException (org.opensearch.OpenSearchTimeoutException)5 ClusterStateObserver (org.opensearch.cluster.ClusterStateObserver)5 Listener (org.opensearch.cluster.ClusterStateObserver.Listener)5 VotingConfiguration (org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration)5 TestThreadPool (org.opensearch.threadpool.TestThreadPool)5 Names (org.opensearch.threadpool.ThreadPool.Names)5 TransportService (org.opensearch.transport.TransportService)5