Skip to content

Commit

Permalink
Rename INDEX_ROUTING_PREFER to TIER_PREFERENCE (#78411) (#78479)
Browse files Browse the repository at this point in the history
  • Loading branch information
joegallo authored Sep 29, 2021
1 parent 278906c commit 9bf8c73
Show file tree
Hide file tree
Showing 35 changed files with 122 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void testScaleFromEmptyWarm(boolean allocatable) throws Exception {
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 6)
.put(INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING.getKey(), "0ms")
.put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, allocatable ? "data_hot" : "data_content")
.put(DataTierAllocationDecider.TIER_PREFERENCE, allocatable ? "data_hot" : "data_content")
.build()
).setWaitForActiveShards(allocatable ? ActiveShardCount.DEFAULT : ActiveShardCount.NONE)
);
Expand All @@ -151,7 +151,7 @@ private void testScaleFromEmptyWarm(boolean allocatable) throws Exception {
.indices()
.updateSettings(
new UpdateSettingsRequest(indexName).settings(
Settings.builder().put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, "data_warm,data_hot")
Settings.builder().put(DataTierAllocationDecider.TIER_PREFERENCE, "data_warm,data_hot")
)
)
.actionGet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,7 @@ public boolean canRemainOnlyHighestTierPreference(ShardRouting shard, RoutingAll
) != Decision.NO;
if (result
&& nodes.isEmpty()
&& Strings.hasText(
DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(indexMetadata(shard, allocation).getSettings())
)) {
&& Strings.hasText(DataTierAllocationDecider.TIER_PREFERENCE_SETTING.get(indexMetadata(shard, allocation).getSettings()))) {
// The data tier decider allows a shard to remain on a lower preference tier when no nodes exists on higher preference
// tiers.
// Here we ensure that if our policy governs the highest preference tier, we assume the shard needs to move to that tier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class FrozenUtils {
public static boolean isFrozenIndex(Settings indexSettings) {
String tierPreference = DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(indexSettings);
String tierPreference = DataTierAllocationDecider.TIER_PREFERENCE_SETTING.get(indexSettings);
String[] preferredTiers = DataTierAllocationDecider.parseTierList(tierPreference);
if (preferredTiers.length >= 1 && preferredTiers[0].equals(DataTier.DATA_FROZEN)) {
assert preferredTiers.length == 1 : "frozen tier preference must be frozen only";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ private IndexMetadata moveToCold(IndexMetadata imd) {
overrideSetting(
imd,
builder,
DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING,
DataTierAllocationDecider.TIER_PREFERENCE_SETTING,
randomFrom(DataTier.DATA_COLD, DataTier.DATA_COLD + "," + DataTier.DATA_HOT)
);
return IndexMetadata.builder(imd).settings(builder).build();
Expand Down Expand Up @@ -625,7 +625,7 @@ private static ClusterState addRandomIndices(int minShards, int maxShardCopies,
String[] tierSettingNames = new String[] {
DataTierAllocationDecider.INDEX_ROUTING_REQUIRE,
DataTierAllocationDecider.INDEX_ROUTING_INCLUDE,
DataTierAllocationDecider.INDEX_ROUTING_PREFER };
DataTierAllocationDecider.TIER_PREFERENCE };
int shards = randomIntBetween(minShards, 20);
Metadata.Builder builder = Metadata.builder();
RoutingTable.Builder routingTableBuilder = RoutingTable.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl

public ClusterState addPreference(IndexMetadata indexMetadata, ClusterState clusterState, String preference) {
IndexMetadata indexMetadataWithPreference = IndexMetadata.builder(indexMetadata)
.settings(Settings.builder().put(indexMetadata.getSettings()).put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, preference))
.settings(Settings.builder().put(indexMetadata.getSettings()).put(DataTierAllocationDecider.TIER_PREFERENCE, preference))
.build();

return ClusterState.builder(clusterState)
Expand Down Expand Up @@ -556,7 +556,7 @@ public void testNeedsThisTier() {
Metadata.Builder metaBuilder = Metadata.builder();
Settings.Builder settings = settings(Version.CURRENT);
if (randomBoolean()) {
settings.put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, randomBoolean() ? DataTier.DATA_HOT : "data_hot,data_warm");
settings.put(DataTierAllocationDecider.TIER_PREFERENCE, randomBoolean() ? DataTier.DATA_HOT : "data_hot,data_warm");
}
IndexMetadata indexMetadata = IndexMetadata.builder(randomAlphaOfLength(5))
.settings(settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static String randomNonFrozenTierPreference() {
public static Settings indexSettings(String tierPreference) {
Settings.Builder settings = Settings.builder()
.put(randomAlphaOfLength(10), randomLong())
.put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, tierPreference)
.put(DataTierAllocationDecider.TIER_PREFERENCE, tierPreference)
.put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT);
// pass setting validator.
if (Objects.equals(tierPreference, DataTier.DATA_FROZEN)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void testDefaultIndexAllocateToContent() {
client().admin().indices().prepareCreate(index).setWaitForActiveShards(0).get();

Settings idxSettings = client().admin().indices().prepareGetIndex().addIndices(index).get().getSettings().get(index);
assertThat(DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(idxSettings), equalTo(DataTier.DATA_CONTENT));
assertThat(DataTierAllocationDecider.TIER_PREFERENCE_SETTING.get(idxSettings), equalTo(DataTier.DATA_CONTENT));

// index should be red
assertThat(client().admin().cluster().prepareHealth(index).get().getIndices().get(index).getStatus(),
Expand All @@ -75,7 +75,7 @@ public void testOverrideDefaultAllocation() {
ensureGreen();

String setting = randomBoolean() ? DataTierAllocationDecider.INDEX_ROUTING_REQUIRE :
DataTierAllocationDecider.INDEX_ROUTING_PREFER;
DataTierAllocationDecider.TIER_PREFERENCE;

client().admin().indices().prepareCreate(index)
.setWaitForActiveShards(0)
Expand All @@ -99,13 +99,13 @@ public void testRequestSettingOverridesAllocation() {
client().admin().indices().prepareCreate(index)
.setWaitForActiveShards(0)
.setSettings(Settings.builder()
.putNull(DataTierAllocationDecider.INDEX_ROUTING_PREFER))
.putNull(DataTierAllocationDecider.TIER_PREFERENCE))
.get();

Settings idxSettings = client().admin().indices().prepareGetIndex().addIndices(index).get().getSettings().get(index);
assertThat(DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(idxSettings), equalTo(""));
assertThat(DataTierAllocationDecider.TIER_PREFERENCE_SETTING.get(idxSettings), equalTo(""));
// Even the key shouldn't exist if it has been nulled out
assertFalse(idxSettings.keySet().toString(), idxSettings.keySet().contains(DataTierAllocationDecider.INDEX_ROUTING_PREFER));
assertFalse(idxSettings.keySet().toString(), idxSettings.keySet().contains(DataTierAllocationDecider.TIER_PREFERENCE));

// index should be yellow
logger.info("--> waiting for {} to be yellow", index);
Expand All @@ -121,9 +121,9 @@ public void testRequestSettingOverridesAllocation() {
.get();

idxSettings = client().admin().indices().prepareGetIndex().addIndices(index).get().getSettings().get(index);
assertThat(DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(idxSettings), equalTo(""));
assertThat(DataTierAllocationDecider.TIER_PREFERENCE_SETTING.get(idxSettings), equalTo(""));
// The key should not be put in place since it was overridden
assertFalse(idxSettings.keySet().contains(DataTierAllocationDecider.INDEX_ROUTING_PREFER));
assertFalse(idxSettings.keySet().contains(DataTierAllocationDecider.TIER_PREFERENCE));
assertThat(DataTierAllocationDecider.INDEX_ROUTING_REQUIRE_SETTING.get(idxSettings), equalTo(DataTier.DATA_COLD));

// index should be yellow
Expand All @@ -144,7 +144,7 @@ public void testShrinkStaysOnTier() {
.setSettings(Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 2)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, "data_warm"))
.put(DataTierAllocationDecider.TIER_PREFERENCE, "data_warm"))
.get();

client().admin().indices().prepareAddBlock(IndexMetadata.APIBlock.READ_ONLY, index).get();
Expand All @@ -160,7 +160,7 @@ public void testShrinkStaysOnTier() {
Settings idxSettings = client().admin().indices().prepareGetIndex().addIndices(index + "-shrunk")
.get().getSettings().get(index + "-shrunk");
// It should inherit the setting of its originator
assertThat(DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(idxSettings), equalTo(DataTier.DATA_WARM));
assertThat(DataTierAllocationDecider.TIER_PREFERENCE_SETTING.get(idxSettings), equalTo(DataTier.DATA_WARM));

// Required or else the test cleanup fails because it can't delete the indices
client().admin().indices().prepareUpdateSettings(index, index + "-shrunk")
Expand All @@ -184,15 +184,15 @@ public void testTemplateOverridesDefaults() {
client().admin().indices().prepareCreate(index).setWaitForActiveShards(0).get();

Settings idxSettings = client().admin().indices().prepareGetIndex().addIndices(index).get().getSettings().get(index);
assertThat(idxSettings.keySet().contains(DataTierAllocationDecider.INDEX_ROUTING_PREFER), equalTo(false));
assertThat(idxSettings.keySet().contains(DataTierAllocationDecider.TIER_PREFERENCE), equalTo(false));

// index should be yellow
ensureYellow(index);

client().admin().indices().prepareDelete(index).get();

t = new Template(Settings.builder()
.putNull(DataTierAllocationDecider.INDEX_ROUTING_PREFER)
.putNull(DataTierAllocationDecider.TIER_PREFERENCE)
.build(), null, null);
ct = new ComposableIndexTemplate.Builder().indexPatterns(Collections.singletonList(index))
.template(t).build();
Expand All @@ -202,7 +202,7 @@ public void testTemplateOverridesDefaults() {
client().admin().indices().prepareCreate(index).setWaitForActiveShards(0).get();

idxSettings = client().admin().indices().prepareGetIndex().addIndices(index).get().getSettings().get(index);
assertThat(idxSettings.keySet().contains(DataTierAllocationDecider.INDEX_ROUTING_PREFER), equalTo(false));
assertThat(idxSettings.keySet().contains(DataTierAllocationDecider.TIER_PREFERENCE), equalTo(false));

ensureYellow(index);
}
Expand All @@ -214,7 +214,7 @@ public void testDataTierTelemetry() {

client().admin().indices().prepareCreate(index)
.setSettings(Settings.builder()
.put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, "data_hot")
.put(DataTierAllocationDecider.TIER_PREFERENCE, "data_hot")
.put("index.number_of_shards", 2)
.put("index.number_of_replicas", 0))
.setWaitForActiveShards(0)
Expand Down Expand Up @@ -280,15 +280,15 @@ public void testIllegalOnFrozen() {
() -> createIndex(index, Settings.builder()
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 0)
.put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, DataTier.DATA_FROZEN)
.put(DataTierAllocationDecider.TIER_PREFERENCE, DataTier.DATA_FROZEN)
.build()));
assertThat(e.getMessage(), equalTo("[data_frozen] tier can only be used for partial searchable snapshots"));

String initialTier = randomFrom(DataTier.DATA_HOT, DataTier.DATA_WARM, DataTier.DATA_COLD);
createIndex(index, Settings.builder()
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 0)
.put(DataTierAllocationDecider.INDEX_ROUTING_PREFER, initialTier)
.put(DataTierAllocationDecider.TIER_PREFERENCE, initialTier)
.build());

IllegalArgumentException e2 = expectThrows(IllegalArgumentException.class, () -> updatePreference(DataTier.DATA_FROZEN));
Expand All @@ -299,7 +299,7 @@ public void testIllegalOnFrozen() {

private void updatePreference(String tier) {
client().admin().indices().updateSettings(new UpdateSettingsRequest(index)
.settings(Map.of(DataTierAllocationDecider.INDEX_ROUTING_PREFER, tier))).actionGet();
.settings(Map.of(DataTierAllocationDecider.TIER_PREFERENCE, tier))).actionGet();
}

private DataTiersFeatureSetUsage getUsage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.List;
import org.elasticsearch.index.IndexModule;
Expand Down Expand Up @@ -51,25 +52,25 @@ public class DataTierAllocationDecider extends AllocationDecider {
public static final String CLUSTER_ROUTING_EXCLUDE = "cluster.routing.allocation.exclude._tier";
public static final String INDEX_ROUTING_REQUIRE = "index.routing.allocation.require._tier";
public static final String INDEX_ROUTING_INCLUDE = "index.routing.allocation.include._tier";
public static final String INDEX_ROUTING_PREFER = "index.routing.allocation.include._tier_preference";
public static final String INDEX_ROUTING_EXCLUDE = "index.routing.allocation.exclude._tier";
public static final String TIER_PREFERENCE = "index.routing.allocation.include._tier_preference";

private static final DataTierValidator VALIDATOR = new DataTierValidator();
public static final Setting<String> CLUSTER_ROUTING_REQUIRE_SETTING = Setting.simpleString(CLUSTER_ROUTING_REQUIRE,
DataTierAllocationDecider::validateTierSetting, Setting.Property.Dynamic, Setting.Property.NodeScope, Setting.Property.Deprecated);
DataTierAllocationDecider::validateTierSetting, Property.Dynamic, Property.NodeScope, Property.Deprecated);
public static final Setting<String> CLUSTER_ROUTING_INCLUDE_SETTING = Setting.simpleString(CLUSTER_ROUTING_INCLUDE,
DataTierAllocationDecider::validateTierSetting, Setting.Property.Dynamic, Setting.Property.NodeScope, Setting.Property.Deprecated);
DataTierAllocationDecider::validateTierSetting, Property.Dynamic, Property.NodeScope, Property.Deprecated);
public static final Setting<String> CLUSTER_ROUTING_EXCLUDE_SETTING = Setting.simpleString(CLUSTER_ROUTING_EXCLUDE,
DataTierAllocationDecider::validateTierSetting, Setting.Property.Dynamic, Setting.Property.NodeScope, Setting.Property.Deprecated);
DataTierAllocationDecider::validateTierSetting, Property.Dynamic, Property.NodeScope, Property.Deprecated);
public static final Setting<String> INDEX_ROUTING_REQUIRE_SETTING = Setting.simpleString(INDEX_ROUTING_REQUIRE,
VALIDATOR, Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.Deprecated);
VALIDATOR, Property.Dynamic, Property.IndexScope, Property.Deprecated);
public static final Setting<String> INDEX_ROUTING_INCLUDE_SETTING = Setting.simpleString(INDEX_ROUTING_INCLUDE,
VALIDATOR, Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.Deprecated);
VALIDATOR, Property.Dynamic, Property.IndexScope, Property.Deprecated);
public static final Setting<String> INDEX_ROUTING_EXCLUDE_SETTING = Setting.simpleString(INDEX_ROUTING_EXCLUDE,
VALIDATOR, Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.Deprecated);
public static final Setting<String> INDEX_ROUTING_PREFER_SETTING = new Setting<String>(new Setting.SimpleKey(INDEX_ROUTING_PREFER),
VALIDATOR, Property.Dynamic, Property.IndexScope, Property.Deprecated);
public static final Setting<String> TIER_PREFERENCE_SETTING = new Setting<String>(new Setting.SimpleKey(TIER_PREFERENCE),
DataTierValidator::getDefaultTierPreference, Function.identity(), VALIDATOR,
Setting.Property.Dynamic, Setting.Property.IndexScope) {
Property.Dynamic, Property.IndexScope) {
@Override
public String get(Settings settings) {
if (SearchableSnapshotsSettings.isPartialSearchableSnapshotIndex(settings)) {
Expand All @@ -88,16 +89,18 @@ private static void validateTierSetting(String setting) {
for (String s : setting.split(",")) {
if (DataTier.validTierName(s) == false) {
throw new IllegalArgumentException(
"invalid tier names found in [" + setting + "] allowed values are " + DataTier.ALL_DATA_TIERS);
"invalid tier names found in [" + setting + "] allowed values are " + DataTier.ALL_DATA_TIERS);
}
}
}
}

private static class DataTierValidator implements Setting.Validator<String> {
private static final Collection<Setting<?>> dependencies =
List.of(IndexModule.INDEX_STORE_TYPE_SETTING,
SearchableSnapshotsConstants.SNAPSHOT_PARTIAL_SETTING);

private static final Collection<Setting<?>> dependencies = List.of(
IndexModule.INDEX_STORE_TYPE_SETTING,
SearchableSnapshotsConstants.SNAPSHOT_PARTIAL_SETTING
);

public static String getDefaultTierPreference(Settings settings) {
if (SearchableSnapshotsSettings.isPartialSearchableSnapshotIndex(settings)) {
Expand Down Expand Up @@ -202,7 +205,7 @@ public Decision shouldFilter(IndexMetadata indexMd, Set<DiscoveryNodeRole> roles
private Decision shouldIndexPreferTier(IndexMetadata indexMetadata, Set<DiscoveryNodeRole> roles,
PreferredTierFunction preferredTierFunction, RoutingAllocation allocation) {
Settings indexSettings = indexMetadata.getSettings();
String tierPreference = INDEX_ROUTING_PREFER_SETTING.get(indexSettings);
String tierPreference = TIER_PREFERENCE_SETTING.get(indexSettings);

if (Strings.hasText(tierPreference)) {
Optional<String> tier = preferredTierFunction.apply(tierPreference, allocation.nodes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public ValueFetcher valueFetcher(SearchExecutionContext context, String format)
*/
private String getTierPreference(SearchExecutionContext context) {
Settings settings = context.getIndexSettings().getSettings();
String value = DataTierAllocationDecider.INDEX_ROUTING_PREFER_SETTING.get(settings);
String value = DataTierAllocationDecider.TIER_PREFERENCE_SETTING.get(settings);

if (Strings.hasText(value) == false) {
return null;
Expand Down
Loading

0 comments on commit 9bf8c73

Please sign in to comment.