Skip to content

Commit c51dcb1

Browse files
authored
[ILM] Check shard and relocation status in AllocationRoutedStep (#35316)
* [ILM] Check shard and relocation status in AllocationRoutedStep This is a follow-up from #35161 where we now check for started and relocating state in `AllocationRoutedStep`. Resolves #35258
1 parent 8de3c6e commit c51dcb1

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/AllocationRoutedStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Result isConditionMet(Index index, ClusterState clusterState) {
7171
boolean canRemainOnCurrentNode = ALLOCATION_DECIDERS
7272
.canRemain(shardRouting, clusterState.getRoutingNodes().node(currentNodeId), allocation)
7373
.type() == Decision.Type.YES;
74-
if (canRemainOnCurrentNode == false) {
74+
if (canRemainOnCurrentNode == false || shardRouting.started() == false) {
7575
allocationPendingAllShards++;
7676
}
7777
}

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/AllocationRoutedStepTests.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.cluster.node.DiscoveryNodes;
1515
import org.elasticsearch.cluster.routing.IndexRoutingTable;
1616
import org.elasticsearch.cluster.routing.RoutingTable;
17+
import org.elasticsearch.cluster.routing.ShardRouting;
1718
import org.elasticsearch.cluster.routing.ShardRoutingState;
1819
import org.elasticsearch.cluster.routing.TestShardRouting;
1920
import org.elasticsearch.cluster.routing.UnassignedInfo;
@@ -132,6 +133,35 @@ public void testConditionMetOnlyOneCopyAllocated() {
132133
new ClusterStateWaitStep.Result(false, new AllocationRoutedStep.Info(0, 1, true)));
133134
}
134135

136+
public void testConditionNotMetDueToRelocation() {
137+
Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
138+
Map<String, String> requires = AllocateActionTests.randomMap(1, 5);
139+
Settings.Builder existingSettings = Settings.builder()
140+
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT.id)
141+
.put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_PREFIX + "._id", "node1")
142+
.put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID());
143+
Settings.Builder expectedSettings = Settings.builder();
144+
Settings.Builder node1Settings = Settings.builder();
145+
Settings.Builder node2Settings = Settings.builder();
146+
requires.forEach((k, v) -> {
147+
existingSettings.put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + k, v);
148+
expectedSettings.put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + k, v);
149+
node1Settings.put(Node.NODE_ATTRIBUTES.getKey() + k, v);
150+
});
151+
boolean primaryOnNode1 = randomBoolean();
152+
ShardRouting shardOnNode1 = TestShardRouting.newShardRouting(new ShardId(index, 0),
153+
"node1", primaryOnNode1, ShardRoutingState.STARTED);
154+
shardOnNode1 = shardOnNode1.relocate("node3", 230);
155+
IndexRoutingTable.Builder indexRoutingTable = IndexRoutingTable.builder(index)
156+
.addShard(shardOnNode1)
157+
.addShard(TestShardRouting.newShardRouting(new ShardId(index, 0), "node2", primaryOnNode1 == false,
158+
ShardRoutingState.STARTED));
159+
160+
AllocationRoutedStep step = new AllocationRoutedStep(randomStepKey(), randomStepKey());
161+
assertAllocateStatus(index, 1, 0, step, existingSettings, node1Settings, node2Settings, indexRoutingTable,
162+
new ClusterStateWaitStep.Result(false, new AllocationRoutedStep.Info(0, 2, true)));
163+
}
164+
135165
public void testExecuteAllocateNotComplete() throws Exception {
136166
Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
137167
Map<String, String> includes = AllocateActionTests.randomMap(1, 5);

0 commit comments

Comments
 (0)