From 29a1d046fda22b0dd0df064b4a4113eceaafa629 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Sat, 5 Nov 2022 18:58:40 +0530 Subject: [PATCH] Fix spotless check Signed-off-by: Rishab Nahata --- .../AddVotingConfigExclusionsHelper.java | 6 ++-- ...nsportAddVotingConfigExclusionsAction.java | 2 -- .../decommission/DecommissionHelper.java | 15 +++++++--- .../decommission/DecommissionService.java | 30 ++++++++++++++----- 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/configuration/AddVotingConfigExclusionsHelper.java b/server/src/main/java/org/opensearch/action/admin/cluster/configuration/AddVotingConfigExclusionsHelper.java index 616c030e622d6..b7366066ed65f 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/configuration/AddVotingConfigExclusionsHelper.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/configuration/AddVotingConfigExclusionsHelper.java @@ -19,7 +19,7 @@ public class AddVotingConfigExclusionsHelper { - public static ClusterState updateExclusionAndGetState( + public static ClusterState updateExclusionAndGetState( ClusterState currentState, Set resolvedExclusions, int finalMaxVotingConfigExclusions @@ -32,8 +32,8 @@ public static ClusterState updateExclusionAndGetState( return newState; } - // throws IAE if no nodes matched or maximum exceeded - public static Set resolveVotingConfigExclusionsAndCheckMaximum( + // throws IAE if no nodes matched or maximum exceeded + public static Set resolveVotingConfigExclusionsAndCheckMaximum( AddVotingConfigExclusionsRequest request, ClusterState state, int maxVotingConfigExclusions diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsAction.java index 983ca2104f4ab..6ddd95bdc3791 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsAction.java @@ -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; diff --git a/server/src/main/java/org/opensearch/cluster/decommission/DecommissionHelper.java b/server/src/main/java/org/opensearch/cluster/decommission/DecommissionHelper.java index a4046ef1001a7..e8143aeb564fc 100644 --- a/server/src/main/java/org/opensearch/cluster/decommission/DecommissionHelper.java +++ b/server/src/main/java/org/opensearch/cluster/decommission/DecommissionHelper.java @@ -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)) @@ -47,7 +50,11 @@ static ClusterState addVotingConfigExclusionsForToBeDecommissionedClusterManager Strings.EMPTY_ARRAY, decommissionActionTimeout ); - Set resolvedExclusion = resolveVotingConfigExclusionsAndCheckMaximum(request, currentState, maxVotingConfigExclusions); + Set resolvedExclusion = resolveVotingConfigExclusionsAndCheckMaximum( + request, + currentState, + maxVotingConfigExclusions + ); return updateExclusionAndGetState(currentState, resolvedExclusion, maxVotingConfigExclusions); } @@ -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; } } diff --git a/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java b/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java index 5ff1b539c7634..8e1a016ae6ab3 100644 --- a/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java +++ b/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java @@ -153,10 +153,12 @@ public ClusterState execute(ClusterState currentState) { // ensure attribute is weighed away ensureToBeDecommissionedAttributeWeighedAway(currentState, decommissionAttribute); - ClusterState newState = registerDecommissionAttributeInClusterState(currentState, decommissionAttribute); + ClusterState newState = registerDecommissionAttributeInClusterState(currentState, decommissionAttribute); Set clusterManagerNodesToBeDecommissioned = filterNodesWithDecommissionAttribute( - currentState, decommissionAttribute, true + currentState, + decommissionAttribute, + true ); logger.info( "resolved cluster manager eligible nodes [{}] that should be added to voting config exclusion", @@ -164,8 +166,16 @@ public ClusterState execute(ClusterState currentState) { ); // 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; } @@ -202,7 +212,8 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS final Set 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 }; @@ -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, " @@ -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 decommissionedNodes = filterNodesWithDecommissionAttribute(