From 8ba6f55e0a7b3751355eb7e52f17a9cb80f2b7f7 Mon Sep 17 00:00:00 2001 From: Andrei Dan Date: Tue, 7 Dec 2021 20:27:29 +0000 Subject: [PATCH] Allow the `unfollow` action in the frozen phase (#81434) * Allow the `unfollow` action in the frozen phase The `unfollow` actions is injected before some of the actions that yield the managed index unsafe to use in a CCR environment (eg. rollover, searchable_snapshot, shrink). This was not allowed in the `frozen` phase, however we do have the `searchable_snapshot` action available. This commit makes the `unfollow` action available in the frozen phase. --- .../core/ilm/TimeseriesLifecycleType.java | 2 +- .../ilm/TimeseriesLifecycleTypeTests.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java index 1603ac7004334..53c112aaa4683 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java @@ -80,7 +80,7 @@ public class TimeseriesLifecycleType implements LifecycleType { FreezeAction.NAME, RollupV2.isEnabled() ? RollupILMAction.NAME : null ).filter(Objects::nonNull).collect(toList()); - static final List ORDERED_VALID_FROZEN_ACTIONS = Arrays.asList(SearchableSnapshotAction.NAME); + static final List ORDERED_VALID_FROZEN_ACTIONS = Arrays.asList(UnfollowAction.NAME, SearchableSnapshotAction.NAME); static final List ORDERED_VALID_DELETE_ACTIONS = Arrays.asList(WaitForSnapshotAction.NAME, DeleteAction.NAME); static final Set VALID_HOT_ACTIONS = Sets.newHashSet(ORDERED_VALID_HOT_ACTIONS); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java index 330e63f873660..ef6ab83604ba4 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java @@ -40,6 +40,7 @@ import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.ORDERED_VALID_WARM_ACTIONS; import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.VALID_COLD_ACTIONS; import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.VALID_DELETE_ACTIONS; +import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.VALID_FROZEN_ACTIONS; import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.VALID_HOT_ACTIONS; import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.VALID_WARM_ACTIONS; import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.WARM_PHASE; @@ -174,6 +175,28 @@ public void testValidateColdPhase() { } } + public void testValidateFrozenPhase() { + LifecycleAction invalidAction = null; + Map actions = randomSubsetOf(VALID_FROZEN_ACTIONS).stream() + .map(this::getTestAction) + .collect(Collectors.toMap(LifecycleAction::getWriteableName, Function.identity())); + if (randomBoolean()) { + invalidAction = getTestAction(randomFrom("rollover", "delete", "forcemerge", "shrink")); + actions.put(invalidAction.getWriteableName(), invalidAction); + } + Map frozenPhase = Collections.singletonMap("frozen", new Phase("frozen", TimeValue.ZERO, actions)); + + if (invalidAction != null) { + Exception e = expectThrows( + IllegalArgumentException.class, + () -> TimeseriesLifecycleType.INSTANCE.validate(frozenPhase.values()) + ); + assertThat(e.getMessage(), equalTo("invalid action [" + invalidAction.getWriteableName() + "] defined in phase [frozen]")); + } else { + TimeseriesLifecycleType.INSTANCE.validate(frozenPhase.values()); + } + } + public void testValidateDeletePhase() { LifecycleAction invalidAction = null; Map actions = VALID_DELETE_ACTIONS.stream() @@ -358,6 +381,8 @@ public void testGetOrderedPhasesInsertsMigrateAction() { public void testUnfollowInjections() { assertTrue(isUnfollowInjected("hot", RolloverAction.NAME)); assertTrue(isUnfollowInjected("warm", ShrinkAction.NAME)); + assertTrue(isUnfollowInjected("cold", SearchableSnapshotAction.NAME)); + assertTrue(isUnfollowInjected("frozen", SearchableSnapshotAction.NAME)); assertFalse(isUnfollowInjected("hot", SetPriorityAction.NAME)); assertFalse(isUnfollowInjected("warm", SetPriorityAction.NAME));