Skip to content

Commit a76a04d

Browse files
authored
Migrate to data tiers API dry run on any ILM status (#82226) (#82260)
The migrate to data tiers routing API required ILM to be stopped. This is fine for "live" runs, but for dry runs this isn't a requirement. This changes the dry_run to allow the API to run irrespective of the ILM status.
1 parent 57c4cd2 commit a76a04d

File tree

5 files changed

+61
-34
lines changed

5 files changed

+61
-34
lines changed

docs/reference/ilm/apis/migrate-to-data-tiers.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ not perform the migration. This provides a way to retrieve the indices and ILM p
5050
migrated.
5151
Defaults to `false`.
5252

53+
NOTE: When simulating a migration (ie. `dry_run` is `true`) {ilm-init} doesn't need to be stopped.
54+
5355
[[ilm-migrate-to-data-tiers-example]]
5456
==== {api-examples-title}
5557

x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/MigrateToDataTiersIT.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,6 @@ public void testMigrationDryRun() throws Exception {
292292
TimeUnit.SECONDS
293293
);
294294

295-
// let's stop ILM so we can simulate the migration
296-
client().performRequest(new Request("POST", "_ilm/stop"));
297-
assertBusy(() -> {
298-
Response response = client().performRequest(new Request("GET", "_ilm/status"));
299-
assertThat(EntityUtils.toString(response.getEntity()), containsString(OperationMode.STOPPED.toString()));
300-
});
301-
302295
String indexWithDataWarmRouting = "indexwithdatawarmrouting";
303296
Settings.Builder settings = Settings.builder()
304297
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,16 @@ public static Tuple<ClusterState, MigratedEntities> migrateToDataTiersRouting(
134134
@Nullable String indexTemplateToDelete,
135135
NamedXContentRegistry xContentRegistry,
136136
Client client,
137-
XPackLicenseState licenseState
137+
XPackLicenseState licenseState,
138+
boolean dryRun
138139
) {
139-
IndexLifecycleMetadata currentMetadata = currentState.metadata().custom(IndexLifecycleMetadata.TYPE);
140-
if (currentMetadata != null && currentMetadata.getOperationMode() != STOPPED) {
141-
throw new IllegalStateException(
142-
"stop ILM before migrating to data tiers, current state is [" + currentMetadata.getOperationMode() + "]"
143-
);
140+
if (dryRun == false) {
141+
IndexLifecycleMetadata currentMetadata = currentState.metadata().custom(IndexLifecycleMetadata.TYPE);
142+
if (currentMetadata != null && currentMetadata.getOperationMode() != STOPPED) {
143+
throw new IllegalStateException(
144+
"stop ILM before migrating to data tiers, current state is [" + currentMetadata.getOperationMode() + "]"
145+
);
146+
}
144147
}
145148

146149
Metadata.Builder mb = Metadata.builder(currentState.metadata());

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportMigrateToDataTiersAction.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,32 @@ protected void masterOperation(
7575
ClusterState state,
7676
ActionListener<MigrateToDataTiersResponse> listener
7777
) throws Exception {
78-
IndexLifecycleMetadata currentMetadata = state.metadata().custom(IndexLifecycleMetadata.TYPE);
79-
if (currentMetadata != null && currentMetadata.getOperationMode() != STOPPED) {
80-
listener.onFailure(
81-
new IllegalStateException(
82-
"stop ILM before migrating to data tiers, current state is [" + currentMetadata.getOperationMode() + "]"
83-
)
84-
);
85-
return;
86-
}
87-
8878
if (request.isDryRun()) {
8979
MigratedEntities entities = migrateToDataTiersRouting(
9080
state,
9181
request.getNodeAttributeName(),
9282
request.getLegacyTemplateToDelete(),
9383
xContentRegistry,
9484
client,
95-
licenseState
85+
licenseState,
86+
request.isDryRun()
9687
).v2();
9788
listener.onResponse(
9889
new MigrateToDataTiersResponse(entities.removedIndexTemplateName, entities.migratedPolicies, entities.migratedIndices, true)
9990
);
10091
return;
10192
}
10293

94+
IndexLifecycleMetadata currentMetadata = state.metadata().custom(IndexLifecycleMetadata.TYPE);
95+
if (currentMetadata != null && currentMetadata.getOperationMode() != STOPPED) {
96+
listener.onFailure(
97+
new IllegalStateException(
98+
"stop ILM before migrating to data tiers, current state is [" + currentMetadata.getOperationMode() + "]"
99+
)
100+
);
101+
return;
102+
}
103+
103104
final SetOnce<MigratedEntities> migratedEntities = new SetOnce<>();
104105
clusterService.submitStateUpdateTask("migrate-to-data-tiers []", new ClusterStateUpdateTask(Priority.HIGH) {
105106
@Override
@@ -110,7 +111,8 @@ public ClusterState execute(ClusterState currentState) throws Exception {
110111
request.getLegacyTemplateToDelete(),
111112
xContentRegistry,
112113
client,
113-
licenseState
114+
licenseState,
115+
request.isDryRun()
114116
);
115117

116118
migratedEntities.set(migratedEntitiesTuple.v2());

x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingServiceTests.java

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,8 @@ public void testMigrateToDataTiersRouting() {
948948
"catch-all",
949949
REGISTRY,
950950
client,
951-
null
951+
null,
952+
false
952953
);
953954

954955
MigratedEntities migratedEntities = migratedEntitiesTuple.v2();
@@ -972,7 +973,8 @@ public void testMigrateToDataTiersRouting() {
972973
null,
973974
REGISTRY,
974975
client,
975-
null
976+
null,
977+
false
976978
);
977979

978980
MigratedEntities migratedEntities = migratedEntitiesTuple.v2();
@@ -996,7 +998,8 @@ public void testMigrateToDataTiersRouting() {
996998
null,
997999
REGISTRY,
9981000
client,
999-
null
1001+
null,
1002+
false
10001003
);
10011004

10021005
MigratedEntities migratedEntities = migratedEntitiesTuple.v2();
@@ -1022,7 +1025,7 @@ public void testMigrateToDataTiersRoutingRequiresILMStopped() {
10221025
.build();
10231026
IllegalStateException illegalStateException = expectThrows(
10241027
IllegalStateException.class,
1025-
() -> migrateToDataTiersRouting(ilmRunningState, "data", "catch-all", REGISTRY, client, null)
1028+
() -> migrateToDataTiersRouting(ilmRunningState, "data", "catch-all", REGISTRY, client, null, false)
10261029
);
10271030
assertThat(illegalStateException.getMessage(), is("stop ILM before migrating to data tiers, current state is [RUNNING]"));
10281031
}
@@ -1035,7 +1038,7 @@ public void testMigrateToDataTiersRoutingRequiresILMStopped() {
10351038
.build();
10361039
IllegalStateException illegalStateException = expectThrows(
10371040
IllegalStateException.class,
1038-
() -> migrateToDataTiersRouting(ilmStoppingState, "data", "catch-all", REGISTRY, client, null)
1041+
() -> migrateToDataTiersRouting(ilmStoppingState, "data", "catch-all", REGISTRY, client, null, false)
10391042
);
10401043
assertThat(illegalStateException.getMessage(), is("stop ILM before migrating to data tiers, current state is [STOPPING]"));
10411044
}
@@ -1052,14 +1055,37 @@ public void testMigrateToDataTiersRoutingRequiresILMStopped() {
10521055
"catch-all",
10531056
REGISTRY,
10541057
client,
1055-
null
1058+
null,
1059+
false
10561060
);
10571061
assertThat(migratedState.v2().migratedIndices, empty());
10581062
assertThat(migratedState.v2().migratedPolicies, empty());
10591063
assertThat(migratedState.v2().removedIndexTemplateName, nullValue());
10601064
}
10611065
}
10621066

1067+
public void testDryRunDoesntRequireILMStopped() {
1068+
{
1069+
ClusterState ilmRunningState = ClusterState.builder(ClusterName.DEFAULT)
1070+
.metadata(
1071+
Metadata.builder().putCustom(IndexLifecycleMetadata.TYPE, new IndexLifecycleMetadata(Map.of(), OperationMode.RUNNING))
1072+
)
1073+
.build();
1074+
migrateToDataTiersRouting(ilmRunningState, "data", "catch-all", REGISTRY, client, null, true);
1075+
// no exceptions
1076+
}
1077+
1078+
{
1079+
ClusterState ilmStoppingState = ClusterState.builder(ClusterName.DEFAULT)
1080+
.metadata(
1081+
Metadata.builder().putCustom(IndexLifecycleMetadata.TYPE, new IndexLifecycleMetadata(Map.of(), OperationMode.STOPPING))
1082+
)
1083+
.build();
1084+
migrateToDataTiersRouting(ilmStoppingState, "data", "catch-all", REGISTRY, client, null, true);
1085+
// no exceptions
1086+
}
1087+
}
1088+
10631089
public void testMigrationDoesNotRemoveComposableTemplates() {
10641090
ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate.Builder().indexPatterns(
10651091
Collections.singletonList("*")
@@ -1075,7 +1101,8 @@ public void testMigrationDoesNotRemoveComposableTemplates() {
10751101
composableTemplateName,
10761102
REGISTRY,
10771103
client,
1078-
null
1104+
null,
1105+
false
10791106
);
10801107
assertThat(migratedEntitiesTuple.v2().removedIndexTemplateName, nullValue());
10811108
assertThat(migratedEntitiesTuple.v1().metadata().templatesV2().get(composableTemplateName), is(composableIndexTemplate));
@@ -1088,7 +1115,7 @@ public void testMigrationSetsEnforceTierPreferenceToTrue() {
10881115

10891116
// if the cluster state doesn't mention the setting, it ends up true
10901117
clusterState = ClusterState.builder(ClusterName.DEFAULT).build();
1091-
migratedEntitiesTuple = migrateToDataTiersRouting(clusterState, null, null, REGISTRY, client, null);
1118+
migratedEntitiesTuple = migrateToDataTiersRouting(clusterState, null, null, REGISTRY, client, null, false);
10921119
assertTrue(DataTier.ENFORCE_DEFAULT_TIER_PREFERENCE_SETTING.get(migratedEntitiesTuple.v1().metadata().persistentSettings()));
10931120
assertFalse(migratedEntitiesTuple.v1().metadata().transientSettings().keySet().contains(DataTier.ENFORCE_DEFAULT_TIER_PREFERENCE));
10941121

@@ -1098,7 +1125,7 @@ public void testMigrationSetsEnforceTierPreferenceToTrue() {
10981125
metadata.persistentSettings(Settings.builder().put(ENFORCE_DEFAULT_TIER_PREFERENCE, randomBoolean()).build());
10991126
metadata.transientSettings(Settings.builder().put(ENFORCE_DEFAULT_TIER_PREFERENCE, randomBoolean()).build());
11001127
clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build();
1101-
migratedEntitiesTuple = migrateToDataTiersRouting(clusterState, null, null, REGISTRY, client, null);
1128+
migratedEntitiesTuple = migrateToDataTiersRouting(clusterState, null, null, REGISTRY, client, null, false);
11021129
assertTrue(DataTier.ENFORCE_DEFAULT_TIER_PREFERENCE_SETTING.get(migratedEntitiesTuple.v1().metadata().persistentSettings()));
11031130
assertFalse(migratedEntitiesTuple.v1().metadata().transientSettings().keySet().contains(DataTier.ENFORCE_DEFAULT_TIER_PREFERENCE));
11041131
}

0 commit comments

Comments
 (0)