|
37 | 37 | import org.elasticsearch.core.Nullable;
|
38 | 38 | import org.elasticsearch.core.TimeValue;
|
39 | 39 | import org.elasticsearch.core.Tuple;
|
40 |
| -import org.elasticsearch.index.CloseUtils; |
41 |
| -import org.elasticsearch.index.Index; |
42 | 40 | import org.elasticsearch.index.IndexService;
|
43 | 41 | import org.elasticsearch.index.IndexSettingProvider;
|
44 | 42 | import org.elasticsearch.index.IndexSettingProviders;
|
|
82 | 80 |
|
83 | 81 | import static java.util.Collections.emptyMap;
|
84 | 82 | import static org.elasticsearch.cluster.metadata.MetadataCreateDataStreamService.validateTimestampFieldMapping;
|
85 |
| -import static org.elasticsearch.indices.cluster.IndexRemovalReason.NO_LONGER_ASSIGNED; |
86 | 83 |
|
87 | 84 | /**
|
88 | 85 | * Service responsible for submitting index templates updates
|
@@ -1861,45 +1858,28 @@ static void validateTemplate(Settings validateSettings, CompressedXContent mappi
|
1861 | 1858 | settings = Settings.EMPTY;
|
1862 | 1859 | }
|
1863 | 1860 |
|
1864 |
| - Index createdIndex = null; |
1865 | 1861 | final String temporaryIndexName = UUIDs.randomBase64UUID();
|
1866 |
| - try { |
1867 |
| - // use the provided values, otherwise just pick valid dummy values |
1868 |
| - int dummyPartitionSize = IndexMetadata.INDEX_ROUTING_PARTITION_SIZE_SETTING.get(settings); |
1869 |
| - int dummyShards = settings.getAsInt( |
1870 |
| - IndexMetadata.SETTING_NUMBER_OF_SHARDS, |
1871 |
| - dummyPartitionSize == 1 ? 1 : dummyPartitionSize + 1 |
1872 |
| - ); |
1873 |
| - int shardReplicas = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0); |
1874 |
| - |
1875 |
| - // create index service for parsing and validating "mappings" |
1876 |
| - Settings dummySettings = Settings.builder() |
1877 |
| - .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()) |
1878 |
| - .put(settings) |
1879 |
| - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, dummyShards) |
1880 |
| - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, shardReplicas) |
1881 |
| - .put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) |
1882 |
| - .build(); |
| 1862 | + int dummyPartitionSize = IndexMetadata.INDEX_ROUTING_PARTITION_SIZE_SETTING.get(settings); |
| 1863 | + int dummyShards = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_SHARDS, dummyPartitionSize == 1 ? 1 : dummyPartitionSize + 1); |
| 1864 | + int shardReplicas = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0); |
1883 | 1865 |
|
1884 |
| - final IndexMetadata tmpIndexMetadata = IndexMetadata.builder(temporaryIndexName).settings(dummySettings).build(); |
1885 |
| - IndexService dummyIndexService = indicesService.createIndex(tmpIndexMetadata, Collections.emptyList(), false); |
1886 |
| - createdIndex = dummyIndexService.index(); |
| 1866 | + // create index service for parsing and validating "mappings" |
| 1867 | + Settings dummySettings = Settings.builder() |
| 1868 | + .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()) |
| 1869 | + .put(settings) |
| 1870 | + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, dummyShards) |
| 1871 | + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, shardReplicas) |
| 1872 | + .put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) |
| 1873 | + .build(); |
1887 | 1874 |
|
| 1875 | + final IndexMetadata tmpIndexMetadata = IndexMetadata.builder(temporaryIndexName).settings(dummySettings).build(); |
| 1876 | + |
| 1877 | + indicesService.withTempIndexService(tmpIndexMetadata, dummyIndexService -> { |
1888 | 1878 | if (mappings != null) {
|
1889 | 1879 | dummyIndexService.mapperService().merge(MapperService.SINGLE_MAPPING_NAME, mappings, MergeReason.INDEX_TEMPLATE);
|
1890 | 1880 | }
|
1891 |
| - |
1892 |
| - } finally { |
1893 |
| - if (createdIndex != null) { |
1894 |
| - indicesService.removeIndex( |
1895 |
| - createdIndex, |
1896 |
| - NO_LONGER_ASSIGNED, |
1897 |
| - " created for parsing template mapping", |
1898 |
| - CloseUtils.NO_SHARDS_CREATED_EXECUTOR, |
1899 |
| - ActionListener.noop() |
1900 |
| - ); |
1901 |
| - } |
1902 |
| - } |
| 1881 | + return null; |
| 1882 | + }); |
1903 | 1883 | }
|
1904 | 1884 |
|
1905 | 1885 | private void validate(String name, ComponentTemplate template) {
|
|
0 commit comments