Skip to content

Commit

Permalink
Fix spotless check
Browse files Browse the repository at this point in the history
Signed-off-by: Rishab Nahata <rnnahata@amazon.com>
  • Loading branch information
imRishN committed Nov 5, 2022
1 parent 36d981d commit 29a1d04
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public class AddVotingConfigExclusionsHelper {

public static ClusterState updateExclusionAndGetState(
public static ClusterState updateExclusionAndGetState(
ClusterState currentState,
Set<VotingConfigExclusion> resolvedExclusions,
int finalMaxVotingConfigExclusions
Expand All @@ -32,8 +32,8 @@ public static ClusterState updateExclusionAndGetState(
return newState;
}

// throws IAE if no nodes matched or maximum exceeded
public static Set<VotingConfigExclusion> resolveVotingConfigExclusionsAndCheckMaximum(
// throws IAE if no nodes matched or maximum exceeded
public static Set<VotingConfigExclusion> resolveVotingConfigExclusionsAndCheckMaximum(
AddVotingConfigExclusionsRequest request,
ClusterState state,
int maxVotingConfigExclusions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@
import org.opensearch.cluster.ClusterStateUpdateTask;
import org.opensearch.cluster.block.ClusterBlockException;
import org.opensearch.cluster.block.ClusterBlockLevel;
import org.opensearch.cluster.coordination.CoordinationMetadata;
import org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion;
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
import org.opensearch.cluster.metadata.Metadata;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.Priority;
import org.opensearch.common.inject.Inject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
*/
public class DecommissionHelper {

static ClusterState registerDecommissionAttributeInClusterState(ClusterState currentState, DecommissionAttribute decommissionAttribute) {
static ClusterState registerDecommissionAttributeInClusterState(
ClusterState currentState,
DecommissionAttribute decommissionAttribute
) {
DecommissionAttributeMetadata decommissionAttributeMetadata = new DecommissionAttributeMetadata(decommissionAttribute);
return ClusterState.builder(currentState)
.metadata(Metadata.builder(currentState.metadata()).decommissionAttributeMetadata(decommissionAttributeMetadata))
Expand All @@ -47,7 +50,11 @@ static ClusterState addVotingConfigExclusionsForToBeDecommissionedClusterManager
Strings.EMPTY_ARRAY,
decommissionActionTimeout
);
Set<VotingConfigExclusion> resolvedExclusion = resolveVotingConfigExclusionsAndCheckMaximum(request, currentState, maxVotingConfigExclusions);
Set<VotingConfigExclusion> resolvedExclusion = resolveVotingConfigExclusionsAndCheckMaximum(
request,
currentState,
maxVotingConfigExclusions
);
return updateExclusionAndGetState(currentState, resolvedExclusion, maxVotingConfigExclusions);
}

Expand Down Expand Up @@ -97,8 +104,8 @@ public static boolean nodeCommissioned(DiscoveryNode discoveryNode, Metadata met
if (decommissionAttribute != null && status != null) {
if (nodeHasDecommissionedAttribute(discoveryNode, decommissionAttribute)
&& (status.equals(DecommissionStatus.IN_PROGRESS)
|| status.equals(DecommissionStatus.SUCCESSFUL)
|| status.equals(DecommissionStatus.DRAINING))) {
|| status.equals(DecommissionStatus.SUCCESSFUL)
|| status.equals(DecommissionStatus.DRAINING))) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,29 @@ public ClusterState execute(ClusterState currentState) {
// ensure attribute is weighed away
ensureToBeDecommissionedAttributeWeighedAway(currentState, decommissionAttribute);

ClusterState newState = registerDecommissionAttributeInClusterState(currentState, decommissionAttribute);
ClusterState newState = registerDecommissionAttributeInClusterState(currentState, decommissionAttribute);

Set<DiscoveryNode> clusterManagerNodesToBeDecommissioned = filterNodesWithDecommissionAttribute(
currentState, decommissionAttribute, true
currentState,
decommissionAttribute,
true
);
logger.info(
"resolved cluster manager eligible nodes [{}] that should be added to voting config exclusion",
clusterManagerNodesToBeDecommissioned.toString()
);
// add all 'to-be-decommissioned' cluster manager eligible nodes to voting config exclusion
nodeIdsToBeExcluded = clusterManagerNodesToBeDecommissioned.stream().map(DiscoveryNode::getId).collect(Collectors.toSet());
newState = addVotingConfigExclusionsForToBeDecommissionedClusterManagerNodes(newState, nodeIdsToBeExcluded, TimeValue.timeValueSeconds(30), maxVotingConfigExclusions);
logger.debug("registering decommission metadata [{}] to execute action", newState.metadata().decommissionAttributeMetadata().toString());
newState = addVotingConfigExclusionsForToBeDecommissionedClusterManagerNodes(
newState,
nodeIdsToBeExcluded,
TimeValue.timeValueSeconds(30),
maxVotingConfigExclusions
);
logger.debug(
"registering decommission metadata [{}] to execute action",
newState.metadata().decommissionAttributeMetadata().toString()
);
return newState;
}

Expand Down Expand Up @@ -202,7 +212,8 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
final Set<String> votingConfigNodeIds = clusterState.getLastCommittedConfiguration().getNodeIds();
return nodeIdsToBeExcluded.stream().noneMatch(votingConfigNodeIds::contains) // nodes are excluded from voting config
&& clusterState.nodes().getClusterManagerNodeId() != null // a master is elected
&& nodeIdsToBeExcluded.contains(clusterState.nodes().getClusterManagerNodeId()) == false; // none of excluded node is elected master
&& nodeIdsToBeExcluded.contains(clusterState.nodes().getClusterManagerNodeId()) == false; // none of excluded node
// is elected master

};

Expand All @@ -227,13 +238,15 @@ public void onNewClusterState(ClusterState state) {
} else {
logger.info("will attempt to fail decommissioned nodes as local node is eligible to process the request");
// we are good here to send the response now as the request is processed by an eligible active leader
// and to-be-decommissioned cluster manager is no more part of Voting Configuration and no more to-be-decommission
// and to-be-decommissioned cluster manager is no more part of Voting Configuration and no more
// to-be-decommission
// nodes can be part of Voting Config
listener.onResponse(new DecommissionResponse(true));
drainNodesWithDecommissionedAttribute(decommissionRequest);
}
} else {
// explicitly calling listener.onFailure with NotClusterManagerException as the local node is not the cluster manager
// explicitly calling listener.onFailure with NotClusterManagerException as the local node is not the cluster
// manager
// this will ensures that request is retried until cluster manager times out
logger.info(
"local node is not eligible to process the request, "
Expand Down Expand Up @@ -286,7 +299,8 @@ public void onTimeout(TimeValue timeout) {
});
}

// TODO - after registering the new status check if any node which is not excluded still present in decommissioned zone. If yes, start the action again (retry)
// TODO - after registering the new status check if any node which is not excluded still present in decommissioned zone. If yes, start
// the action again (retry)
void drainNodesWithDecommissionedAttribute(DecommissionRequest decommissionRequest) {
ClusterState state = clusterService.getClusterApplierService().state();
Set<DiscoveryNode> decommissionedNodes = filterNodesWithDecommissionAttribute(
Expand Down

0 comments on commit 29a1d04

Please sign in to comment.