File tree Expand file tree Collapse file tree 4 files changed +14
-18
lines changed
main/java/org/elasticsearch/cluster/routing/allocation/allocator
test/java/org/elasticsearch/cluster/routing/allocation/allocator Expand file tree Collapse file tree 4 files changed +14
-18
lines changed Original file line number Diff line number Diff line change @@ -384,7 +384,7 @@ private void balance() {
384384 }
385385
386386 // Balance each partition
387- for (NodeSorter nodeSorter : nodeSorters . allNodeSorters () ) {
387+ for (NodeSorter nodeSorter : nodeSorters ) {
388388 balanceByWeights (nodeSorter );
389389 }
390390 }
Original file line number Diff line number Diff line change 1111
1212import org .elasticsearch .cluster .routing .RoutingNode ;
1313import org .elasticsearch .cluster .routing .ShardRouting ;
14+ import org .elasticsearch .common .collect .Iterators ;
1415
15- import java .util .Collection ;
16- import java .util .List ;
16+ import java .util .Iterator ;
1717
1818public class GlobalBalancingWeightsFactory implements BalancingWeightsFactory {
1919
@@ -59,13 +59,13 @@ public NodeSorters createNodeSorters(BalancedShardsAllocator.ModelNode[] modelNo
5959 private record GlobalNodeSorters (BalancedShardsAllocator .NodeSorter nodeSorter ) implements NodeSorters {
6060
6161 @ Override
62- public Collection < BalancedShardsAllocator .NodeSorter > allNodeSorters ( ) {
63- return List . of ( nodeSorter ) ;
62+ public BalancedShardsAllocator .NodeSorter sorterForShard ( ShardRouting shard ) {
63+ return nodeSorter ;
6464 }
6565
6666 @ Override
67- public BalancedShardsAllocator .NodeSorter sorterForShard ( ShardRouting shard ) {
68- return nodeSorter ;
67+ public Iterator < BalancedShardsAllocator .NodeSorter > iterator ( ) {
68+ return Iterators . single ( nodeSorter ) ;
6969 }
7070 }
7171 }
Original file line number Diff line number Diff line change 1111
1212import org .elasticsearch .cluster .routing .ShardRouting ;
1313
14- import java .util .Collection ;
15-
1614/**
1715 * NodeSorters is just a cache of
1816 * {@link org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator.NodeSorter}
1917 * instances for each cluster partition
18+ * <p>
19+ * The returned iterator will return a node sorter for each partition in the cluster.
2020 */
21- public interface NodeSorters {
22-
23- /**
24- * Get the {@link BalancedShardsAllocator.NodeSorter}s for all partitions
25- */
26- Collection <BalancedShardsAllocator .NodeSorter > allNodeSorters ();
21+ public interface NodeSorters extends Iterable <BalancedShardsAllocator .NodeSorter > {
2722
2823 /**
2924 * Get the {@link BalancedShardsAllocator.NodeSorter} for the specified shard
Original file line number Diff line number Diff line change 5151import org .elasticsearch .test .gateway .TestGatewayAllocator ;
5252
5353import java .util .Arrays ;
54- import java .util .Collection ;
5554import java .util .Collections ;
5655import java .util .HashMap ;
56+ import java .util .Iterator ;
5757import java .util .List ;
5858import java .util .Map ;
5959import java .util .Set ;
@@ -844,9 +844,10 @@ public NodeSorters createNodeSorters(
844844 );
845845 }
846846 return new NodeSorters () {
847+
847848 @ Override
848- public Collection <BalancedShardsAllocator .NodeSorter > allNodeSorters () {
849- return prefixNodeSorters .values ();
849+ public Iterator <BalancedShardsAllocator .NodeSorter > iterator () {
850+ return prefixNodeSorters .values (). iterator () ;
850851 }
851852
852853 @ Override
You can’t perform that action at this time.
0 commit comments