Skip to content

Commit

Permalink
Allow the unfollow action in the frozen phase (#81434) (#81495)
Browse files Browse the repository at this point in the history
* 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.

(cherry picked from commit 8ba6f55)
Signed-off-by: Andrei Dan <[email protected]>

# Conflicts:
#	x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java
  • Loading branch information
andreidan authored Dec 8, 2021
1 parent 969e565 commit 3798ff6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class TimeseriesLifecycleType implements LifecycleType {
FreezeAction.NAME,
RollupV2.isEnabled() ? RollupILMAction.NAME : null
).filter(Objects::nonNull).collect(toList());
static final List<String> ORDERED_VALID_FROZEN_ACTIONS = Arrays.asList(SearchableSnapshotAction.NAME);
static final List<String> ORDERED_VALID_FROZEN_ACTIONS = Arrays.asList(UnfollowAction.NAME, SearchableSnapshotAction.NAME);
static final List<String> ORDERED_VALID_DELETE_ACTIONS = Arrays.asList(WaitForSnapshotAction.NAME, DeleteAction.NAME);

static final Set<String> VALID_HOT_ACTIONS = Sets.newHashSet(ORDERED_VALID_HOT_ACTIONS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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;
Expand Down Expand Up @@ -197,6 +198,30 @@ public void testFreezeActionDeprecationLog() {
);
}

public void testValidateFrozenPhase() {
LifecycleAction invalidAction = null;
Map<String, LifecycleAction> actions = randomSubsetOf(VALID_FROZEN_ACTIONS).stream()
.map(this::getTestAction)
.collect(Collectors.toMap(LifecycleAction::getWriteableName, Function.identity()));
// regardless of the randomised actions, we must have a SearchableSnapshotAction in frozen
actions.put(SearchableSnapshotAction.NAME, getTestAction(SearchableSnapshotAction.NAME));
if (randomBoolean()) {
invalidAction = getTestAction(randomFrom("rollover", "delete", "forcemerge", "shrink"));
actions.put(invalidAction.getWriteableName(), invalidAction);
}
Map<String, Phase> 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<String, LifecycleAction> actions = VALID_DELETE_ACTIONS.stream()
Expand Down Expand Up @@ -417,6 +442,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));
Expand Down

0 comments on commit 3798ff6

Please sign in to comment.