-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Atomically update cluster state with decommission status and correspo…
…nding action (#5093) * Atomically update the cluster state with decommission status and its corresponding action in the same execute call Signed-off-by: Rishab Nahata <rnnahata@amazon.com>
- Loading branch information
Showing
13 changed files
with
668 additions
and
495 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
.../java/org/opensearch/action/admin/cluster/configuration/VotingConfigExclusionsHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.admin.cluster.configuration; | ||
|
||
import org.opensearch.cluster.ClusterState; | ||
import org.opensearch.cluster.coordination.CoordinationMetadata; | ||
import org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion; | ||
import org.opensearch.cluster.metadata.Metadata; | ||
|
||
import java.util.Set; | ||
|
||
import static org.opensearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction.MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING; | ||
|
||
/** | ||
* Static helper utilities for voting config exclusions cluster state updates | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class VotingConfigExclusionsHelper { | ||
|
||
/** | ||
* Static helper to update current state with given resolved exclusions | ||
* | ||
* @param currentState current cluster state | ||
* @param resolvedExclusions resolved exclusions from the request | ||
* @param finalMaxVotingConfigExclusions max exclusions that be added | ||
* @return newly formed cluster state | ||
*/ | ||
public static ClusterState addExclusionAndGetState( | ||
ClusterState currentState, | ||
Set<VotingConfigExclusion> resolvedExclusions, | ||
int finalMaxVotingConfigExclusions | ||
) { | ||
final CoordinationMetadata.Builder builder = CoordinationMetadata.builder(currentState.coordinationMetadata()); | ||
resolvedExclusions.forEach(builder::addVotingConfigExclusion); | ||
final Metadata newMetadata = Metadata.builder(currentState.metadata()).coordinationMetadata(builder.build()).build(); | ||
final ClusterState newState = ClusterState.builder(currentState).metadata(newMetadata).build(); | ||
assert newState.getVotingConfigExclusions().size() <= finalMaxVotingConfigExclusions; | ||
return newState; | ||
} | ||
|
||
/** | ||
* Resolves the exclusion from the request and throws IAE if no nodes matched or maximum exceeded | ||
* | ||
* @param request AddVotingConfigExclusionsRequest request | ||
* @param state current cluster state | ||
* @param maxVotingConfigExclusions max number of exclusion acceptable | ||
* @return set of VotingConfigExclusion | ||
*/ | ||
public static Set<VotingConfigExclusion> resolveVotingConfigExclusionsAndCheckMaximum( | ||
AddVotingConfigExclusionsRequest request, | ||
ClusterState state, | ||
int maxVotingConfigExclusions | ||
) { | ||
return request.resolveVotingConfigExclusionsAndCheckMaximum( | ||
state, | ||
maxVotingConfigExclusions, | ||
MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING.getKey() | ||
); | ||
} | ||
|
||
/** | ||
* Clears Voting config exclusion from the given cluster state | ||
* | ||
* @param currentState current cluster state | ||
* @return newly formed cluster state after clearing voting config exclusions | ||
*/ | ||
public static ClusterState clearExclusionsAndGetState(ClusterState currentState) { | ||
final CoordinationMetadata newCoordinationMetadata = CoordinationMetadata.builder(currentState.coordinationMetadata()) | ||
.clearVotingConfigExclusions() | ||
.build(); | ||
final Metadata newMetadata = Metadata.builder(currentState.metadata()).coordinationMetadata(newCoordinationMetadata).build(); | ||
return ClusterState.builder(currentState).metadata(newMetadata).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.