Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.cluster.routing.allocation.DataTier;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.Strings;
Expand All @@ -47,7 +48,6 @@
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.PathUtils;
Expand All @@ -68,6 +68,7 @@
import org.elasticsearch.indices.ShardLimitValidator;
import org.elasticsearch.indices.SystemIndices;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xcontent.NamedXContentRegistry;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -132,6 +133,8 @@ public class MetadataCreateIndexService {
private final boolean forbidPrivateIndexSettings;
private final Set<IndexSettingProvider> indexSettingProviders = new HashSet<>();

private volatile boolean enforceDefaultTierPreference;

public MetadataCreateIndexService(
final Settings settings,
final ClusterService clusterService,
Expand All @@ -157,6 +160,14 @@ public MetadataCreateIndexService(
this.systemIndices = systemIndices;
this.forbidPrivateIndexSettings = forbidPrivateIndexSettings;
this.shardLimitValidator = shardLimitValidator;

enforceDefaultTierPreference = DataTier.ENFORCE_DEFAULT_TIER_PREFERENCE_SETTING.get(settings);
clusterService.getClusterSettings().addSettingsUpdateConsumer(DataTier.ENFORCE_DEFAULT_TIER_PREFERENCE_SETTING,
this::setEnforceDefaultTierPreference);
}

public void setEnforceDefaultTierPreference(boolean enforceDefaultTierPreference) {
this.enforceDefaultTierPreference = enforceDefaultTierPreference;
}

/**
Expand Down Expand Up @@ -490,7 +501,8 @@ private ClusterState applyCreateIndexRequestWithV1Templates(final ClusterState c

final Settings aggregatedIndexSettings =
aggregateIndexSettings(currentState, request, resolveSettings(templates),
null, settings, indexScopedSettings, shardLimitValidator, indexSettingProviders);
null, settings, indexScopedSettings, shardLimitValidator, indexSettingProviders,
this.enforceDefaultTierPreference);
int routingNumShards = getIndexNumberOfRoutingShards(aggregatedIndexSettings, null);
IndexMetadata tmpImd = buildAndValidateTemporaryIndexMetadata(aggregatedIndexSettings, request, routingNumShards);

Expand Down Expand Up @@ -525,7 +537,8 @@ private ClusterState applyCreateIndexRequestWithV2Template(final ClusterState cu
final Settings aggregatedIndexSettings =
aggregateIndexSettings(currentState, request,
resolveSettings(currentState.metadata(), templateName),
null, settings, indexScopedSettings, shardLimitValidator, indexSettingProviders);
null, settings, indexScopedSettings, shardLimitValidator, indexSettingProviders,
this.enforceDefaultTierPreference);
int routingNumShards = getIndexNumberOfRoutingShards(aggregatedIndexSettings, null);
IndexMetadata tmpImd = buildAndValidateTemporaryIndexMetadata(aggregatedIndexSettings, request, routingNumShards);

Expand Down Expand Up @@ -581,7 +594,8 @@ private ClusterState applyCreateIndexRequestForSystemDataStream(final ClusterSta
settings,
indexScopedSettings,
shardLimitValidator,
indexSettingProviders
indexSettingProviders,
this.enforceDefaultTierPreference
);
final int routingNumShards = getIndexNumberOfRoutingShards(aggregatedIndexSettings, null);
final IndexMetadata tmpImd = buildAndValidateTemporaryIndexMetadata(aggregatedIndexSettings, request, routingNumShards);
Expand Down Expand Up @@ -650,7 +664,7 @@ private ClusterState applyCreateIndexRequestWithExistingMetadata(final ClusterSt
}

final Settings aggregatedIndexSettings = aggregateIndexSettings(currentState, request, Settings.EMPTY,
sourceMetadata, settings, indexScopedSettings, shardLimitValidator, indexSettingProviders);
sourceMetadata, settings, indexScopedSettings, shardLimitValidator, indexSettingProviders, this.enforceDefaultTierPreference);
final int routingNumShards = getIndexNumberOfRoutingShards(aggregatedIndexSettings, sourceMetadata);
IndexMetadata tmpImd = buildAndValidateTemporaryIndexMetadata(aggregatedIndexSettings, request, routingNumShards);

Expand Down Expand Up @@ -740,7 +754,9 @@ static Map<String, Map<String, Object>> parseV1Mappings(Map<String, String> requ
static Settings aggregateIndexSettings(ClusterState currentState, CreateIndexClusterStateUpdateRequest request,
Settings combinedTemplateSettings, @Nullable IndexMetadata sourceMetadata, Settings settings,
IndexScopedSettings indexScopedSettings, ShardLimitValidator shardLimitValidator,
Set<IndexSettingProvider> indexSettingProviders) {
Set<IndexSettingProvider> indexSettingProviders, boolean enforceDefaultTierPreference) {
final boolean isDataStreamIndex = request.dataStreamName() != null;

// Create builders for the template and request settings. We transform these into builders
// because we may want settings to be "removed" from these prior to being set on the new
// index (see more comments below)
Expand All @@ -755,7 +771,6 @@ static Settings aggregateIndexSettings(ClusterState currentState, CreateIndexClu
.put(request.settings())
.build();

final boolean isDataStreamIndex = request.dataStreamName() != null;
// Loop through all the explicit index setting providers, adding them to the
// additionalIndexSettings map
for (IndexSettingProvider provider : indexSettingProviders) {
Expand Down Expand Up @@ -798,6 +813,20 @@ static Settings aggregateIndexSettings(ClusterState currentState, CreateIndexClu
// now, put the request settings, so they override templates
indexSettingsBuilder.put(requestSettings.build());

if (sourceMetadata == null) { // not for shrink/split/clone
if (enforceDefaultTierPreference) {
// regardless of any previous logic, we're going to force there
// to be an appropriate non-empty value for the tier preference
String currentTierPreference = indexSettingsBuilder.get(DataTier.TIER_PREFERENCE);
if (DataTier.parseTierList(currentTierPreference).isEmpty()) {
String newTierPreference = isDataStreamIndex ? DataTier.DATA_HOT : DataTier.DATA_CONTENT;
logger.debug("enforcing default [{}] setting for [{}] creation, replacing [{}] with [{}]",
DataTier.TIER_PREFERENCE, request.index(), currentTierPreference, newTierPreference);
indexSettingsBuilder.put(DataTier.TIER_PREFERENCE, newTierPreference);
}
}
}

if (indexSettingsBuilder.get(IndexMetadata.SETTING_VERSION_CREATED) == null) {
final DiscoveryNodes nodes = currentState.nodes();
final Version createdVersion = Version.min(Version.CURRENT, nodes.getSmallestNonClientNodeVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.shard.IndexSettingProvider;
Expand Down Expand Up @@ -45,6 +46,13 @@ public class DataTier {
public static final Set<String> ALL_DATA_TIERS =
org.elasticsearch.core.Set.of(DATA_CONTENT, DATA_HOT, DATA_WARM, DATA_COLD, DATA_FROZEN);

// this setting is for migrating from 7.x (where a tier preference was not required, and did not necessarily
// have a default value), to 8.x (where a tier preference will be required, and a default value will be injected).
// it will be removed as a breaking change in some future version, likely 9.0.
public static final String ENFORCE_DEFAULT_TIER_PREFERENCE = "cluster.routing.allocation.enforce_default_tier_preference";
public static final Setting<Boolean> ENFORCE_DEFAULT_TIER_PREFERENCE_SETTING =
Setting.boolSetting(ENFORCE_DEFAULT_TIER_PREFERENCE, false, Property.Dynamic, Property.NodeScope);

public static final String TIER_PREFERENCE = "index.routing.allocation.include._tier_preference";

public static final Setting.Validator<String> DATA_TIER_SETTING_VALIDATOR = new DataTierSettingValidator();
Expand All @@ -60,8 +68,8 @@ public class DataTier {
DataTierSettingValidator::getDefaultTierPreference,
Function.identity(),
DATA_TIER_SETTING_VALIDATOR,
Setting.Property.Dynamic,
Setting.Property.IndexScope
Property.Dynamic,
Property.IndexScope
);

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.elasticsearch.cluster.metadata.IndexGraveyard;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.routing.OperationRouting;
import org.elasticsearch.cluster.routing.allocation.DataTier;
import org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings;
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
import org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider;
Expand Down Expand Up @@ -566,7 +567,8 @@ public void apply(Settings value, Settings current, Settings previous) {
FsHealthService.REFRESH_INTERVAL_SETTING,
FsHealthService.SLOW_PATH_LOGGING_THRESHOLD_SETTING,
IndexingPressure.MAX_INDEXING_BYTES,
ShardLimitValidator.SETTING_CLUSTER_MAX_SHARDS_PER_NODE_FROZEN)));
ShardLimitValidator.SETTING_CLUSTER_MAX_SHARDS_PER_NODE_FROZEN,
DataTier.ENFORCE_DEFAULT_TIER_PREFERENCE_SETTING)));

public static List<SettingUpgrader<?>> BUILT_IN_SETTING_UPGRADERS = Collections.unmodifiableList(Arrays.asList(
SniffConnectionStrategy.SEARCH_REMOTE_CLUSTER_SEEDS_UPGRADER,
Expand Down
Loading