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);
}
}
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;
}
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;
}
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));
}
}
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));
}
Aggregations