Skip to content

Commit 34b9a3f

Browse files
committed
Add existing shards allocator settings to failure store allowed list. (elastic#131056)
* Add existing shards allocator settings to failure store allowed list. * Cleanup docstring * Update docs/changelog/131056.yaml * Add comment
1 parent f1f88eb commit 34b9a3f

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

docs/changelog/131056.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 131056
2+
summary: Add existing shards allocator settings to failure store allowed list
3+
area: Data streams
4+
type: bug
5+
issues: []

server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamFailureStoreDefinition.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch.cluster.metadata;
1111

1212
import org.elasticsearch.cluster.routing.allocation.DataTier;
13+
import org.elasticsearch.cluster.routing.allocation.ExistingShardsAllocator;
1314
import org.elasticsearch.common.compress.CompressedXContent;
1415
import org.elasticsearch.common.settings.Setting;
1516
import org.elasticsearch.common.settings.Settings;
@@ -40,7 +41,9 @@ public class DataStreamFailureStoreDefinition {
4041
IndexMetadata.SETTING_NUMBER_OF_SHARDS,
4142
IndexMetadata.SETTING_NUMBER_OF_REPLICAS,
4243
IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS,
43-
IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey()
44+
IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(),
45+
// Different recovery implementations may be provided on the index which need to be preserved.
46+
ExistingShardsAllocator.EXISTING_SHARDS_ALLOCATOR_SETTING.getKey()
4447
);
4548
public static final Set<String> SUPPORTED_USER_SETTINGS_PREFIXES = Set.of(
4649
IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_PREFIX + ".",

server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexServiceTests.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.cluster.routing.RoutingTable;
3131
import org.elasticsearch.cluster.routing.allocation.AllocationService;
3232
import org.elasticsearch.cluster.routing.allocation.DataTier;
33+
import org.elasticsearch.cluster.routing.allocation.ExistingShardsAllocator;
3334
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
3435
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
3536
import org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider;
@@ -735,6 +736,55 @@ public boolean overrulesTemplateAndRequestSettings() {
735736
assertThat(aggregatedIndexSettings.get("other_setting"), equalTo("other_value"));
736737
}
737738

739+
/**
740+
* When a failure store index is created, we must filter out any unsupported settings from the create request or from the template that
741+
* may have been provided by users in the create request or from the original data stream template. An exception to this is any settings
742+
* that have been provided by index setting providers which should be considered default values on indices.
743+
*/
744+
public void testAggregateSettingsProviderIsNotFilteredOnFailureStore() {
745+
IndexTemplateMetadata templateMetadata = addMatchingTemplate(builder -> {
746+
builder.settings(Settings.builder().put("template_setting", "value1"));
747+
});
748+
ProjectMetadata projectMetadata = ProjectMetadata.builder(projectId).templates(Map.of("template_1", templateMetadata)).build();
749+
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).putProjectMetadata(projectMetadata).build();
750+
var request = new CreateIndexClusterStateUpdateRequest("create index", projectId, "test", "test").settings(
751+
Settings.builder().put("request_setting", "value2").build()
752+
).isFailureIndex(true);
753+
754+
Settings aggregatedIndexSettings = aggregateIndexSettings(
755+
clusterState,
756+
request,
757+
templateMetadata.settings(),
758+
null,
759+
null,
760+
Settings.EMPTY,
761+
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS,
762+
randomShardLimitService(),
763+
Set.of(new IndexSettingProvider() {
764+
@Override
765+
public Settings getAdditionalIndexSettings(
766+
String indexName,
767+
String dataStreamName,
768+
IndexMode templateIndexMode,
769+
ProjectMetadata projectMetadata,
770+
Instant resolvedAt,
771+
Settings indexTemplateAndCreateRequestSettings,
772+
List<CompressedXContent> combinedTemplateMappings
773+
) {
774+
return Settings.builder().put(ExistingShardsAllocator.EXISTING_SHARDS_ALLOCATOR_SETTING.getKey(), "override").build();
775+
}
776+
777+
@Override
778+
public boolean overrulesTemplateAndRequestSettings() {
779+
return true;
780+
}
781+
})
782+
);
783+
784+
assertThat(aggregatedIndexSettings.get("template_setting"), nullValue());
785+
assertThat(aggregatedIndexSettings.get(ExistingShardsAllocator.EXISTING_SHARDS_ALLOCATOR_SETTING.getKey()), equalTo("override"));
786+
}
787+
738788
public void testAggregateSettingsProviderOverrulesNullFromRequest() {
739789
IndexTemplateMetadata templateMetadata = addMatchingTemplate(builder -> {
740790
builder.settings(Settings.builder().put("template_setting", "value1"));

0 commit comments

Comments
 (0)