Skip to content

Commit ffbb769

Browse files
authored
Fix exceptions in index pattern conflict checks (elastic#134231) (elastic#134291)
We already fixed an issue with this in elastic#128362 but apparently another instance of the unnecessary determinization was hiding elsewhere and in its current state throws exceptions starting with Lucene 10 on complext patterns. This change adds the same fix as elastic#128362 and adds a test that would have triggered this. Closes elastic#133652
1 parent 240e362 commit ffbb769

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

docs/changelog/134231.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 134231
2+
summary: Fix unnecessary determinization in index pattern conflict checks
3+
area: Indices APIs
4+
type: bug
5+
issues:
6+
- 133652

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -995,12 +995,16 @@ static Map<String, List<String>> findConflictingV2Templates(
995995
boolean checkPriority,
996996
long priority
997997
) {
998-
Automaton v1automaton = Regex.simpleMatchToAutomaton(indexPatterns.toArray(Strings.EMPTY_ARRAY));
998+
// No need to determinize the automaton, as it is only used to check for intersection with another automaton.
999+
// Determinization is avoided because it can fail or become very costly due to state explosion.
1000+
Automaton v1automaton = Regex.simpleMatchToNonDeterminizedAutomaton(indexPatterns.toArray(Strings.EMPTY_ARRAY));
9991001
Map<String, List<String>> overlappingTemplates = new TreeMap<>();
10001002
for (Map.Entry<String, ComposableIndexTemplate> entry : project.templatesV2().entrySet()) {
10011003
String name = entry.getKey();
10021004
ComposableIndexTemplate template = entry.getValue();
1003-
Automaton v2automaton = Regex.simpleMatchToAutomaton(template.indexPatterns().toArray(Strings.EMPTY_ARRAY));
1005+
// No need to determinize the automaton, as it is only used to check for intersection with another automaton.
1006+
// Determinization is avoided because it can fail or become very costly due to state explosion.
1007+
Automaton v2automaton = Regex.simpleMatchToNonDeterminizedAutomaton(template.indexPatterns().toArray(Strings.EMPTY_ARRAY));
10041008
if (Operations.isEmpty(Operations.intersection(v1automaton, v2automaton)) == false) {
10051009
if (checkPriority == false || priority == template.priorityOrZero()) {
10061010
logger.debug(

server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateServiceTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,6 +2495,23 @@ public void testV2TemplateOverlaps() throws Exception {
24952495
}
24962496
}
24972497

2498+
/**
2499+
* test that using complex index patterns doesn't run into a too_complex_to_determinize_exception,
2500+
* see https://github.com/elastic/elasticsearch/issues/133652
2501+
*/
2502+
public void testFindConflictingTemplates_complex_pattern() throws Exception {
2503+
ProjectMetadata initialProject = ProjectMetadata.builder(randomProjectIdOrDefault()).build();
2504+
List<String> complexPattern = new ArrayList<>();
2505+
for (int i = 1; i < 20; i++) {
2506+
complexPattern.add("cluster-somenamespace-*-app" + i + "*");
2507+
}
2508+
ComposableIndexTemplate template = ComposableIndexTemplate.builder().indexPatterns(complexPattern).build();
2509+
MetadataIndexTemplateService service = getMetadataIndexTemplateService();
2510+
ProjectMetadata project = service.addIndexTemplateV2(initialProject, false, "foo", template);
2511+
assertEquals(0, MetadataIndexTemplateService.findConflictingV1Templates(project, "foo", complexPattern).size());
2512+
assertEquals(0, MetadataIndexTemplateService.findConflictingV2Templates(project, "foo", complexPattern).size());
2513+
}
2514+
24982515
/**
24992516
* Tests to add two component templates but ignores both with is valid
25002517
*

0 commit comments

Comments
 (0)