Skip to content

Commit dd035b0

Browse files
committed
ILM: enable the readonly action in the cold phase (elastic#69024)
This enables the readonly ILM action in the cold phase. (cherry picked from commit 9da3a6e) Signed-off-by: Andrei Dan <[email protected]>
1 parent 7c96891 commit dd035b0

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
@@ -576,6 +576,10 @@ public void testGetNextActionName() {
576576
assertNextActionName("cold", SetPriorityAction.NAME, null, new String[] { SetPriorityAction.NAME });
577577
assertNextActionName("cold", SetPriorityAction.NAME, null, new String[] {});
578578

579+
assertNextActionName("cold", UnfollowAction.NAME, ReadOnlyAction.NAME,
580+
new String[] {ReadOnlyAction.NAME, SearchableSnapshotAction.NAME, SetPriorityAction.NAME, AllocateAction.NAME});
581+
assertNextActionName("cold", UnfollowAction.NAME, SearchableSnapshotAction.NAME,
582+
new String[] {SearchableSnapshotAction.NAME, AllocateAction.NAME, FreezeAction.NAME});
579583
assertNextActionName("cold", UnfollowAction.NAME, AllocateAction.NAME,
580584
new String[] {SetPriorityAction.NAME, AllocateAction.NAME, FreezeAction.NAME});
581585
assertNextActionName("cold", UnfollowAction.NAME, AllocateAction.NAME,
@@ -594,7 +598,6 @@ public void testGetNextActionName() {
594598
assertInvalidAction("cold", "foo", new String[] { AllocateAction.NAME });
595599
assertInvalidAction("cold", DeleteAction.NAME, new String[] { AllocateAction.NAME });
596600
assertInvalidAction("cold", ForceMergeAction.NAME, new String[] { AllocateAction.NAME });
597-
assertInvalidAction("cold", ReadOnlyAction.NAME, new String[] { AllocateAction.NAME });
598601
assertInvalidAction("cold", RolloverAction.NAME, new String[] { AllocateAction.NAME });
599602
assertInvalidAction("cold", ShrinkAction.NAME, new String[] { AllocateAction.NAME });
600603

@@ -746,6 +749,8 @@ private ConcurrentMap<String, LifecycleAction> convertActionNamesToActions(Strin
746749
return new MigrateAction(true);
747750
case RollupILMAction.NAME:
748751
return TEST_ROLLUP_ACTION;
752+
case SearchableSnapshotAction.NAME:
753+
return TEST_SEARCHABLE_SNAPSHOT_ACTION;
749754
}
750755
return new DeleteAction();
751756
}).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;
@@ -392,49 +391,6 @@ public void testDeleteDuringSnapshot() throws Exception {
392391
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(404));
393392
}
394393

395-
public void testReadOnly() throws Exception {
396-
createIndexWithSettings(client(), index, alias, Settings.builder()
397-
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
398-
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0));
399-
createNewSingletonPolicy(client(), policy, "warm", new ReadOnlyAction());
400-
updatePolicy(client(), index, policy);
401-
assertBusy(() -> {
402-
Map<String, Object> settings = getOnlyIndexSettings(client(), index);
403-
assertThat(getStepKeyForIndex(client(), index), equalTo(PhaseCompleteStep.finalStep("warm").getKey()));
404-
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey()), equalTo("true"));
405-
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_METADATA_SETTING.getKey()), nullValue());
406-
});
407-
}
408-
409-
public void testReadOnlyInTheHotPhase() throws Exception {
410-
String originalIndex = index + "-000001";
411-
412-
// add a policy
413-
Map<String, LifecycleAction> hotActions = org.elasticsearch.common.collect.Map.of(
414-
RolloverAction.NAME, new RolloverAction(null, null, 1L),
415-
ReadOnlyAction.NAME, new ReadOnlyAction());
416-
Map<String, Phase> phases = org.elasticsearch.common.collect.Map.of(
417-
"hot", new Phase("hot", TimeValue.ZERO, hotActions));
418-
LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policy, phases);
419-
Request createPolicyRequest = new Request("PUT", "_ilm/policy/" + policy);
420-
createPolicyRequest.setJsonEntity("{ \"policy\":" + Strings.toString(lifecyclePolicy) + "}");
421-
client().performRequest(createPolicyRequest);
422-
423-
// then create the index and index a document to trigger rollover
424-
createIndexWithSettings(client(), originalIndex, alias, Settings.builder()
425-
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
426-
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
427-
.put("index.lifecycle.rollover_alias", alias)
428-
.put("index.lifecycle.name", policy));
429-
index(client(), originalIndex, "_id", "foo", "bar");
430-
431-
assertBusy(() -> {
432-
Map<String, Object> settings = getOnlyIndexSettings(client(), originalIndex);
433-
assertThat(getStepKeyForIndex(client(), originalIndex), equalTo(PhaseCompleteStep.finalStep("hot").getKey()));
434-
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey()), equalTo("true"));
435-
});
436-
}
437-
438394
public void forceMergeActionWithCodec(String codec) throws Exception {
439395
createIndexWithSettings(client(), index, alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
440396
.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 = org.elasticsearch.common.collect.Map.of(
72+
RolloverAction.NAME, new RolloverAction(null, null, 1L),
73+
ReadOnlyAction.NAME, new ReadOnlyAction());
74+
Map<String, Phase> phases = org.elasticsearch.common.collect.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)