Skip to content

Commit 2402803

Browse files
committed
Simplify getReplacementName
1 parent 238112a commit 2402803

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDecider.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import org.elasticsearch.cluster.routing.ShardRouting;
1717
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
1818

19+
import java.util.Optional;
20+
1921
public class NodeReplacementAllocationDecider extends AllocationDecider {
2022

2123
public static final String NAME = "node_replacement";
@@ -153,14 +155,12 @@ private static boolean isReplacementTargetName(Metadata metadata, String nodeNam
153155
.anyMatch(shutdown -> shutdown.getTargetNodeName().equals(nodeName));
154156
}
155157

156-
private static String getReplacementName(Metadata metadata, String nodeBeingReplaced) {
157-
if (nodeBeingReplaced == null || replacementOngoing(metadata) == false) {
158+
private static String getReplacementName(Metadata metadata, String nodeIdBeingReplaced) {
159+
if (nodeIdBeingReplaced == null || replacementOngoing(metadata) == false) {
158160
return null;
159161
}
160-
return metadata.nodeShutdowns().values().stream()
162+
return Optional.ofNullable(metadata.nodeShutdowns().get(nodeIdBeingReplaced))
161163
.filter(shutdown -> shutdown.getType().equals(SingleNodeShutdownMetadata.Type.REPLACE))
162-
.filter(shutdown -> shutdown.getNodeId().equals(nodeBeingReplaced))
163-
.findFirst()
164164
.map(SingleNodeShutdownMetadata::getTargetNodeName)
165165
.orElse(null);
166166
}

0 commit comments

Comments
 (0)