Skip to content

Commit 9b0944f

Browse files
committed
Revert "Only simulate legal desired moves"
This reverts commit 1f86eb8.
1 parent 1f86eb8 commit 9b0944f

File tree

6 files changed

+22
-154
lines changed

6 files changed

+22
-154
lines changed

docs/changelog/93635.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/SnapshotBasedRecoveryIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import static org.hamcrest.Matchers.notNullValue;
4141

4242
public class SnapshotBasedRecoveryIT extends AbstractRollingTestCase {
43-
43+
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/91383")
4444
public void testSnapshotBasedRecovery() throws Exception {
4545
final String indexName = "snapshot_based_recovery";
4646
final String repositoryName = "snapshot_based_recovery_repo";

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceComputer.java

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.elasticsearch.cluster.routing.ShardRouting;
1818
import org.elasticsearch.cluster.routing.UnassignedInfo;
1919
import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand;
20-
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
2120
import org.elasticsearch.common.metrics.MeanMetric;
2221
import org.elasticsearch.core.Strings;
2322
import org.elasticsearch.index.shard.ShardId;
@@ -144,21 +143,14 @@ public DesiredBalance compute(
144143
// Here existing shards are moved to desired locations before initializing unassigned shards because we prefer not to leave
145144
// immovable shards allocated to undesirable locations (e.g. a node that is shutting down or an allocation filter which was
146145
// 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()) {
148147
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;
162154
}
163155
}
164156

@@ -180,15 +172,9 @@ public DesiredBalance compute(
180172
final var nodeIds = unassignedShardsToInitialize.get(shardRouting);
181173
if (nodeIds != null && nodeIds.isEmpty() == false) {
182174
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);
192178
}
193179
}
194180
}
@@ -199,16 +185,10 @@ public DesiredBalance compute(
199185
if (unassignedPrimaries.contains(shardRouting.shardId()) == false) {
200186
final var nodeIds = unassignedShardsToInitialize.get(shardRouting);
201187
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);
212192
}
213193
}
214194
}

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceShardsAllocator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,13 @@ private static String diff(DesiredBalance old, DesiredBalance updated) {
318318
var oldAssignment = old.getAssignment(shardId);
319319
var updatedAssignment = updated.getAssignment(shardId);
320320
if (Objects.equals(oldAssignment, updatedAssignment) == false) {
321-
builder.append(newLine).append(shardId).append(": ").append(oldAssignment).append(" -> ").append(updatedAssignment);
321+
builder.append(newLine).append(shardId).append(": ").append(oldAssignment).append(" --> ").append(updatedAssignment);
322322
}
323323
}
324324
for (ShardId shardId : diff) {
325325
var oldAssignment = old.getAssignment(shardId);
326326
var updatedAssignment = updated.getAssignment(shardId);
327-
builder.append(newLine).append(shardId).append(": ").append(oldAssignment).append(" -> ").append(updatedAssignment);
327+
builder.append(newLine).append(shardId).append(": ").append(oldAssignment).append(" --> ").append(updatedAssignment);
328328
}
329329
return builder.append(newLine).toString();
330330
}

server/src/test/java/org/elasticsearch/cluster/routing/allocation/AwarenessAllocationTests.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.elasticsearch.cluster.ESAllocationTestCase;
1818
import org.elasticsearch.cluster.metadata.IndexMetadata;
1919
import org.elasticsearch.cluster.metadata.Metadata;
20-
import org.elasticsearch.cluster.node.DiscoveryNode;
2120
import org.elasticsearch.cluster.node.DiscoveryNodes;
2221
import org.elasticsearch.cluster.routing.RoutingNode;
2322
import org.elasticsearch.cluster.routing.RoutingTable;
@@ -36,7 +35,6 @@
3635
import java.util.HashMap;
3736
import java.util.Map;
3837
import java.util.function.UnaryOperator;
39-
import java.util.stream.Collectors;
4038

4139
import static java.util.Collections.emptyMap;
4240
import static java.util.Collections.singletonList;
@@ -934,24 +932,15 @@ public void testUnassignedShardsWithUnbalancedZones() {
934932

935933
// Cancel all initializing shards and move started primary to another node.
936934
AllocationCommands commands = new AllocationCommands();
937-
final var unusedNodes = clusterState.nodes().stream().map(DiscoveryNode::getId).collect(Collectors.toSet());
938-
// Cancel all initializing shards
939-
for (ShardRouting routing : clusterState.routingTable().allShards()) {
940-
unusedNodes.remove(routing.currentNodeId());
941-
if (routing.initializing()) {
942-
commands.add(new CancelAllocationCommand(routing.shardId().getIndexName(), routing.id(), routing.currentNodeId(), false));
943-
}
944-
}
945-
// Move started primary to another node.
935+
String primaryNode = null;
946936
for (ShardRouting routing : clusterState.routingTable().allShards()) {
947937
if (routing.primary()) {
948-
var currentNodeId = routing.currentNodeId();
949-
unusedNodes.remove(currentNodeId);
950-
var otherNodeId = randomFrom(unusedNodes);
951-
commands.add(new MoveAllocationCommand("test", 0, currentNodeId, otherNodeId));
952-
break;
938+
primaryNode = routing.currentNodeId();
939+
} else if (routing.initializing()) {
940+
commands.add(new CancelAllocationCommand(routing.shardId().getIndexName(), routing.id(), routing.currentNodeId(), false));
953941
}
954942
}
943+
commands.add(new MoveAllocationCommand("test", 0, primaryNode, "A-4"));
955944

956945
clusterState = strategy.reroute(clusterState, commands, false, false, false, ActionListener.noop()).clusterState();
957946

x-pack/plugin/shutdown/src/internalClusterTest/java/org/elasticsearch/xpack/shutdown/DesiredBalanceShutdownIT.java

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)