Skip to content

Commit d519a2b

Browse files
authored
Allow readonly in the hot phase for ILM policies (#64418)
1 parent 50c6ec2 commit d519a2b

File tree

6 files changed

+57
-5
lines changed

6 files changed

+57
-5
lines changed

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

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

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

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

9+
To use the `readonly` action in the `hot` phase, the `rollover` action *must* be present.
10+
If no rollover action is configured, {ilm-init} will reject the policy.
11+
912
[[ilm-read-only-options]]
1013
==== Options
1114

docs/reference/ilm/ilm-index-lifecycle.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ the rollover criteria, it could be 20 minutes before the rollover is complete.
7878
- <<ilm-set-priority,Set Priority>>
7979
- <<ilm-unfollow,Unfollow>>
8080
- <<ilm-rollover,Rollover>>
81+
- <<ilm-readonly,Read-Only>>
8182
- <<ilm-shrink,Shrink>>
8283
- <<ilm-forcemerge,Force Merge>>
8384
* Warm

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class TimeseriesLifecycleType implements LifecycleType {
4040
static final String DELETE_PHASE = "delete";
4141
static final List<String> VALID_PHASES = Arrays.asList(HOT_PHASE, WARM_PHASE, COLD_PHASE, DELETE_PHASE);
4242
static final List<String> ORDERED_VALID_HOT_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, RolloverAction.NAME,
43-
ShrinkAction.NAME, ForceMergeAction.NAME);
43+
ReadOnlyAction.NAME, ShrinkAction.NAME, ForceMergeAction.NAME);
4444
static final List<String> ORDERED_VALID_WARM_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, ReadOnlyAction.NAME,
4545
AllocateAction.NAME, MigrateAction.NAME, ShrinkAction.NAME, ForceMergeAction.NAME);
4646
static final List<String> ORDERED_VALID_COLD_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, AllocateAction.NAME,
@@ -56,7 +56,8 @@ public class TimeseriesLifecycleType implements LifecycleType {
5656
COLD_PHASE, VALID_COLD_ACTIONS,
5757
DELETE_PHASE, VALID_DELETE_ACTIONS);
5858

59-
static final Set<String> HOT_ACTIONS_THAT_REQUIRE_ROLLOVER = Sets.newHashSet(ShrinkAction.NAME, ForceMergeAction.NAME);
59+
static final Set<String> HOT_ACTIONS_THAT_REQUIRE_ROLLOVER = Sets.newHashSet(ReadOnlyAction.NAME, ShrinkAction.NAME,
60+
ForceMergeAction.NAME);
6061

6162
private TimeseriesLifecycleType() {
6263
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ public void testGetNextActionName() {
408408
assertInvalidAction("hot", "foo", new String[] { RolloverAction.NAME });
409409
assertInvalidAction("hot", AllocateAction.NAME, new String[] { RolloverAction.NAME });
410410
assertInvalidAction("hot", DeleteAction.NAME, new String[] { RolloverAction.NAME });
411-
assertInvalidAction("hot", ReadOnlyAction.NAME, new String[] { RolloverAction.NAME });
412411

413412
// Warm Phase
414413
assertNextActionName("warm", SetPriorityAction.NAME, UnfollowAction.NAME,

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ public void testDeleteDuringSnapshot() throws Exception {
436436
}
437437

438438
public void testReadOnly() throws Exception {
439-
createIndexWithSettings(client(), index, alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
439+
createIndexWithSettings(client(), index, alias, Settings.builder()
440+
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
440441
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0));
441442
createNewSingletonPolicy(client(), policy, "warm", new ReadOnlyAction());
442443
updatePolicy(index, policy);
@@ -447,6 +448,35 @@ public void testReadOnly() throws Exception {
447448
});
448449
}
449450

451+
public void testReadOnlyInTheHotPhase() throws Exception {
452+
String originalIndex = index + "-000001";
453+
454+
// add a policy
455+
Map<String, LifecycleAction> hotActions = org.elasticsearch.common.collect.Map.of(
456+
RolloverAction.NAME, new RolloverAction(null, null, 1L),
457+
ReadOnlyAction.NAME, new ReadOnlyAction());
458+
Map<String, Phase> phases = org.elasticsearch.common.collect.Map.of(
459+
"hot", new Phase("hot", TimeValue.ZERO, hotActions));
460+
LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policy, phases);
461+
Request createPolicyRequest = new Request("PUT", "_ilm/policy/" + policy);
462+
createPolicyRequest.setJsonEntity("{ \"policy\":" + Strings.toString(lifecyclePolicy) + "}");
463+
client().performRequest(createPolicyRequest);
464+
465+
// then create the index and index a document to trigger rollover
466+
createIndexWithSettings(client(), originalIndex, alias, Settings.builder()
467+
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
468+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
469+
.put("index.lifecycle.rollover_alias", alias)
470+
.put("index.lifecycle.name", policy));
471+
index(client(), originalIndex, "_id", "foo", "bar");
472+
473+
assertBusy(() -> {
474+
Map<String, Object> settings = getOnlyIndexSettings(client(), originalIndex);
475+
assertThat(getStepKeyForIndex(client(), originalIndex), equalTo(PhaseCompleteStep.finalStep("hot").getKey()));
476+
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey()), equalTo("true"));
477+
});
478+
}
479+
450480
public void forceMergeActionWithCodec(String codec) throws Exception {
451481
createIndexWithSettings(client(), index, alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
452482
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0));

x-pack/plugin/ilm/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/ilm/10_basic.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,21 @@ setup:
258258
}
259259
}
260260
}
261+
262+
- do:
263+
catch: bad_request
264+
ilm.put_lifecycle:
265+
policy: "my_invalid_lifecycle"
266+
body: |
267+
{
268+
"policy": {
269+
"phases": {
270+
"hot": {
271+
"min_age": "0s",
272+
"actions": {
273+
"readonly": {}
274+
}
275+
}
276+
}
277+
}
278+
}

0 commit comments

Comments
 (0)