|
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; |
|
83 | 81 |
|
84 | 82 | import static java.util.Collections.emptyMap; |
85 | 83 | import static org.elasticsearch.cluster.metadata.MetadataCreateDataStreamService.validateTimestampFieldMapping; |
86 | | -import static org.elasticsearch.indices.cluster.IndexRemovalReason.NO_LONGER_ASSIGNED; |
87 | 84 |
|
88 | 85 | /** |
89 | 86 | * Service responsible for submitting index templates updates |
@@ -1950,45 +1947,28 @@ static void validateTemplate(Settings validateSettings, CompressedXContent mappi |
1950 | 1947 | settings = Settings.EMPTY; |
1951 | 1948 | } |
1952 | 1949 |
|
1953 | | - Index createdIndex = null; |
1954 | 1950 | final String temporaryIndexName = UUIDs.randomBase64UUID(); |
1955 | | - try { |
1956 | | - // use the provided values, otherwise just pick valid dummy values |
1957 | | - int dummyPartitionSize = IndexMetadata.INDEX_ROUTING_PARTITION_SIZE_SETTING.get(settings); |
1958 | | - int dummyShards = settings.getAsInt( |
1959 | | - IndexMetadata.SETTING_NUMBER_OF_SHARDS, |
1960 | | - dummyPartitionSize == 1 ? 1 : dummyPartitionSize + 1 |
1961 | | - ); |
1962 | | - int shardReplicas = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0); |
1963 | | - |
1964 | | - // create index service for parsing and validating "mappings" |
1965 | | - Settings dummySettings = Settings.builder() |
1966 | | - .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()) |
1967 | | - .put(settings) |
1968 | | - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, dummyShards) |
1969 | | - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, shardReplicas) |
1970 | | - .put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) |
1971 | | - .build(); |
| 1951 | + int dummyPartitionSize = IndexMetadata.INDEX_ROUTING_PARTITION_SIZE_SETTING.get(settings); |
| 1952 | + int dummyShards = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_SHARDS, dummyPartitionSize == 1 ? 1 : dummyPartitionSize + 1); |
| 1953 | + int shardReplicas = settings.getAsInt(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0); |
1972 | 1954 |
|
1973 | | - final IndexMetadata tmpIndexMetadata = IndexMetadata.builder(temporaryIndexName).settings(dummySettings).build(); |
1974 | | - IndexService dummyIndexService = indicesService.createIndex(tmpIndexMetadata, Collections.emptyList(), false); |
1975 | | - createdIndex = dummyIndexService.index(); |
| 1955 | + // create index service for parsing and validating "mappings" |
| 1956 | + Settings dummySettings = Settings.builder() |
| 1957 | + .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()) |
| 1958 | + .put(settings) |
| 1959 | + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, dummyShards) |
| 1960 | + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, shardReplicas) |
| 1961 | + .put(IndexMetadata.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) |
| 1962 | + .build(); |
1976 | 1963 |
|
| 1964 | + final IndexMetadata tmpIndexMetadata = IndexMetadata.builder(temporaryIndexName).settings(dummySettings).build(); |
| 1965 | + |
| 1966 | + indicesService.withTempIndexService(tmpIndexMetadata, dummyIndexService -> { |
1977 | 1967 | if (mappings != null) { |
1978 | 1968 | dummyIndexService.mapperService().merge(MapperService.SINGLE_MAPPING_NAME, mappings, MergeReason.INDEX_TEMPLATE); |
1979 | 1969 | } |
1980 | | - |
1981 | | - } finally { |
1982 | | - if (createdIndex != null) { |
1983 | | - indicesService.removeIndex( |
1984 | | - createdIndex, |
1985 | | - NO_LONGER_ASSIGNED, |
1986 | | - " created for parsing template mapping", |
1987 | | - CloseUtils.NO_SHARDS_CREATED_EXECUTOR, |
1988 | | - ActionListener.noop() |
1989 | | - ); |
1990 | | - } |
1991 | | - } |
| 1970 | + return null; |
| 1971 | + }); |
1992 | 1972 | } |
1993 | 1973 |
|
1994 | 1974 | private void validate(String name, ComponentTemplate template) { |
|
0 commit comments