Skip to content

Commit 9da3a6e

Browse files
authored
ILM: enable the readonly action in the cold phase (elastic#69024)
This enables the readonly ILM action in the cold phase.
1 parent 45b1c46 commit 9da3a6e

File tree

5 files changed

+106
-50
lines changed

5 files changed

+106
-50
lines changed

docs/reference/ilm/actions/ilm-readonly.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[[ilm-readonly]]
33
=== Read only
44

5-
Phases allowed: hot, warm.
5+
Phases allowed: hot, warm, cold, frozen.
66

77
Makes the index <<index-blocks-read-only,read-only>>.
88

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ public class TimeseriesLifecycleType implements LifecycleType {
6868
if (RollupV2.isEnabled()) {
6969
ORDERED_VALID_HOT_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, RolloverAction.NAME,
7070
ReadOnlyAction.NAME, RollupILMAction.NAME, ShrinkAction.NAME, ForceMergeAction.NAME, SearchableSnapshotAction.NAME);
71-
ORDERED_VALID_COLD_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, SearchableSnapshotAction.NAME,
72-
AllocateAction.NAME, MigrateAction.NAME, FreezeAction.NAME, RollupILMAction.NAME);
71+
ORDERED_VALID_COLD_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, ReadOnlyAction.NAME,
72+
SearchableSnapshotAction.NAME, AllocateAction.NAME, MigrateAction.NAME, FreezeAction.NAME, RollupILMAction.NAME);
7373
} else {
7474
ORDERED_VALID_HOT_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, RolloverAction.NAME,
7575
ReadOnlyAction.NAME, ShrinkAction.NAME, ForceMergeAction.NAME, SearchableSnapshotAction.NAME);
76-
ORDERED_VALID_COLD_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, SearchableSnapshotAction.NAME,
77-
AllocateAction.NAME, MigrateAction.NAME, FreezeAction.NAME);
76+
ORDERED_VALID_COLD_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, ReadOnlyAction.NAME,
77+
SearchableSnapshotAction.NAME, AllocateAction.NAME, MigrateAction.NAME, FreezeAction.NAME);
7878
}
7979
VALID_HOT_ACTIONS = Sets.newHashSet(ORDERED_VALID_HOT_ACTIONS);
8080
VALID_COLD_ACTIONS = Sets.newHashSet(ORDERED_VALID_COLD_ACTIONS);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ public void testGetNextActionName() {
570570
assertNextActionName("cold", SetPriorityAction.NAME, null, new String[] { SetPriorityAction.NAME });
571571
assertNextActionName("cold", SetPriorityAction.NAME, null, new String[] {});
572572

573+
assertNextActionName("cold", UnfollowAction.NAME, ReadOnlyAction.NAME,
574+
new String[] {ReadOnlyAction.NAME, SearchableSnapshotAction.NAME, SetPriorityAction.NAME, AllocateAction.NAME});
575+
assertNextActionName("cold", UnfollowAction.NAME, SearchableSnapshotAction.NAME,
576+
new String[] {SearchableSnapshotAction.NAME, AllocateAction.NAME, FreezeAction.NAME});
573577
assertNextActionName("cold", UnfollowAction.NAME, AllocateAction.NAME,
574578
new String[] {SetPriorityAction.NAME, AllocateAction.NAME, FreezeAction.NAME});
575579
assertNextActionName("cold", UnfollowAction.NAME, AllocateAction.NAME,
@@ -588,7 +592,6 @@ public void testGetNextActionName() {
588592
assertInvalidAction("cold", "foo", new String[] { AllocateAction.NAME });
589593
assertInvalidAction("cold", DeleteAction.NAME, new String[] { AllocateAction.NAME });
590594
assertInvalidAction("cold", ForceMergeAction.NAME, new String[] { AllocateAction.NAME });
591-
assertInvalidAction("cold", ReadOnlyAction.NAME, new String[] { AllocateAction.NAME });
592595
assertInvalidAction("cold", RolloverAction.NAME, new String[] { AllocateAction.NAME });
593596
assertInvalidAction("cold", ShrinkAction.NAME, new String[] { AllocateAction.NAME });
594597

@@ -740,6 +743,8 @@ private ConcurrentMap<String, LifecycleAction> convertActionNamesToActions(Strin
740743
return new MigrateAction(true);
741744
case RollupILMAction.NAME:
742745
return TEST_ROLLUP_ACTION;
746+
case SearchableSnapshotAction.NAME:
747+
return TEST_SEARCHABLE_SNAPSHOT_ACTION;
743748
}
744749
return new DeleteAction();
745750
}).collect(Collectors.toConcurrentMap(LifecycleAction::getWriteableName, Function.identity()));

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

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
3939
import org.elasticsearch.xpack.core.ilm.Phase;
4040
import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep;
41-
import org.elasticsearch.xpack.core.ilm.ReadOnlyAction;
4241
import org.elasticsearch.xpack.core.ilm.RolloverAction;
4342
import org.elasticsearch.xpack.core.ilm.SearchableSnapshotAction;
4443
import org.elasticsearch.xpack.core.ilm.SetPriorityAction;
@@ -388,49 +387,6 @@ public void testDeleteDuringSnapshot() throws Exception {
388387
assertOK(client().performRequest(new Request("DELETE", "/_snapshot/repo/" + snapName)));
389388
}
390389

391-
public void testReadOnly() throws Exception {
392-
createIndexWithSettings(client(), index, alias, Settings.builder()
393-
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
394-
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0));
395-
createNewSingletonPolicy(client(), policy, "warm", new ReadOnlyAction());
396-
updatePolicy(client(), index, policy);
397-
assertBusy(() -> {
398-
Map<String, Object> settings = getOnlyIndexSettings(client(), index);
399-
assertThat(getStepKeyForIndex(client(), index), equalTo(PhaseCompleteStep.finalStep("warm").getKey()));
400-
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey()), equalTo("true"));
401-
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_METADATA_SETTING.getKey()), nullValue());
402-
});
403-
}
404-
405-
public void testReadOnlyInTheHotPhase() throws Exception {
406-
String originalIndex = index + "-000001";
407-
408-
// add a policy
409-
Map<String, LifecycleAction> hotActions = Map.of(
410-
RolloverAction.NAME, new RolloverAction(null, null, 1L),
411-
ReadOnlyAction.NAME, new ReadOnlyAction());
412-
Map<String, Phase> phases = Map.of(
413-
"hot", new Phase("hot", TimeValue.ZERO, hotActions));
414-
LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policy, phases);
415-
Request createPolicyRequest = new Request("PUT", "_ilm/policy/" + policy);
416-
createPolicyRequest.setJsonEntity("{ \"policy\":" + Strings.toString(lifecyclePolicy) + "}");
417-
client().performRequest(createPolicyRequest);
418-
419-
// then create the index and index a document to trigger rollover
420-
createIndexWithSettings(client(), originalIndex, alias, Settings.builder()
421-
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
422-
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
423-
.put("index.lifecycle.rollover_alias", alias)
424-
.put("index.lifecycle.name", policy));
425-
index(client(), originalIndex, "_id", "foo", "bar");
426-
427-
assertBusy(() -> {
428-
Map<String, Object> settings = getOnlyIndexSettings(client(), originalIndex);
429-
assertThat(getStepKeyForIndex(client(), originalIndex), equalTo(PhaseCompleteStep.finalStep("hot").getKey()));
430-
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey()), equalTo("true"));
431-
});
432-
}
433-
434390
public void forceMergeActionWithCodec(String codec) throws Exception {
435391
createIndexWithSettings(client(), index, alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
436392
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.ilm.actions;
9+
10+
import org.elasticsearch.client.Request;
11+
import org.elasticsearch.cluster.metadata.IndexMetadata;
12+
import org.elasticsearch.common.Strings;
13+
import org.elasticsearch.common.settings.Settings;
14+
import org.elasticsearch.common.unit.TimeValue;
15+
import org.elasticsearch.test.rest.ESRestTestCase;
16+
import org.elasticsearch.xpack.core.ilm.LifecycleAction;
17+
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
18+
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
19+
import org.elasticsearch.xpack.core.ilm.Phase;
20+
import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep;
21+
import org.elasticsearch.xpack.core.ilm.ReadOnlyAction;
22+
import org.elasticsearch.xpack.core.ilm.RolloverAction;
23+
import org.junit.Before;
24+
25+
import java.util.Locale;
26+
import java.util.Map;
27+
28+
import static org.elasticsearch.xpack.TimeSeriesRestDriver.createIndexWithSettings;
29+
import static org.elasticsearch.xpack.TimeSeriesRestDriver.createNewSingletonPolicy;
30+
import static org.elasticsearch.xpack.TimeSeriesRestDriver.getOnlyIndexSettings;
31+
import static org.elasticsearch.xpack.TimeSeriesRestDriver.getStepKeyForIndex;
32+
import static org.elasticsearch.xpack.TimeSeriesRestDriver.index;
33+
import static org.elasticsearch.xpack.TimeSeriesRestDriver.updatePolicy;
34+
import static org.hamcrest.Matchers.equalTo;
35+
import static org.hamcrest.Matchers.nullValue;
36+
37+
public class ReadonlyActionIT extends ESRestTestCase {
38+
private static final String FAILED_STEP_RETRY_COUNT_FIELD = "failed_step_retry_count";
39+
40+
private String policy;
41+
private String index;
42+
private String alias;
43+
44+
@Before
45+
public void refreshAbstractions() {
46+
policy = "policy-" + randomAlphaOfLength(5);
47+
index = "index-" + randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
48+
alias = "alias-" + randomAlphaOfLength(5);
49+
logger.info("--> running [{}] with index [{}], alias [{}] and policy [{}]", getTestName(), index, alias, policy);
50+
}
51+
52+
public void testReadOnly() throws Exception {
53+
createIndexWithSettings(client(), index, alias, Settings.builder()
54+
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
55+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0));
56+
String phaseName = randomFrom("warm", "cold", "frozen");
57+
createNewSingletonPolicy(client(), policy, phaseName, new ReadOnlyAction());
58+
updatePolicy(client(), index, policy);
59+
assertBusy(() -> {
60+
Map<String, Object> settings = getOnlyIndexSettings(client(), index);
61+
assertThat(getStepKeyForIndex(client(), index), equalTo(PhaseCompleteStep.finalStep(phaseName).getKey()));
62+
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey()), equalTo("true"));
63+
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_METADATA_SETTING.getKey()), nullValue());
64+
});
65+
}
66+
67+
public void testReadOnlyInTheHotPhase() throws Exception {
68+
String originalIndex = index + "-000001";
69+
70+
// add a policy
71+
Map<String, LifecycleAction> hotActions = Map.of(
72+
RolloverAction.NAME, new RolloverAction(null, null, 1L),
73+
ReadOnlyAction.NAME, new ReadOnlyAction());
74+
Map<String, Phase> phases = Map.of(
75+
"hot", new Phase("hot", TimeValue.ZERO, hotActions));
76+
LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policy, phases);
77+
Request createPolicyRequest = new Request("PUT", "_ilm/policy/" + policy);
78+
createPolicyRequest.setJsonEntity("{ \"policy\":" + Strings.toString(lifecyclePolicy) + "}");
79+
client().performRequest(createPolicyRequest);
80+
81+
// then create the index and index a document to trigger rollover
82+
createIndexWithSettings(client(), originalIndex, alias, Settings.builder()
83+
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
84+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
85+
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias)
86+
.put(LifecycleSettings.LIFECYCLE_NAME, policy));
87+
index(client(), originalIndex, "_id", "foo", "bar");
88+
89+
assertBusy(() -> {
90+
Map<String, Object> settings = getOnlyIndexSettings(client(), originalIndex);
91+
assertThat(getStepKeyForIndex(client(), originalIndex), equalTo(PhaseCompleteStep.finalStep("hot").getKey()));
92+
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey()), equalTo("true"));
93+
});
94+
}
95+
}

0 commit comments

Comments
 (0)