Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to enforce a default TIER_PREFERENCE #79210

Merged
merged 14 commits into from
Oct 15, 2021
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 @@ -34,6 +34,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 @@ -45,7 +46,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 @@ -66,6 +66,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 @@ -128,6 +129,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 @@ -153,6 +156,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 @@ -481,7 +492,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 @@ -516,7 +528,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 @@ -570,7 +583,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 @@ -634,7 +648,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 @@ -696,7 +710,9 @@ static Map<String, Object> parseV1Mappings(String mappingsJson, List<CompressedX
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 @@ -711,7 +727,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 @@ -754,6 +769,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 @@ -44,6 +45,13 @@ public class DataTier {

public static final Set<String> ALL_DATA_TIERS = 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";
henningandersen marked this conversation as resolved.
Show resolved Hide resolved
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";

private static final Settings DATA_CONTENT_TIER_PREFERENCE_SETTINGS = Settings.builder().put(TIER_PREFERENCE, DATA_CONTENT).build();
Expand All @@ -57,8 +65,8 @@ public class DataTier {
DataTierSettingValidator::getDefaultTierPreference,
Function.identity(),
new DataTierSettingValidator(),
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 @@ -33,6 +33,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 @@ -485,7 +486,9 @@ 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
);

static List<SettingUpgrader<?>> BUILT_IN_SETTING_UPGRADERS = Collections.emptyList();

Expand Down
Loading