Guard adding the index.prefer_v2_templates settings for pre-7.8 nodes (#55546)
If some of the nodes are pre-7.8 nodes, they may not support the `index.prefer_v2_templates` setting (since it exists only on 7.8+). This commit makes sure that we only add this setting to the index's metadata if all of the nodes are 7.8+. Otherwise we get errors like: ``` [ WARN ][o.e.i.c.IndicesClusterStateService] [v7.7.0-3] [test-snapshot-index][2] marking and sending shard failed due to [failed to create index] java.lang.IllegalArgumentException: unknown setting [index.prefer_v2_templates] please check that any required plugins are installed, or check the breaking changes documentation for removed settings at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:544) ~[elasticsearch-7.7.0-SNAPSHOT.jar:7.7.0-SNAPSHOT] at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:489) ~[elasticsearch-7.7.0-SNAPSHOT.jar:7.7.0-SNAPSHOT] at org.elasticsearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:460) ~[elasticsearch-7.7.0-SNAPSHOT.jar:7.7.0-SNAPSHOT] at org.elasticsearch.indices.IndicesService.createIndexService(IndicesService.java:595) ~[elasticsearch-7.7.0-SNAPSHOT.jar:7.7.0-SNAPSHOT] at org.elasticsearch.indices.IndicesService.createIndex(IndicesService.java:549) ~[elasticsearch-7.7.0-SNAPSHOT.jar:7.7.0-SNAPSHOT] at org.elasticsearch.indices.IndicesService.createIndex(IndicesService.java:176) ~[elasticsearch-7.7.0-SNAPSHOT.jar:7.7.0-SNAPSHOT] at org.elasticsearch.indices.cluster.IndicesClusterStateService.createIndices(IndicesClusterStateService.java:484) [elasticsearch-7.7.0-SNAPSHOT.jar:7.7.0-SNAPSHOT] at org.elasticsearch.indices.cluster.IndicesClusterStateService.applyClusterState(IndicesClusterStateService.java:246) [elasticsearch-7.7.0-SNAPSHOT.jar:7.7.0-SNAPSHOT] at org.elasticsearch.cluster.service.ClusterApplierService.lambda$callClusterStateAppliers$5(ClusterApplierService.java:517) [elasticsearch-7.7.0-SNAPSHOT.jar:7.7.0-SNAPSHOT] ``` Relates to #55411 Relates to #53101 Resolves #55539
This commit is contained in:
parent
8e8c6b4aee
commit
55ff146d9b
|
@ -429,7 +429,12 @@ public class MetadataCreateIndexService {
|
||||||
// remove the setting it's temporary and is only relevant once we create the index
|
// remove the setting it's temporary and is only relevant once we create the index
|
||||||
final Settings.Builder settingsBuilder = Settings.builder().put(aggregatedIndexSettings);
|
final Settings.Builder settingsBuilder = Settings.builder().put(aggregatedIndexSettings);
|
||||||
settingsBuilder.remove(IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey());
|
settingsBuilder.remove(IndexMetadata.INDEX_NUMBER_OF_ROUTING_SHARDS_SETTING.getKey());
|
||||||
|
// This setting was added in 7.8, so we can only add it if all nodes are 7.8+, otherwise
|
||||||
|
// the nodes can throw an error about "unknown setting [index.prefer_v2_templates]" when
|
||||||
|
// they go to create the index
|
||||||
|
if (currentState.nodes().mastersFirstStream().allMatch(dn -> dn.getVersion().onOrAfter(Version.V_7_8_0))) {
|
||||||
settingsBuilder.put(IndexMetadata.PREFER_V2_TEMPLATES_SETTING.getKey(), preferV2Templates);
|
settingsBuilder.put(IndexMetadata.PREFER_V2_TEMPLATES_SETTING.getKey(), preferV2Templates);
|
||||||
|
}
|
||||||
final Settings indexSettings = settingsBuilder.build();
|
final Settings indexSettings = settingsBuilder.build();
|
||||||
|
|
||||||
final IndexMetadata.Builder tmpImdBuilder = IndexMetadata.builder(request.index());
|
final IndexMetadata.Builder tmpImdBuilder = IndexMetadata.builder(request.index());
|
||||||
|
|
Loading…
Reference in New Issue