|
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 |
@@ -1862,45 +1859,28 @@ private static void validateTemplate(Settings validateSettings, CompressedXConte |
1862 | 1859 | settings = Settings.EMPTY; |
1863 | 1860 | } |
1864 | 1861 |
|
1865 | | - Index createdIndex = null; |
1866 | 1862 | final String temporaryIndexName = UUIDs.randomBase64UUID(); |
1867 | | - try { |
1868 | | - // use the provided values, otherwise just pick valid dummy values |
1869 | | - int dummyPartitionSize = IndexMetadata.INDEX_ROUTING_PARTITION_SIZE_SETTING.get(settings); |
1870 | | - int dummyShards = settings.getAsInt( |
1871 | | - IndexMetadata.SETTING_NUMBER_OF_SHARDS, |
1872 | | - dummyPartitionSize == 1 ? 1 : dummyPartitionSize + 1 |
1873 | | - ); |
1874 | | - int shardReplicas = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0); |
1875 | | - |
1876 | | - // create index service for parsing and validating "mappings" |
1877 | | - Settings dummySettings = Settings.builder() |
1878 | | - .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()) |
1879 | | - .put(settings) |
1880 | | - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, dummyShards) |
1881 | | - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, shardReplicas) |
1882 | | - .put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) |
1883 | | - .build(); |
| 1863 | + int dummyPartitionSize = IndexMetadata.INDEX_ROUTING_PARTITION_SIZE_SETTING.get(settings); |
| 1864 | + int dummyShards = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_SHARDS, dummyPartitionSize == 1 ? 1 : dummyPartitionSize + 1); |
| 1865 | + int shardReplicas = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0); |
1884 | 1866 |
|
1885 | | - final IndexMetadata tmpIndexMetadata = IndexMetadata.builder(temporaryIndexName).settings(dummySettings).build(); |
1886 | | - IndexService dummyIndexService = indicesService.createIndex(tmpIndexMetadata, Collections.emptyList(), false); |
1887 | | - createdIndex = dummyIndexService.index(); |
| 1867 | + // create index service for parsing and validating "mappings" |
| 1868 | + Settings dummySettings = Settings.builder() |
| 1869 | + .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()) |
| 1870 | + .put(settings) |
| 1871 | + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, dummyShards) |
| 1872 | + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, shardReplicas) |
| 1873 | + .put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) |
| 1874 | + .build(); |
1888 | 1875 |
|
| 1876 | + final IndexMetadata tmpIndexMetadata = IndexMetadata.builder(temporaryIndexName).settings(dummySettings).build(); |
| 1877 | + |
| 1878 | + indicesService.withTempIndexService(tmpIndexMetadata, dummyIndexService -> { |
1889 | 1879 | if (mappings != null) { |
1890 | 1880 | dummyIndexService.mapperService().merge(MapperService.SINGLE_MAPPING_NAME, mappings, MergeReason.INDEX_TEMPLATE); |
1891 | 1881 | } |
1892 | | - |
1893 | | - } finally { |
1894 | | - if (createdIndex != null) { |
1895 | | - indicesService.removeIndex( |
1896 | | - createdIndex, |
1897 | | - NO_LONGER_ASSIGNED, |
1898 | | - " created for parsing template mapping", |
1899 | | - CloseUtils.NO_SHARDS_CREATED_EXECUTOR, |
1900 | | - ActionListener.noop() |
1901 | | - ); |
1902 | | - } |
1903 | | - } |
| 1882 | + return null; |
| 1883 | + }); |
1904 | 1884 | } |
1905 | 1885 |
|
1906 | 1886 | private void validate(String name, ComponentTemplate template) { |
|
0 commit comments