17
17
import org .elasticsearch .cluster .routing .ShardRouting ;
18
18
import org .elasticsearch .cluster .routing .UnassignedInfo ;
19
19
import org .elasticsearch .cluster .routing .allocation .command .MoveAllocationCommand ;
20
- import org .elasticsearch .cluster .routing .allocation .decider .Decision ;
21
20
import org .elasticsearch .common .metrics .MeanMetric ;
22
21
import org .elasticsearch .core .Strings ;
23
22
import org .elasticsearch .index .shard .ShardId ;
@@ -144,21 +143,14 @@ public DesiredBalance compute(
144
143
// Here existing shards are moved to desired locations before initializing unassigned shards because we prefer not to leave
145
144
// immovable shards allocated to undesirable locations (e.g. a node that is shutting down or an allocation filter which was
146
145
// only recently applied). In contrast, reconciliation prefers to initialize the unassigned shards first.
147
- relocateToDesiredLocation : for (final var shardRouting : shardsToRelocate .values ()) {
146
+ for (final var shardRouting : shardsToRelocate .values ()) {
148
147
assert shardRouting .started ();
149
-
150
- while (targetNodesIterator .hasNext ()) {
151
- final var targetNodeId = targetNodesIterator .next ();
152
- final var targetNode = routingNodes .node (targetNodeId );
153
- if (targetNode != null
154
- && routingAllocation .deciders ()
155
- .canAllocate (shardRouting , targetNode , routingAllocation )
156
- .type () != Decision .Type .NO ) {
157
- final var shardToRelocate = routingNodes .relocateShard (shardRouting , targetNodeId , 0L , changes ).v2 ();
158
- clusterInfoSimulator .simulateShardStarted (shardToRelocate );
159
- routingNodes .startShard (logger , shardToRelocate , changes , 0L );
160
- continue relocateToDesiredLocation ;
161
- }
148
+ if (targetNodesIterator .hasNext ()) {
149
+ ShardRouting shardToRelocate = routingNodes .relocateShard (shardRouting , targetNodesIterator .next (), 0L , changes ).v2 ();
150
+ clusterInfoSimulator .simulateShardStarted (shardToRelocate );
151
+ routingNodes .startShard (logger , shardToRelocate , changes , 0L );
152
+ } else {
153
+ break ;
162
154
}
163
155
}
164
156
@@ -180,15 +172,9 @@ public DesiredBalance compute(
180
172
final var nodeIds = unassignedShardsToInitialize .get (shardRouting );
181
173
if (nodeIds != null && nodeIds .isEmpty () == false ) {
182
174
final var nodeId = nodeIds .removeFirst ();
183
- final var routingNode = routingNodes .node (nodeId );
184
- if (routingNode != null
185
- && routingAllocation .deciders ()
186
- .canAllocate (shardRouting , routingNode , routingAllocation )
187
- .type () != Decision .Type .NO ) {
188
- final var shardToInitialize = unassignedPrimaryIterator .initialize (nodeId , null , 0L , changes );
189
- clusterInfoSimulator .simulateShardStarted (shardToInitialize );
190
- routingNodes .startShard (logger , shardToInitialize , changes , 0L );
191
- }
175
+ final var shardToInitialize = unassignedPrimaryIterator .initialize (nodeId , null , 0L , changes );
176
+ clusterInfoSimulator .simulateShardStarted (shardToInitialize );
177
+ routingNodes .startShard (logger , shardToInitialize , changes , 0L );
192
178
}
193
179
}
194
180
}
@@ -199,16 +185,10 @@ public DesiredBalance compute(
199
185
if (unassignedPrimaries .contains (shardRouting .shardId ()) == false ) {
200
186
final var nodeIds = unassignedShardsToInitialize .get (shardRouting );
201
187
if (nodeIds != null && nodeIds .isEmpty () == false ) {
202
- final var nodeId = nodeIds .removeFirst ();
203
- final var routingNode = routingNodes .node (nodeId );
204
- if (routingNode != null
205
- && routingAllocation .deciders ()
206
- .canAllocate (shardRouting , routingNode , routingAllocation )
207
- .type () != Decision .Type .NO ) {
208
- final var shardToInitialize = unassignedReplicaIterator .initialize (nodeId , null , 0L , changes );
209
- clusterInfoSimulator .simulateShardStarted (shardToInitialize );
210
- routingNodes .startShard (logger , shardToInitialize , changes , 0L );
211
- }
188
+ final String nodeId = nodeIds .removeFirst ();
189
+ ShardRouting shardToInitialize = unassignedReplicaIterator .initialize (nodeId , null , 0L , changes );
190
+ clusterInfoSimulator .simulateShardStarted (shardToInitialize );
191
+ routingNodes .startShard (logger , shardToInitialize , changes , 0L );
212
192
}
213
193
}
214
194
}
0 commit comments