Skip to content

Commit

Permalink
[ILM] Fix the migrate to tiers service and migrate action tiers confi…
Browse files Browse the repository at this point in the history
…guration (elastic#95934) (elastic#95965)

The migrate action (although no allowed in the frozen phase) would seem
to convert `frozen` to `data_frozen,data_cold,data_warm,data_hot` tier
configuration. As the migrate action is not allowed in the frozen phase
this would never happen, however the code is confusing as it seems like
it could.

The migrate to data tiers routing service shared the code used by the
`migrate` action that converted `frozen` to
`data_frozen,data_cold,data_warm,data_hot` if it would encounter an
index without any `_tier_preference` setting  but with a custom node
attribute configured to `frozen` e.g. `include.data: frozen`

As part of elastic#84758 we have
seen frozen indices with the `data_frozen,data_cold,data_warm,data_hot`
tier preference however we could never reproduce it.

Relates to elastic#84758
  • Loading branch information
andreidan authored May 9, 2023
1 parent ad84ba6 commit 78790f1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/95934.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 95934
summary: "[ILM] Fix the migrate to tiers service and migrate action tiers configuration"
area: ILM+SLM
type: bug
issues: []
6 changes: 2 additions & 4 deletions docs/reference/ilm/actions/ilm-migrate.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ to `data_cold,data_warm,data_hot`. This moves the index to nodes in the
The migrate action is not allowed in the frozen phase. The frozen phase directly
mounts the searchable snapshot using a
<<tier-preference-allocation-filter, `index.routing.allocation.include._tier_preference`>>
of `data_frozen,data_cold,data_warm,data_hot`. This moves the index to nodes in the
<<frozen-tier, frozen tier>>. If there are no nodes in the frozen tier, it falls back to the
<<cold-tier, cold>> tier, then the <<warm-tier, warm>> tier, then finally the <<hot-tier, hot>>
tier.
of `data_frozen`. This moves the index to nodes in the
<<frozen-tier, frozen tier>>.

The migrate action is not allowed in the hot phase.
The initial index allocation is performed <<data-tier-allocation, automatically>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,15 @@ public class DataTier {
final Map<String, Settings> tmpSettings = new HashMap<>();
for (int i = 0, ordered_frozen_to_hot_tiersSize = ORDERED_FROZEN_TO_HOT_TIERS.size(); i < ordered_frozen_to_hot_tiersSize; i++) {
String tier = ORDERED_FROZEN_TO_HOT_TIERS.get(i);
final String prefTierString = String.join(",", ORDERED_FROZEN_TO_HOT_TIERS.subList(i, ORDERED_FROZEN_TO_HOT_TIERS.size()))
.intern();
tmp.put(tier, prefTierString);
tmpSettings.put(tier, Settings.builder().put(DataTier.TIER_PREFERENCE, prefTierString).build());
if (tier.equals(DATA_FROZEN)) {
tmp.put(tier, DATA_FROZEN);
tmpSettings.put(DATA_FROZEN, Settings.builder().put(DataTier.TIER_PREFERENCE, DATA_FROZEN).build());
} else {
final String prefTierString = String.join(",", ORDERED_FROZEN_TO_HOT_TIERS.subList(i, ORDERED_FROZEN_TO_HOT_TIERS.size()))
.intern();
tmp.put(tier, prefTierString);
tmpSettings.put(tier, Settings.builder().put(DataTier.TIER_PREFERENCE, prefTierString).build());
}
}
PREFERENCE_TIER_CONFIGURATIONS = Map.copyOf(tmp);
PREFERENCE_TIER_CONFIGURATION_SETTINGS = Map.copyOf(tmpSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import static org.elasticsearch.cluster.routing.allocation.DataTier.DATA_COLD;
import static org.elasticsearch.cluster.routing.allocation.DataTier.DATA_FROZEN;
import static org.elasticsearch.cluster.routing.allocation.DataTier.DATA_HOT;
import static org.elasticsearch.cluster.routing.allocation.DataTier.DATA_WARM;
import static org.elasticsearch.cluster.routing.allocation.DataTier.getPreferredTiersConfiguration;
Expand Down Expand Up @@ -120,6 +121,7 @@ public void testGetPreferredTiersConfiguration() {
assertThat(getPreferredTiersConfiguration(DATA_HOT), is(DATA_HOT));
assertThat(getPreferredTiersConfiguration(DATA_WARM), is(DATA_WARM + "," + DATA_HOT));
assertThat(getPreferredTiersConfiguration(DATA_COLD), is(DATA_COLD + "," + DATA_WARM + "," + DATA_HOT));
assertThat(getPreferredTiersConfiguration(DATA_FROZEN), is(DATA_FROZEN));
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> getPreferredTiersConfiguration("no_tier"));
assertThat(exception.getMessage(), is("invalid data tier [no_tier]"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void testMigrateIlmPolicyForIndexWithoutILMMetadata() {
assertThat(migratedColdAllocateAction.getRequire().size(), is(0));
}

public void testMigrateIlmPolicyFOrPhaseWithDeactivatedMigrateAction() {
public void testMigrateIlmPolicyForPhaseWithDeactivatedMigrateAction() {
ShrinkAction shrinkAction = new ShrinkAction(2, null);
AllocateAction warmAllocateAction = new AllocateAction(null, null, Map.of("data", "warm"), null, Map.of("rack", "rack1"));

Expand Down Expand Up @@ -511,7 +511,7 @@ public void testAllocateActionDefinesRoutingRules() {
}

public void testConvertAttributeValueToTierPreference() {
assertThat(convertAttributeValueToTierPreference("frozen"), is("data_frozen,data_cold,data_warm,data_hot"));
assertThat(convertAttributeValueToTierPreference("frozen"), is("data_frozen"));
assertThat(convertAttributeValueToTierPreference("cold"), is("data_cold,data_warm,data_hot"));
assertThat(convertAttributeValueToTierPreference("warm"), is("data_warm,data_hot"));
assertThat(convertAttributeValueToTierPreference("hot"), is("data_hot"));
Expand Down Expand Up @@ -560,6 +560,26 @@ public void testMigrateIndices() {
assertThat(migratedIndex.getSettings().get(TIER_PREFERENCE), is("data_warm,data_hot"));
}

{
// test the migration of `include.data: frozen` configuration to the equivalent _tier_preference routing
IndexMetadata.Builder indexWithFrozenDataAttribute = IndexMetadata.builder("indexWithFrozenDataAttribute")
.settings(getBaseIndexSettings().put(DATA_ROUTING_INCLUDE_SETTING, "frozen"));
ClusterState state = ClusterState.builder(ClusterName.DEFAULT)
.metadata(Metadata.builder().put(indexWithFrozenDataAttribute))
.build();

Metadata.Builder mb = Metadata.builder(state.metadata());

List<String> migratedIndices = migrateIndices(mb, state, "data");
assertThat(migratedIndices.size(), is(1));
assertThat(migratedIndices.get(0), is("indexWithFrozenDataAttribute"));

ClusterState migratedState = ClusterState.builder(ClusterName.DEFAULT).metadata(mb).build();
IndexMetadata migratedIndex = migratedState.metadata().index("indexWithFrozenDataAttribute");
assertThat(migratedIndex.getSettings().get(DATA_ROUTING_INCLUDE_SETTING), nullValue());
assertThat(migratedIndex.getSettings().get(TIER_PREFERENCE), is("data_frozen"));
}

{
// since the index has a _tier_preference configuration the migrated index should still contain it and have ALL the `data`
// attributes routing removed
Expand Down

0 comments on commit 78790f1

Please sign in to comment.