Skip to content

Commit b1655c4

Browse files
authored
Remove ALL shard check in CheckShrinkReadyStep (#35346)
Since it's still possible to shrink an index when replicas are unassigned, we should not check that all copies are available when performing the shrink, since we set the allocation requirement for a single node. Resolves #35321
1 parent ed8732b commit b1655c4

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import org.apache.logging.log4j.LogManager;
1010
import org.apache.logging.log4j.Logger;
11-
import org.elasticsearch.action.support.ActiveShardCount;
1211
import org.elasticsearch.cluster.ClusterState;
1312
import org.elasticsearch.cluster.metadata.IndexMetaData;
1413
import org.elasticsearch.cluster.routing.IndexRoutingTable;
@@ -53,12 +52,6 @@ public Result isConditionMet(Index index, ClusterState clusterState) {
5352
// How many shards the node should have
5453
int expectedShardCount = idxMeta.getNumberOfShards();
5554

56-
if (ActiveShardCount.ALL.enoughShardsActive(clusterState, index.getName()) == false) {
57-
logger.debug("[{}] shrink action for [{}] cannot make progress because not all shards are active",
58-
getKey().getAction(), index.getName());
59-
return new Result(false, new CheckShrinkReadyStep.Info("", expectedShardCount, -1));
60-
}
61-
6255
// The id of the node the shards should be on
6356
final String idShardsShouldBeOn = idxMeta.getSettings().get(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_PREFIX + "._id");
6457
if (idShardsShouldBeOn == null) {

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

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public void testExecuteAllocateNotCompleteOnlyOneCopyAllocated() throws Exceptio
221221
new ClusterStateWaitStep.Result(false, new CheckShrinkReadyStep.Info("node1", 2, 1)));
222222
}
223223

224-
public void testExecuteAllocateUnassigned() throws Exception {
224+
public void testExecuteAllocateReplicaUnassigned() {
225225
Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
226226
Map<String, String> requires = AllocateActionTests.randomMap(1, 5);
227227
Settings.Builder existingSettings = Settings.builder()
@@ -239,12 +239,12 @@ public void testExecuteAllocateUnassigned() throws Exception {
239239

240240
IndexRoutingTable.Builder indexRoutingTable = IndexRoutingTable.builder(index)
241241
.addShard(TestShardRouting.newShardRouting(new ShardId(index, 0), "node1", true, ShardRoutingState.STARTED))
242-
.addShard(TestShardRouting.newShardRouting(new ShardId(index, 1), null, null, true, ShardRoutingState.UNASSIGNED,
242+
.addShard(TestShardRouting.newShardRouting(new ShardId(index, 0), null, null, false, ShardRoutingState.UNASSIGNED,
243243
new UnassignedInfo(randomFrom(UnassignedInfo.Reason.values()), "the shard is intentionally unassigned")));
244244

245245
CheckShrinkReadyStep step = createRandomInstance();
246-
assertAllocateStatus(index, 2, 0, step, existingSettings, node1Settings, node2Settings, indexRoutingTable,
247-
new ClusterStateWaitStep.Result(false, new CheckShrinkReadyStep.Info("", 2, -1)));
246+
assertAllocateStatus(index, 1, 1, step, existingSettings, node1Settings, node2Settings, indexRoutingTable,
247+
new ClusterStateWaitStep.Result(true, null));
248248
}
249249

250250
/**
@@ -267,7 +267,9 @@ public void testExecuteAllocateUnassigned() throws Exception {
267267
public void testExecuteReplicasNotAllocatedOnSingleNode() {
268268
Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
269269
Map<String, String> requires = Collections.singletonMap("_id", "node1");
270-
Settings.Builder existingSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT.id)
270+
Settings.Builder existingSettings = Settings.builder()
271+
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT.id)
272+
.put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_PREFIX + "._id", "node1")
271273
.put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID());
272274
Settings.Builder expectedSettings = Settings.builder();
273275
Settings.Builder node1Settings = Settings.builder();
@@ -278,12 +280,40 @@ public void testExecuteReplicasNotAllocatedOnSingleNode() {
278280

279281
IndexRoutingTable.Builder indexRoutingTable = IndexRoutingTable.builder(index)
280282
.addShard(TestShardRouting.newShardRouting(new ShardId(index, 0), "node1", true, ShardRoutingState.STARTED))
283+
.addShard(TestShardRouting.newShardRouting(new ShardId(index, 1), "node1", false, ShardRoutingState.STARTED))
284+
.addShard(TestShardRouting.newShardRouting(new ShardId(index, 1), "node2", true, ShardRoutingState.STARTED))
281285
.addShard(TestShardRouting.newShardRouting(new ShardId(index, 0), null, null, false, ShardRoutingState.UNASSIGNED,
282286
new UnassignedInfo(UnassignedInfo.Reason.REPLICA_ADDED, "no attempt")));
283287

284288
CheckShrinkReadyStep step = createRandomInstance();
285-
assertAllocateStatus(index, 1, 1, step, existingSettings, node1Settings, node2Settings, indexRoutingTable,
286-
new ClusterStateWaitStep.Result(false, new CheckShrinkReadyStep.Info("", 1, -1)));
289+
assertAllocateStatus(index, 2, 1, step, existingSettings, node1Settings, node2Settings, indexRoutingTable,
290+
new ClusterStateWaitStep.Result(true, null));
291+
}
292+
293+
public void testExecuteReplicasButCopiesNotPresent() {
294+
Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));
295+
Map<String, String> requires = Collections.singletonMap("_id", "node1");
296+
Settings.Builder existingSettings = Settings.builder()
297+
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT.id)
298+
.put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_PREFIX + "._id", "node1")
299+
.put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID());
300+
Settings.Builder expectedSettings = Settings.builder();
301+
Settings.Builder node1Settings = Settings.builder();
302+
Settings.Builder node2Settings = Settings.builder();
303+
requires.forEach((k, v) -> {
304+
expectedSettings.put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + k, v);
305+
});
306+
307+
IndexRoutingTable.Builder indexRoutingTable = IndexRoutingTable.builder(index)
308+
.addShard(TestShardRouting.newShardRouting(new ShardId(index, 0), "node1", true, ShardRoutingState.STARTED))
309+
.addShard(TestShardRouting.newShardRouting(new ShardId(index, 1), "node2", false, ShardRoutingState.STARTED))
310+
.addShard(TestShardRouting.newShardRouting(new ShardId(index, 1), "node3", true, ShardRoutingState.STARTED))
311+
.addShard(TestShardRouting.newShardRouting(new ShardId(index, 0), null, null, false, ShardRoutingState.UNASSIGNED,
312+
new UnassignedInfo(UnassignedInfo.Reason.REPLICA_ADDED, "no attempt")));
313+
314+
CheckShrinkReadyStep step = createRandomInstance();
315+
assertAllocateStatus(index, 2, 1, step, existingSettings, node1Settings, node2Settings, indexRoutingTable,
316+
new ClusterStateWaitStep.Result(false, new CheckShrinkReadyStep.Info("node1", 2, 1)));
287317
}
288318

289319
public void testExecuteIndexMissing() throws Exception {

0 commit comments

Comments
 (0)