Skip to content

Commit 79e2e04

Browse files
authored
Add existing shards allocator settings to failure store allowed list. (#131056)
* Add existing shards allocator settings to failure store allowed list. * Cleanup docstring * Update docs/changelog/131056.yaml * Add comment
1 parent 8eb2a17 commit 79e2e04

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
@@ -35,6 +35,7 @@
3535
import org.elasticsearch.cluster.routing.RoutingTable;
3636
import org.elasticsearch.cluster.routing.allocation.AllocationService;
3737
import org.elasticsearch.cluster.routing.allocation.DataTier;
38+
import org.elasticsearch.cluster.routing.allocation.ExistingShardsAllocator;
3839
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
3940
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
4041
import org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider;
@@ -791,6 +792,55 @@ public boolean overrulesTemplateAndRequestSettings() {
791792
assertThat(aggregatedIndexSettings.get("other_setting"), equalTo("other_value"));
792793
}
793794

795+
/**
796+
* When a failure store index is created, we must filter out any unsupported settings from the create request or from the template that
797+
* may have been provided by users in the create request or from the original data stream template. An exception to this is any settings
798+
* that have been provided by index setting providers which should be considered default values on indices.
799+
*/
800+
public void testAggregateSettingsProviderIsNotFilteredOnFailureStore() {
801+
IndexTemplateMetadata templateMetadata = addMatchingTemplate(builder -> {
802+
builder.settings(Settings.builder().put("template_setting", "value1"));
803+
});
804+
ProjectMetadata projectMetadata = ProjectMetadata.builder(projectId).templates(Map.of("template_1", templateMetadata)).build();
805+
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).putProjectMetadata(projectMetadata).build();
806+
var request = new CreateIndexClusterStateUpdateRequest("create index", projectId, "test", "test").settings(
807+
Settings.builder().put("request_setting", "value2").build()
808+
).isFailureIndex(true);
809+
810+
Settings aggregatedIndexSettings = aggregateIndexSettings(
811+
clusterState,
812+
request,
813+
templateMetadata.settings(),
814+
null,
815+
null,
816+
Settings.EMPTY,
817+
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS,
818+
randomShardLimitService(),
819+
Set.of(new IndexSettingProvider() {
820+
@Override
821+
public Settings getAdditionalIndexSettings(
822+
String indexName,
823+
String dataStreamName,
824+
IndexMode templateIndexMode,
825+
ProjectMetadata projectMetadata,
826+
Instant resolvedAt,
827+
Settings indexTemplateAndCreateRequestSettings,
828+
List<CompressedXContent> combinedTemplateMappings
829+
) {
830+
return Settings.builder().put(ExistingShardsAllocator.EXISTING_SHARDS_ALLOCATOR_SETTING.getKey(), "override").build();
831+
}
832+
833+
@Override
834+
public boolean overrulesTemplateAndRequestSettings() {
835+
return true;
836+
}
837+
})
838+
);
839+
840+
assertThat(aggregatedIndexSettings.get("template_setting"), nullValue());
841+
assertThat(aggregatedIndexSettings.get(ExistingShardsAllocator.EXISTING_SHARDS_ALLOCATOR_SETTING.getKey()), equalTo("override"));
842+
}
843+
794844
public void testAggregateSettingsProviderOverrulesNullFromRequest() {
795845
IndexTemplateMetadata templateMetadata = addMatchingTemplate(builder -> {
796846
builder.settings(Settings.builder().put("template_setting", "value1"));

0 commit comments

Comments
 (0)