|
32 | 32 | import org.opensearch.gateway.PriorityComparator; |
33 | 33 |
|
34 | 34 | import java.util.ArrayList; |
35 | | -import java.util.Arrays; |
36 | 35 | import java.util.Collections; |
37 | 36 | import java.util.Comparator; |
38 | 37 | import java.util.HashMap; |
|
41 | 40 | import java.util.List; |
42 | 41 | import java.util.Map; |
43 | 42 | import java.util.Set; |
44 | | -import java.util.stream.Collectors; |
45 | 43 | import java.util.stream.Stream; |
46 | 44 | import java.util.stream.StreamSupport; |
47 | 45 |
|
@@ -779,15 +777,16 @@ void allocateUnassigned() { |
779 | 777 | * if we allocate for instance (0, R, IDX1) we move the second replica to the secondary array and proceed with |
780 | 778 | * the next replica. If we could not find a node to allocate (0,R,IDX1) we move all it's replicas to ignoreUnassigned. |
781 | 779 | */ |
782 | | - ShardRouting[] unassignedShards = unassigned.drain(); |
783 | | - List<ShardRouting> allUnassignedShards = Arrays.stream(unassignedShards).collect(Collectors.toList()); |
784 | | - List<ShardRouting> localUnassignedShards = allUnassignedShards.stream() |
785 | | - .filter(shard -> RoutingPool.LOCAL_ONLY.equals(RoutingPool.getShardPool(shard, allocation))) |
786 | | - .collect(Collectors.toList()); |
787 | | - allUnassignedShards.removeAll(localUnassignedShards); |
788 | | - allUnassignedShards.forEach(shard -> routingNodes.unassigned().add(shard)); |
789 | | - unassignedShards = localUnassignedShards.toArray(new ShardRouting[0]); |
790 | | - ShardRouting[] primary = unassignedShards; |
| 780 | + List<ShardRouting> primaryList = new ArrayList<>(); |
| 781 | + for (ShardRouting shard : unassigned.drain()) { |
| 782 | + if (RoutingPool.LOCAL_ONLY.equals(RoutingPool.getShardPool(shard, allocation))) { |
| 783 | + primaryList.add(shard); |
| 784 | + } else { |
| 785 | + routingNodes.unassigned().add(shard); |
| 786 | + } |
| 787 | + } |
| 788 | + |
| 789 | + ShardRouting[] primary = primaryList.toArray(new ShardRouting[0]); |
791 | 790 | ShardRouting[] secondary = new ShardRouting[primary.length]; |
792 | 791 | int secondaryLength = 0; |
793 | 792 | int primaryLength = primary.length; |
|
0 commit comments