Skip to content

Commit

Permalink
Avoid throw exception in SyntheticSourceIndexSettingsProvider (elasti…
Browse files Browse the repository at this point in the history
…c#114479)

Co-authored-by: Nhat Nguyen <[email protected]>
  • Loading branch information
nicktindall and dnhatn authored Oct 13, 2024
1 parent e833e7b commit bc0d1d7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/reference/index-modules.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ preview:[]

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

[[ccr-index-soft-deletes]]
Expand Down
6 changes: 0 additions & 6 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,6 @@ tests:
- class: org.elasticsearch.ingest.geoip.DatabaseNodeServiceIT
method: testGzippedDatabase
issue: https://github.com/elastic/elasticsearch/issues/113752
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
method: test {p0=indices.split/40_routing_partition_size/more than 1}
issue: https://github.com/elastic/elasticsearch/issues/113841
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
method: test {p0=indices.split/40_routing_partition_size/nested}
issue: https://github.com/elastic/elasticsearch/issues/113842
- class: org.elasticsearch.threadpool.SimpleThreadPoolIT
method: testThreadPoolMetrics
issue: https://github.com/elastic/elasticsearch/issues/108320
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ public void testPartitionedTemplate() throws Exception {
);
assertThat(
eBadSettings.getMessage(),
containsString("partition size [6] should be a positive number less than the number of shards [5]")
containsString("partition size [6] should be a positive number less than the number of routing shards [5]")
);

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

assertThat(
eBadIndex.getMessage(),
containsString("partition size [6] should be a positive number less than the number of shards [5]")
containsString("partition size [6] should be a positive number less than the number of routing shards [5]")
);

// finally, create a valid index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2265,7 +2265,7 @@ IndexMetadata build(boolean repair) {
"routing partition size ["
+ routingPartitionSize
+ "] should be a positive number"
+ " less than the number of shards ["
+ " less than the number of routing shards ["
+ getRoutingNumShards()
+ "] for ["
+ index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,17 @@ boolean newIndexHasSyntheticSourceUsage(
return false;
}

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

0 comments on commit bc0d1d7

Please sign in to comment.