Skip to content

ILM: enable the readonly action in the cold phase #69024

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

Merged
merged 2 commits into from
Feb 16, 2021
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
2 changes: 1 addition & 1 deletion docs/reference/ilm/actions/ilm-readonly.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[[ilm-readonly]]
=== Read only

Phases allowed: hot, warm.
Phases allowed: hot, warm, cold, frozen.

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ public class TimeseriesLifecycleType implements LifecycleType {
if (RollupV2.isEnabled()) {
ORDERED_VALID_HOT_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, RolloverAction.NAME,
ReadOnlyAction.NAME, RollupILMAction.NAME, ShrinkAction.NAME, ForceMergeAction.NAME, SearchableSnapshotAction.NAME);
ORDERED_VALID_COLD_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, SearchableSnapshotAction.NAME,
AllocateAction.NAME, MigrateAction.NAME, FreezeAction.NAME, RollupILMAction.NAME);
ORDERED_VALID_COLD_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, ReadOnlyAction.NAME,
SearchableSnapshotAction.NAME, AllocateAction.NAME, MigrateAction.NAME, FreezeAction.NAME, RollupILMAction.NAME);
} else {
ORDERED_VALID_HOT_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, RolloverAction.NAME,
ReadOnlyAction.NAME, ShrinkAction.NAME, ForceMergeAction.NAME, SearchableSnapshotAction.NAME);
ORDERED_VALID_COLD_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, SearchableSnapshotAction.NAME,
AllocateAction.NAME, MigrateAction.NAME, FreezeAction.NAME);
ORDERED_VALID_COLD_ACTIONS = Arrays.asList(SetPriorityAction.NAME, UnfollowAction.NAME, ReadOnlyAction.NAME,
SearchableSnapshotAction.NAME, AllocateAction.NAME, MigrateAction.NAME, FreezeAction.NAME);
}
VALID_HOT_ACTIONS = Sets.newHashSet(ORDERED_VALID_HOT_ACTIONS);
VALID_COLD_ACTIONS = Sets.newHashSet(ORDERED_VALID_COLD_ACTIONS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,10 @@ public void testGetNextActionName() {
assertNextActionName("cold", SetPriorityAction.NAME, null, new String[] { SetPriorityAction.NAME });
assertNextActionName("cold", SetPriorityAction.NAME, null, new String[] {});

assertNextActionName("cold", UnfollowAction.NAME, ReadOnlyAction.NAME,
new String[] {ReadOnlyAction.NAME, SearchableSnapshotAction.NAME, SetPriorityAction.NAME, AllocateAction.NAME});
assertNextActionName("cold", UnfollowAction.NAME, SearchableSnapshotAction.NAME,
new String[] {SearchableSnapshotAction.NAME, AllocateAction.NAME, FreezeAction.NAME});
assertNextActionName("cold", UnfollowAction.NAME, AllocateAction.NAME,
new String[] {SetPriorityAction.NAME, AllocateAction.NAME, FreezeAction.NAME});
assertNextActionName("cold", UnfollowAction.NAME, AllocateAction.NAME,
Expand All @@ -588,7 +592,6 @@ public void testGetNextActionName() {
assertInvalidAction("cold", "foo", new String[] { AllocateAction.NAME });
assertInvalidAction("cold", DeleteAction.NAME, new String[] { AllocateAction.NAME });
assertInvalidAction("cold", ForceMergeAction.NAME, new String[] { AllocateAction.NAME });
assertInvalidAction("cold", ReadOnlyAction.NAME, new String[] { AllocateAction.NAME });
assertInvalidAction("cold", RolloverAction.NAME, new String[] { AllocateAction.NAME });
assertInvalidAction("cold", ShrinkAction.NAME, new String[] { AllocateAction.NAME });

Expand Down Expand Up @@ -740,6 +743,8 @@ private ConcurrentMap<String, LifecycleAction> convertActionNamesToActions(Strin
return new MigrateAction(true);
case RollupILMAction.NAME:
return TEST_ROLLUP_ACTION;
case SearchableSnapshotAction.NAME:
return TEST_SEARCHABLE_SNAPSHOT_ACTION;
}
return new DeleteAction();
}).collect(Collectors.toConcurrentMap(LifecycleAction::getWriteableName, Function.identity()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
import org.elasticsearch.xpack.core.ilm.Phase;
import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep;
import org.elasticsearch.xpack.core.ilm.ReadOnlyAction;
import org.elasticsearch.xpack.core.ilm.RolloverAction;
import org.elasticsearch.xpack.core.ilm.SearchableSnapshotAction;
import org.elasticsearch.xpack.core.ilm.SetPriorityAction;
Expand Down Expand Up @@ -388,49 +387,6 @@ public void testDeleteDuringSnapshot() throws Exception {
assertOK(client().performRequest(new Request("DELETE", "/_snapshot/repo/" + snapName)));
}

public void testReadOnly() throws Exception {
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(client(), index, policy);
assertBusy(() -> {
Map<String, Object> settings = getOnlyIndexSettings(client(), index);
assertThat(getStepKeyForIndex(client(), index), equalTo(PhaseCompleteStep.finalStep("warm").getKey()));
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey()), equalTo("true"));
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_METADATA_SETTING.getKey()), nullValue());
});
}

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
@@ -0,0 +1,95 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.ilm.actions;

import org.elasticsearch.client.Request;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xpack.core.ilm.LifecycleAction;
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
import org.elasticsearch.xpack.core.ilm.Phase;
import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep;
import org.elasticsearch.xpack.core.ilm.ReadOnlyAction;
import org.elasticsearch.xpack.core.ilm.RolloverAction;
import org.junit.Before;

import java.util.Locale;
import java.util.Map;

import static org.elasticsearch.xpack.TimeSeriesRestDriver.createIndexWithSettings;
import static org.elasticsearch.xpack.TimeSeriesRestDriver.createNewSingletonPolicy;
import static org.elasticsearch.xpack.TimeSeriesRestDriver.getOnlyIndexSettings;
import static org.elasticsearch.xpack.TimeSeriesRestDriver.getStepKeyForIndex;
import static org.elasticsearch.xpack.TimeSeriesRestDriver.index;
import static org.elasticsearch.xpack.TimeSeriesRestDriver.updatePolicy;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;

public class ReadonlyActionIT extends ESRestTestCase {
private static final String FAILED_STEP_RETRY_COUNT_FIELD = "failed_step_retry_count";

private String policy;
private String index;
private String alias;

@Before
public void refreshAbstractions() {
policy = "policy-" + randomAlphaOfLength(5);
index = "index-" + randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
alias = "alias-" + randomAlphaOfLength(5);
logger.info("--> running [{}] with index [{}], alias [{}] and policy [{}]", getTestName(), index, alias, policy);
}

public void testReadOnly() throws Exception {
createIndexWithSettings(client(), index, alias, Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0));
String phaseName = randomFrom("warm", "cold", "frozen");
createNewSingletonPolicy(client(), policy, phaseName, new ReadOnlyAction());
updatePolicy(client(), index, policy);
assertBusy(() -> {
Map<String, Object> settings = getOnlyIndexSettings(client(), index);
assertThat(getStepKeyForIndex(client(), index), equalTo(PhaseCompleteStep.finalStep(phaseName).getKey()));
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey()), equalTo("true"));
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_METADATA_SETTING.getKey()), nullValue());
});
}

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(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias)
.put(LifecycleSettings.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"));
});
}
}