Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow readonly in the hot phase for ILM policies #64381

Merged
merged 3 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/reference/ilm/actions/ilm-readonly.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
[[ilm-readonly]]
=== Read only

Phases allowed: warm.
Phases allowed: hot, warm.

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

To use the `readonly` action in the `hot` phase, the `rollover` action *must* be present.
If no rollover action is configured, {ilm-init} will reject the policy.

[[ilm-read-only-options]]
==== Options

Expand Down
1 change: 1 addition & 0 deletions docs/reference/ilm/ilm-index-lifecycle.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ the rollover criteria, it could be 20 minutes before the rollover is complete.
- <<ilm-set-priority,Set Priority>>
- <<ilm-unfollow,Unfollow>>
- <<ilm-rollover,Rollover>>
- <<ilm-readonly,Read-Only>>
- <<ilm-shrink,Shrink>>
- <<ilm-forcemerge,Force Merge>>
* Warm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class TimeseriesLifecycleType implements LifecycleType {
static final String DELETE_PHASE = "delete";
static final List<String> VALID_PHASES = Arrays.asList(HOT_PHASE, WARM_PHASE, COLD_PHASE, DELETE_PHASE);
static final List<String> ORDERED_VALID_HOT_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, RolloverAction.NAME,
ShrinkAction.NAME, ForceMergeAction.NAME);
ReadOnlyAction.NAME, ShrinkAction.NAME, ForceMergeAction.NAME);
static final List<String> ORDERED_VALID_WARM_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, ReadOnlyAction.NAME,
AllocateAction.NAME, MigrateAction.NAME, ShrinkAction.NAME, ForceMergeAction.NAME);
static final List<String> ORDERED_VALID_COLD_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, AllocateAction.NAME,
Expand All @@ -56,7 +56,8 @@ public class TimeseriesLifecycleType implements LifecycleType {
COLD_PHASE, VALID_COLD_ACTIONS,
DELETE_PHASE, VALID_DELETE_ACTIONS);

static final Set<String> HOT_ACTIONS_THAT_REQUIRE_ROLLOVER = Sets.newHashSet(ShrinkAction.NAME, ForceMergeAction.NAME);
static final Set<String> HOT_ACTIONS_THAT_REQUIRE_ROLLOVER = Sets.newHashSet(ReadOnlyAction.NAME, ShrinkAction.NAME,
ForceMergeAction.NAME);

private TimeseriesLifecycleType() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ public void testGetNextActionName() {
assertInvalidAction("hot", "foo", new String[] { RolloverAction.NAME });
assertInvalidAction("hot", AllocateAction.NAME, new String[] { RolloverAction.NAME });
assertInvalidAction("hot", DeleteAction.NAME, new String[] { RolloverAction.NAME });
assertInvalidAction("hot", ReadOnlyAction.NAME, new String[] { RolloverAction.NAME });

// Warm Phase
assertNextActionName("warm", SetPriorityAction.NAME, UnfollowAction.NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ public void testDeleteDuringSnapshot() throws Exception {
}

public void testReadOnly() throws Exception {
createIndexWithSettings(client(), index, alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
createIndexWithSettings(client(), index, alias, Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0));
createNewSingletonPolicy(client(), policy, "warm", new ReadOnlyAction());
updatePolicy(index, policy);
Expand All @@ -444,6 +445,35 @@ public void testReadOnly() throws Exception {
});
}

public void testReadOnlyInTheHotPhase() throws Exception {
String originalIndex = index + "-000001";

// add a policy
Map<String, LifecycleAction> hotActions = Map.of(
RolloverAction.NAME, new RolloverAction(null, null, 1L),
ReadOnlyAction.NAME, new ReadOnlyAction());
Map<String, Phase> phases = Map.of(
"hot", new Phase("hot", TimeValue.ZERO, hotActions));
LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policy, phases);
Request createPolicyRequest = new Request("PUT", "_ilm/policy/" + policy);
createPolicyRequest.setJsonEntity("{ \"policy\":" + Strings.toString(lifecyclePolicy) + "}");
client().performRequest(createPolicyRequest);

// then create the index and index a document to trigger rollover
createIndexWithSettings(client(), originalIndex, alias, Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put("index.lifecycle.rollover_alias", alias)
.put("index.lifecycle.name", policy));
index(client(), originalIndex, "_id", "foo", "bar");

assertBusy(() -> {
Map<String, Object> settings = getOnlyIndexSettings(client(), originalIndex);
assertThat(getStepKeyForIndex(client(), originalIndex), equalTo(PhaseCompleteStep.finalStep("hot").getKey()));
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey()), equalTo("true"));
});
}

public void forceMergeActionWithCodec(String codec) throws Exception {
createIndexWithSettings(client(), index, alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,21 @@ setup:
}
}
}
- do:
catch: bad_request
ilm.put_lifecycle:
policy: "my_invalid_lifecycle"
body: |
{
"policy": {
"phases": {
"hot": {
"min_age": "0s",
"actions": {
"readonly": {}
}
}
}
}
}