Skip to content

Commit 6e0652a

Browse files
nicktindalldnhatn
authored andcommitted
Avoid throw exception in SyntheticSourceIndexSettingsProvider (elastic#114479)
Co-authored-by: Nhat Nguyen <[email protected]>
1 parent 626356a commit 6e0652a

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

docs/reference/index-modules.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ preview:[]
122122

123123
The number of shards a custom <<mapping-routing-field,routing>> value can go to.
124124
Defaults to 1 and can only be set at index creation time. This value must be less
125-
than the `index.number_of_shards` unless the `index.number_of_shards` value is also 1.
125+
than the `index.number_of_routing_shards` unless the `index.number_of_routing_shards` value is also 1.
126126
See <<routing-index-partition>> for more details about how this setting is used.
127127

128128
[[ccr-index-soft-deletes]]

muted-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,6 @@ tests:
283283
- class: org.elasticsearch.ingest.geoip.DatabaseNodeServiceIT
284284
method: testGzippedDatabase
285285
issue: https://github.com/elastic/elasticsearch/issues/113752
286-
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
287-
method: test {p0=indices.split/40_routing_partition_size/more than 1}
288-
issue: https://github.com/elastic/elasticsearch/issues/113841
289-
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
290-
method: test {p0=indices.split/40_routing_partition_size/nested}
291-
issue: https://github.com/elastic/elasticsearch/issues/113842
292286
- class: org.elasticsearch.threadpool.SimpleThreadPoolIT
293287
method: testThreadPoolMetrics
294288
issue: https://github.com/elastic/elasticsearch/issues/108320

server/src/internalClusterTest/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ public void testPartitionedTemplate() throws Exception {
881881
);
882882
assertThat(
883883
eBadSettings.getMessage(),
884-
containsString("partition size [6] should be a positive number less than the number of shards [5]")
884+
containsString("partition size [6] should be a positive number less than the number of routing shards [5]")
885885
);
886886

887887
// provide an invalid mapping for a partitioned index
@@ -913,7 +913,7 @@ public void testPartitionedTemplate() throws Exception {
913913

914914
assertThat(
915915
eBadIndex.getMessage(),
916-
containsString("partition size [6] should be a positive number less than the number of shards [5]")
916+
containsString("partition size [6] should be a positive number less than the number of routing shards [5]")
917917
);
918918

919919
// finally, create a valid index

server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,7 @@ IndexMetadata build(boolean repair) {
22652265
"routing partition size ["
22662266
+ routingPartitionSize
22672267
+ "] should be a positive number"
2268-
+ " less than the number of shards ["
2268+
+ " less than the number of routing shards ["
22692269
+ getRoutingNumShards()
22702270
+ "] for ["
22712271
+ index

x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/SyntheticSourceIndexSettingsProvider.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,17 @@ boolean newIndexHasSyntheticSourceUsage(
7979
return false;
8080
}
8181

82-
var tmpIndexMetadata = buildIndexMetadataForMapperService(indexName, isTimeSeries, indexTemplateAndCreateRequestSettings);
83-
try (var mapperService = mapperServiceFactory.apply(tmpIndexMetadata)) {
84-
// combinedTemplateMappings can be null when creating system indices
85-
// combinedTemplateMappings can be empty when creating a normal index that doesn't match any template and without mapping.
86-
if (combinedTemplateMappings == null || combinedTemplateMappings.isEmpty()) {
87-
combinedTemplateMappings = List.of(new CompressedXContent("{}"));
82+
try {
83+
var tmpIndexMetadata = buildIndexMetadataForMapperService(indexName, isTimeSeries, indexTemplateAndCreateRequestSettings);
84+
try (var mapperService = mapperServiceFactory.apply(tmpIndexMetadata)) {
85+
// combinedTemplateMappings can be null when creating system indices
86+
// combinedTemplateMappings can be empty when creating a normal index that doesn't match any template and without mapping.
87+
if (combinedTemplateMappings == null || combinedTemplateMappings.isEmpty()) {
88+
combinedTemplateMappings = List.of(new CompressedXContent("{}"));
89+
}
90+
mapperService.merge(MapperService.SINGLE_MAPPING_NAME, combinedTemplateMappings, MapperService.MergeReason.INDEX_TEMPLATE);
91+
return mapperService.documentMapper().sourceMapper().isSynthetic();
8892
}
89-
mapperService.merge(MapperService.SINGLE_MAPPING_NAME, combinedTemplateMappings, MapperService.MergeReason.INDEX_TEMPLATE);
90-
return mapperService.documentMapper().sourceMapper().isSynthetic();
9193
} catch (AssertionError | Exception e) {
9294
// In case invalid mappings or setting are provided, then mapper service creation can fail.
9395
// In that case it is ok to return false here. The index creation will fail anyway later, so need to fallback to stored source.

0 commit comments

Comments
 (0)