From 4713dfbe81dbf07c7155b677b6d11d70ec662f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Fri, 5 Sep 2025 16:38:23 +0200 Subject: [PATCH 1/4] Fix exceptions in index pattern conflict checks We already fixed an issue with this in #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 #128362 and adds a test that would have triggered this. Closes #133652 --- .../MetadataIndexTemplateService.java | 8 ++++-- .../MetadataIndexTemplateServiceTests.java | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java index a3dbd34605c18..d7ce16acc8af4 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java @@ -1077,12 +1077,16 @@ static Map> findConflictingV2Templates( boolean checkPriority, long priority ) { - Automaton v1automaton = Regex.simpleMatchToAutomaton(indexPatterns.toArray(Strings.EMPTY_ARRAY)); + // No need to determinize the automaton, as it is only used to check for intersection with another automaton. + // Determinization is avoided because it can fail or become very costly due to state explosion. + Automaton v1automaton = Regex.simpleMatchToNonDeterminizedAutomaton(indexPatterns.toArray(Strings.EMPTY_ARRAY)); Map> overlappingTemplates = new TreeMap<>(); for (Map.Entry entry : templatesV2.entrySet()) { String name = entry.getKey(); ComposableIndexTemplate template = entry.getValue(); - Automaton v2automaton = Regex.simpleMatchToAutomaton(template.indexPatterns().toArray(Strings.EMPTY_ARRAY)); + // No need to determinize the automaton, as it is only used to check for intersection with another automaton. + // Determinization is avoided because it can fail or become very costly due to state explosion. + Automaton v2automaton = Regex.simpleMatchToNonDeterminizedAutomaton(template.indexPatterns().toArray(Strings.EMPTY_ARRAY)); if (Operations.isEmpty(Operations.intersection(v1automaton, v2automaton)) == false) { if (checkPriority == false || priority == template.priorityOrZero()) { logger.debug( diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateServiceTests.java index 50d868dd9c35b..7be0ea479431d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateServiceTests.java @@ -2526,6 +2526,31 @@ public void testV2TemplateOverlaps() throws Exception { } } + /** + * test that using complex index patterns doesn't run into a too_complex_to_determinize_exception, + * see https://github.com/elastic/elasticsearch/issues/133652 + */ + public void testFindConflictingTemplates_complex_pattern() throws Exception { + ProjectMetadata initialProject = ProjectMetadata.builder(randomProjectIdOrDefault()).build(); + List complexPattern = new ArrayList<>(); + for (int i = 1; i < 20; i++) { + complexPattern.add("cluster-somenamespace-*-app" + i + "*"); + } + ComposableIndexTemplate template = ComposableIndexTemplate.builder().indexPatterns(complexPattern).build(); + MetadataIndexTemplateService service = getMetadataIndexTemplateService(); + ProjectMetadata project = service.addIndexTemplateV2(initialProject, false, "foo", template); + assertEquals(0, MetadataIndexTemplateService.findConflictingV1Templates( + project, + "foo", + complexPattern + ).size()); + assertEquals(0, MetadataIndexTemplateService.findConflictingV2Templates( + project, + "foo", + complexPattern + ).size()); + } + /** * Tests to add two component templates but ignores both with is valid * From d523121bef269a310eebd65cbd4c7eec03da064d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Fri, 5 Sep 2025 17:34:35 +0200 Subject: [PATCH 2/4] Update docs/changelog/134231.yaml --- docs/changelog/134231.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docs/changelog/134231.yaml diff --git a/docs/changelog/134231.yaml b/docs/changelog/134231.yaml new file mode 100644 index 0000000000000..47feb55ff7fb8 --- /dev/null +++ b/docs/changelog/134231.yaml @@ -0,0 +1,6 @@ +pr: 134231 +summary: Fix exceptions in index pattern conflict checks +area: Indices APIs +type: bug +issues: + - 133652 From 0d326cfbdacec915318e90f00d5bf2f77a469704 Mon Sep 17 00:00:00 2001 From: elasticsearchmachine Date: Fri, 5 Sep 2025 15:44:33 +0000 Subject: [PATCH 3/4] [CI] Auto commit changes from spotless --- .../metadata/MetadataIndexTemplateServiceTests.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateServiceTests.java index 7be0ea479431d..8805654969661 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateServiceTests.java @@ -2539,16 +2539,8 @@ public void testFindConflictingTemplates_complex_pattern() throws Exception { ComposableIndexTemplate template = ComposableIndexTemplate.builder().indexPatterns(complexPattern).build(); MetadataIndexTemplateService service = getMetadataIndexTemplateService(); ProjectMetadata project = service.addIndexTemplateV2(initialProject, false, "foo", template); - assertEquals(0, MetadataIndexTemplateService.findConflictingV1Templates( - project, - "foo", - complexPattern - ).size()); - assertEquals(0, MetadataIndexTemplateService.findConflictingV2Templates( - project, - "foo", - complexPattern - ).size()); + assertEquals(0, MetadataIndexTemplateService.findConflictingV1Templates(project, "foo", complexPattern).size()); + assertEquals(0, MetadataIndexTemplateService.findConflictingV2Templates(project, "foo", complexPattern).size()); } /** From c4ed78a469b5641986ca8c29e1684d017fe0a7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Fri, 5 Sep 2025 21:22:33 +0200 Subject: [PATCH 4/4] Update 134231.yaml --- docs/changelog/134231.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog/134231.yaml b/docs/changelog/134231.yaml index 47feb55ff7fb8..dd0e7f5f84f0d 100644 --- a/docs/changelog/134231.yaml +++ b/docs/changelog/134231.yaml @@ -1,5 +1,5 @@ pr: 134231 -summary: Fix exceptions in index pattern conflict checks +summary: Fix unnecessary determinization in index pattern conflict checks area: Indices APIs type: bug issues: