Skip to content

Commit

Permalink
Migrate to data tiers routing configures correct default for mounted …
Browse files Browse the repository at this point in the history
…indices (elastic#97936)
  • Loading branch information
andreidan committed Jul 26, 2023
1 parent 6111e95 commit 1f24b9d
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 17 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/97936.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 97936
summary: Migrate to data tiers routing configures correct default for mounted indices
area: ILM+SLM
type: bug
issues:
- 97898
Original file line number Diff line number Diff line change
Expand Up @@ -142,23 +142,6 @@ public static Settings getPreferredTiersConfigurationSettings(String targetTier)
return res;
}

/**
* Returns true iff the given settings have a data tier setting configured
*/
public static boolean isExplicitDataTier(Settings settings) {
/*
* This method can be called before the o.e.n.NodeRoleSettings.NODE_ROLES_SETTING is
* initialized. We do not want to trigger initialization prematurely because that will bake
* the default roles before plugins have had a chance to register them. Therefore,
* to avoid initializing this setting prematurely, we avoid using the actual node roles
* setting instance here in favor of the string.
*/
if (settings.hasValue("node.roles")) {
return settings.getAsList("node.roles").stream().anyMatch(DataTier::validTierName);
}
return false;
}

public static boolean isContentNode(DiscoveryNode discoveryNode) {
return discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE)
|| discoveryNode.getRoles().contains(DiscoveryNodeRole.DATA_ROLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.snapshots.SearchableSnapshotsSettings;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xpack.core.ilm.AllocateAction;
import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata;
Expand All @@ -34,6 +35,7 @@
import org.elasticsearch.xpack.core.ilm.Phase;
import org.elasticsearch.xpack.core.ilm.PhaseExecutionInfo;
import org.elasticsearch.xpack.core.ilm.Step;
import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest;

import java.time.Instant;
import java.util.ArrayList;
Expand Down Expand Up @@ -759,6 +761,15 @@ private static Settings migrateToDefaultTierPreference(ClusterState currentState

boolean isDataStream = currentState.metadata().findDataStreams(indexName).isEmpty() == false;
String convertedTierPreference = isDataStream ? DataTier.DATA_HOT : DataTier.DATA_CONTENT;
if (SearchableSnapshotsSettings.isSearchableSnapshotStore(indexMetadata.getSettings())) {
if (SearchableSnapshotsSettings.isPartialSearchableSnapshotIndex(indexMetadata.getSettings())) {
// partially mounted index
convertedTierPreference = MountSearchableSnapshotRequest.Storage.SHARED_CACHE.defaultDataTiersPreference();
} else {
// fully mounted index
convertedTierPreference = MountSearchableSnapshotRequest.Storage.FULL_COPY.defaultDataTiersPreference();
}
}
newSettingsBuilder.put(TIER_PREFERENCE, convertedTierPreference);
logger.debug("index [{}]: configured setting [{}] to [{}]", indexName, TIER_PREFERENCE, convertedTierPreference);
return newSettingsBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import org.elasticsearch.core.Strings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.snapshots.SearchableSnapshotsSettings;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ParseField;
Expand All @@ -41,6 +43,7 @@
import org.elasticsearch.xpack.core.ilm.Phase;
import org.elasticsearch.xpack.core.ilm.SetPriorityAction;
import org.elasticsearch.xpack.core.ilm.ShrinkAction;
import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest;
import org.junit.Before;

import java.io.ByteArrayInputStream;
Expand All @@ -55,6 +58,7 @@
import static org.elasticsearch.cluster.metadata.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
import static org.elasticsearch.cluster.routing.allocation.DataTier.ENFORCE_DEFAULT_TIER_PREFERENCE;
import static org.elasticsearch.cluster.routing.allocation.DataTier.TIER_PREFERENCE;
import static org.elasticsearch.snapshots.SearchableSnapshotsSettings.SEARCHABLE_SNAPSHOT_STORE_TYPE;
import static org.elasticsearch.xpack.cluster.metadata.MetadataMigrateToDataTiersRoutingService.allocateActionDefinesRoutingRules;
import static org.elasticsearch.xpack.cluster.metadata.MetadataMigrateToDataTiersRoutingService.convertAttributeValueToTierPreference;
import static org.elasticsearch.xpack.cluster.metadata.MetadataMigrateToDataTiersRoutingService.migrateIlmPolicies;
Expand Down Expand Up @@ -826,6 +830,83 @@ public void testMigrateIndices() {
}
}

public void testMigrateMountedIndices() {
{
// migrate "cold" custom routing attribute for fully mounted index
IndexMetadata.Builder partiallyMountedIndex = IndexMetadata.builder("foo")
.settings(
getBaseIndexSettings().put(DATA_ROUTING_REQUIRE_SETTING, "cold")
.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), SEARCHABLE_SNAPSHOT_STORE_TYPE)
.put(SearchableSnapshotsSettings.SNAPSHOT_PARTIAL_SETTING.getKey(), false)
);
ClusterState state = ClusterState.builder(ClusterName.DEFAULT).metadata(Metadata.builder().put(partiallyMountedIndex)).build();

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

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

ClusterState migratedState = ClusterState.builder(ClusterName.DEFAULT).metadata(mb).build();
IndexMetadata migratedIndex = migratedState.metadata().index("foo");
assertThat(migratedIndex.getSettings().get(DATA_ROUTING_INCLUDE_SETTING), nullValue());
assertThat(
migratedIndex.getSettings().get(TIER_PREFERENCE),
is(MountSearchableSnapshotRequest.Storage.FULL_COPY.defaultDataTiersPreference())
);
}

{
// migrate the _wrong_ custom routing attribute for partially mounted index without any tier preference will keep data_frozen
IndexMetadata.Builder partiallyMountedIndex = IndexMetadata.builder("foo")
.settings(
getBaseIndexSettings().put(BOX_ROUTING_REQUIRE_SETTING, "cold")
.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), SEARCHABLE_SNAPSHOT_STORE_TYPE)
.put(SearchableSnapshotsSettings.SNAPSHOT_PARTIAL_SETTING.getKey(), true)
);
ClusterState state = ClusterState.builder(ClusterName.DEFAULT).metadata(Metadata.builder().put(partiallyMountedIndex)).build();

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

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

ClusterState migratedState = ClusterState.builder(ClusterName.DEFAULT).metadata(mb).build();
IndexMetadata migratedIndex = migratedState.metadata().index("foo");
assertThat(migratedIndex.getSettings().get(BOX_ROUTING_REQUIRE_SETTING), is("cold"));
// partially mounted index must remain in `data_frozen`
assertThat(
migratedIndex.getSettings().get(TIER_PREFERENCE),
is(MountSearchableSnapshotRequest.Storage.SHARED_CACHE.defaultDataTiersPreference())
);
}

{
// migrate the _wrong_ custom routing attribute for fully mounted index without any tier preference will configure
// MountSearchableSnapshotRequest.Storage.FULL_COPY.defaultDataTiersPreference()
IndexMetadata.Builder partiallyMountedIndex = IndexMetadata.builder("foo")
.settings(
getBaseIndexSettings().put(BOX_ROUTING_REQUIRE_SETTING, "cold")
.put(IndexModule.INDEX_STORE_TYPE_SETTING.getKey(), SEARCHABLE_SNAPSHOT_STORE_TYPE)
.put(SearchableSnapshotsSettings.SNAPSHOT_PARTIAL_SETTING.getKey(), false)
);
ClusterState state = ClusterState.builder(ClusterName.DEFAULT).metadata(Metadata.builder().put(partiallyMountedIndex)).build();

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

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

ClusterState migratedState = ClusterState.builder(ClusterName.DEFAULT).metadata(mb).build();
IndexMetadata migratedIndex = migratedState.metadata().index("foo");
assertThat(migratedIndex.getSettings().get(BOX_ROUTING_REQUIRE_SETTING), is("cold"));

assertThat(
migratedIndex.getSettings().get(TIER_PREFERENCE),
is(MountSearchableSnapshotRequest.Storage.FULL_COPY.defaultDataTiersPreference())
);
}
}

public void testColdestAttributeIsConvertedToTierPreference() {
// `include` is colder than `require`
{
Expand Down

0 comments on commit 1f24b9d

Please sign in to comment.