Skip to content

Commit

Permalink
[7.14] Migrate to data tiers fix for phase with deactivated migrate …
Browse files Browse the repository at this point in the history
…action (#75102) (#75149)

* Migrate to data tiers fix for phase with deactivated migrate action (#75102)

* Migrate to data tiers fix for phase with deactivated migrate action

This fixes the migration to also take into account explicitly deactivated
migrate actions. A phase with both an allocate action (which we update
to not contain routing rules anymore) and a deactivated migrate action
will not configure any allocation routing rules.

This changes the migrate service to also enable the migrate action.

* Remove the deactivated migrate action

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

* Use es.Map

* More use of es.Map

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
andreidan and elasticmachine committed Jul 8, 2021
1 parent 3bf2ac2 commit 9e4ea9a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,17 @@ private static LifecyclePolicy migrateSingleILMPolicy(String nodeAttrName, Lifec
phase.getName());
}

// we removed the allocate action allocation rules (or the action completely) so let's check if there is an
// explicit migrate action that's disabled, and remove it so ILM can inject an enabled one
if (actionMap.containsKey(MigrateAction.NAME)) {
MigrateAction migrateAction = (MigrateAction) actionMap.get(MigrateAction.NAME);
if (migrateAction.isEnabled() == false) {
actionMap.remove(MigrateAction.NAME);
logger.debug("ILM policy [{}], phase [{}]: removed the deactivated migrate action", lifecyclePolicy.getName(),
phase.getName());
}
}

Phase updatedPhase = new Phase(phase.getName(), phase.getMinimumAge(), actionMap);
Map<String, Phase> updatedPhases =
new HashMap<>(newLifecyclePolicy == null ? lifecyclePolicy.getPhases() : newLifecyclePolicy.getPhases());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata;
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
import org.elasticsearch.xpack.core.ilm.MigrateAction;
import org.elasticsearch.xpack.core.ilm.OperationMode;
import org.elasticsearch.xpack.core.ilm.Phase;
import org.elasticsearch.xpack.core.ilm.SetPriorityAction;
Expand Down Expand Up @@ -123,6 +124,41 @@ public void testMigrateIlmPolicyForIndexWithoutILMMetadata() {
assertThat(migratedColdAllocateAction.getRequire().size(), is(0));
}

public void testMigrateIlmPolicyFOrPhaseWithDeactivatedMigrateAction() {
ShrinkAction shrinkAction = new ShrinkAction(2, null);
AllocateAction warmAllocateAction = new AllocateAction(null, org.elasticsearch.core.Map.of("data", "warm"), null,
org.elasticsearch.core.Map.of("rack", "rack1"));
MigrateAction deactivatedMigrateAction = new MigrateAction(false);

LifecyclePolicy policy = new LifecyclePolicy(lifecycleName,
org.elasticsearch.core.Map.of("warm",
new Phase("warm", TimeValue.ZERO, org.elasticsearch.core.Map.of(shrinkAction.getWriteableName(), shrinkAction,
warmAllocateAction.getWriteableName(), warmAllocateAction, deactivatedMigrateAction.getWriteableName(),
deactivatedMigrateAction))
));
LifecyclePolicyMetadata policyMetadata = new LifecyclePolicyMetadata(policy, Collections.emptyMap(),
randomNonNegativeLong(), randomNonNegativeLong());

ClusterState state = ClusterState.builder(ClusterName.DEFAULT).metadata(Metadata.builder()
.putCustom(IndexLifecycleMetadata.TYPE, new IndexLifecycleMetadata(
Collections.singletonMap(policyMetadata.getName(), policyMetadata), OperationMode.STOPPED))
.put(IndexMetadata.builder(indexName).settings(getBaseIndexSettings())).build())
.build();

Metadata.Builder newMetadata = Metadata.builder(state.metadata());
List<String> migratedPolicies = migrateIlmPolicies(newMetadata, state, "data", REGISTRY, client, null);
assertThat(migratedPolicies.size(), is(1));
assertThat(migratedPolicies.get(0), is(lifecycleName));

ClusterState newState = ClusterState.builder(state).metadata(newMetadata).build();
IndexLifecycleMetadata updatedLifecycleMetadata = newState.metadata().custom(IndexLifecycleMetadata.TYPE);
LifecyclePolicy lifecyclePolicy = updatedLifecycleMetadata.getPolicies().get(lifecycleName);
Map<String, LifecycleAction> warmActions = lifecyclePolicy.getPhases().get("warm").getActions();
assertThat("allocate action in the warm phase didn't specify any number of replicas so it must be removed, together with the " +
"deactivated migrate action", warmActions.size(), is(1));
assertThat(warmActions.get(shrinkAction.getWriteableName()), is(shrinkAction));
}

@SuppressWarnings("unchecked")
public void testMigrateIlmPolicyRefreshesCachedPhase() {
ShrinkAction shrinkAction = new ShrinkAction(2, null);
Expand Down

0 comments on commit 9e4ea9a

Please sign in to comment.