Skip to content

Commit 718315c

Browse files
authored
Add unit tests for MountSnapshotStep in COLD phase (#126804)
1 parent 83ce15a commit 718315c

File tree

2 files changed

+96
-3
lines changed

2 files changed

+96
-3
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MountSnapshotStep.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ static Optional<String> overrideTierPreference(String phase) {
230230
* - index.routing.allocation.total_shards_per_node: It is likely that frozen tier has fewer nodes than the hot tier. If this setting
231231
* is not specifically set in the frozen tier, keeping this setting runs the risk that we will not have enough nodes to
232232
* allocate all the shards in the frozen tier and the user does not have any way of fixing this. For this reason, we ignore this
233-
* setting when moving to frozen. We do not ignore this setting if it is specifically set in the mount searchable snapshot step
234-
* of frozen tier.
233+
* setting when moving to frozen. We do not ignore this setting if it is specifically set in the mount searchable snapshot step.
235234
*/
236235
String[] ignoredIndexSettings() {
237236
ArrayList<String> ignoredSettings = new ArrayList<>();
@@ -240,6 +239,7 @@ String[] ignoredIndexSettings() {
240239
// if total_shards_per_node setting is specifically set for the frozen phase and not propagated from previous phase,
241240
// then it should not be ignored
242241
if (TimeseriesLifecycleType.FROZEN_PHASE.equals(this.getKey().phase()) && this.totalShardsPerNode == null) {
242+
// in frozen phase only, propagated total_shards_per_node (from previous hot/cold phase) is ignored
243243
ignoredSettings.add(ShardsLimitAllocationDecider.INDEX_TOTAL_SHARDS_PER_NODE_SETTING.getKey());
244244
}
245245
return ignoredSettings.toArray(new String[0]);

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MountSnapshotStepTests.java

+94-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,52 @@ public void testIgnoreTotalShardsPerNodeInFrozenPhase() throws Exception {
397397
}
398398
}
399399

400-
public void testDoNotIgnoreTotalShardsPerNodeAndReplicasIfSet() throws Exception {
400+
public void testDoNotIgnorePropagatedTotalShardsPerNodeInColdPhase() throws Exception {
401+
String indexName = randomAlphaOfLength(10);
402+
String policyName = "test-ilm-policy";
403+
Map<String, String> ilmCustom = new HashMap<>();
404+
String snapshotName = indexName + "-" + policyName;
405+
ilmCustom.put("snapshot_name", snapshotName);
406+
String repository = "repository";
407+
ilmCustom.put("snapshot_repository", repository);
408+
409+
IndexMetadata.Builder indexMetadataBuilder = IndexMetadata.builder(indexName)
410+
.settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_NAME, policyName))
411+
.putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, ilmCustom)
412+
.numberOfShards(randomIntBetween(1, 5))
413+
.numberOfReplicas(randomIntBetween(0, 5));
414+
IndexMetadata indexMetadata = indexMetadataBuilder.build();
415+
416+
ClusterState clusterState = ClusterState.builder(emptyClusterState())
417+
.metadata(Metadata.builder().put(indexMetadata, true).build())
418+
.build();
419+
420+
try (var threadPool = createThreadPool()) {
421+
final var client = getRestoreSnapshotRequestAssertingClient(
422+
threadPool,
423+
repository,
424+
snapshotName,
425+
indexName,
426+
RESTORED_INDEX_PREFIX,
427+
indexName,
428+
new String[] { LifecycleSettings.LIFECYCLE_NAME },
429+
null,
430+
0
431+
);
432+
MountSnapshotStep step = new MountSnapshotStep(
433+
new StepKey(TimeseriesLifecycleType.COLD_PHASE, randomAlphaOfLength(10), randomAlphaOfLength(10)),
434+
randomStepKey(),
435+
client,
436+
RESTORED_INDEX_PREFIX,
437+
randomStorageType(),
438+
null,
439+
0
440+
);
441+
performActionAndWait(step, indexMetadata, clusterState, null);
442+
}
443+
}
444+
445+
public void testDoNotIgnoreTotalShardsPerNodeAndReplicasIfSetInFrozenPhase() throws Exception {
401446
String indexName = randomAlphaOfLength(10);
402447
String policyName = "test-ilm-policy";
403448
Map<String, String> ilmCustom = new HashMap<>();
@@ -445,6 +490,54 @@ public void testDoNotIgnoreTotalShardsPerNodeAndReplicasIfSet() throws Exception
445490
}
446491
}
447492

493+
public void testDoNotIgnoreTotalShardsPerNodeAndReplicasIfSetInCold() throws Exception {
494+
String indexName = randomAlphaOfLength(10);
495+
String policyName = "test-ilm-policy";
496+
Map<String, String> ilmCustom = new HashMap<>();
497+
String snapshotName = indexName + "-" + policyName;
498+
ilmCustom.put("snapshot_name", snapshotName);
499+
String repository = "repository";
500+
ilmCustom.put("snapshot_repository", repository);
501+
502+
IndexMetadata.Builder indexMetadataBuilder = IndexMetadata.builder(indexName)
503+
.settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_NAME, policyName))
504+
.putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, ilmCustom)
505+
.numberOfShards(randomIntBetween(1, 5))
506+
.numberOfReplicas(randomIntBetween(0, 5));
507+
IndexMetadata indexMetadata = indexMetadataBuilder.build();
508+
509+
ClusterState clusterState = ClusterState.builder(emptyClusterState())
510+
.metadata(Metadata.builder().put(indexMetadata, true).build())
511+
.build();
512+
513+
final Integer totalShardsPerNode = randomTotalShardsPerNode(false);
514+
final int replicas = randomIntBetween(1, 5);
515+
516+
try (var threadPool = createThreadPool()) {
517+
final var client = getRestoreSnapshotRequestAssertingClient(
518+
threadPool,
519+
repository,
520+
snapshotName,
521+
indexName,
522+
RESTORED_INDEX_PREFIX,
523+
indexName,
524+
new String[] { LifecycleSettings.LIFECYCLE_NAME },
525+
totalShardsPerNode,
526+
replicas
527+
);
528+
MountSnapshotStep step = new MountSnapshotStep(
529+
new StepKey(TimeseriesLifecycleType.COLD_PHASE, randomAlphaOfLength(10), randomAlphaOfLength(10)),
530+
randomStepKey(),
531+
client,
532+
RESTORED_INDEX_PREFIX,
533+
randomStorageType(),
534+
totalShardsPerNode,
535+
replicas
536+
);
537+
performActionAndWait(step, indexMetadata, clusterState, null);
538+
}
539+
}
540+
448541
@SuppressWarnings("unchecked")
449542
private NoOpClient getClientTriggeringResponse(ThreadPool threadPool, RestoreSnapshotResponse response) {
450543
return new NoOpClient(threadPool) {

0 commit comments

Comments
 (0)