Skip to content

Commit 4713dfb

Browse files
committed
Fix exceptions in index pattern conflict checks
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 abc660f commit 4713dfb

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,12 +1077,16 @@ static Map<String, List<String>> findConflictingV2Templates(
10771077
boolean checkPriority,
10781078
long priority
10791079
) {
1080-
Automaton v1automaton = Regex.simpleMatchToAutomaton(indexPatterns.toArray(Strings.EMPTY_ARRAY));
1080+
// No need to determinize the automaton, as it is only used to check for intersection with another automaton.
1081+
// Determinization is avoided because it can fail or become very costly due to state explosion.
1082+
Automaton v1automaton = Regex.simpleMatchToNonDeterminizedAutomaton(indexPatterns.toArray(Strings.EMPTY_ARRAY));
10811083
Map<String, List<String>> overlappingTemplates = new TreeMap<>();
10821084
for (Map.Entry<String, ComposableIndexTemplate> entry : templatesV2.entrySet()) {
10831085
String name = entry.getKey();
10841086
ComposableIndexTemplate template = entry.getValue();
1085-
Automaton v2automaton = Regex.simpleMatchToAutomaton(template.indexPatterns().toArray(Strings.EMPTY_ARRAY));
1087+
// No need to determinize the automaton, as it is only used to check for intersection with another automaton.
1088+
// Determinization is avoided because it can fail or become very costly due to state explosion.
1089+
Automaton v2automaton = Regex.simpleMatchToNonDeterminizedAutomaton(template.indexPatterns().toArray(Strings.EMPTY_ARRAY));
10861090
if (Operations.isEmpty(Operations.intersection(v1automaton, v2automaton)) == false) {
10871091
if (checkPriority == false || priority == template.priorityOrZero()) {
10881092
logger.debug(

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,6 +2526,31 @@ public void testV2TemplateOverlaps() throws Exception {
25262526
}
25272527
}
25282528

2529+
/**
2530+
* test that using complex index patterns doesn't run into a too_complex_to_determinize_exception,
2531+
* see https://github.com/elastic/elasticsearch/issues/133652
2532+
*/
2533+
public void testFindConflictingTemplates_complex_pattern() throws Exception {
2534+
ProjectMetadata initialProject = ProjectMetadata.builder(randomProjectIdOrDefault()).build();
2535+
List<String> complexPattern = new ArrayList<>();
2536+
for (int i = 1; i < 20; i++) {
2537+
complexPattern.add("cluster-somenamespace-*-app" + i + "*");
2538+
}
2539+
ComposableIndexTemplate template = ComposableIndexTemplate.builder().indexPatterns(complexPattern).build();
2540+
MetadataIndexTemplateService service = getMetadataIndexTemplateService();
2541+
ProjectMetadata project = service.addIndexTemplateV2(initialProject, false, "foo", template);
2542+
assertEquals(0, MetadataIndexTemplateService.findConflictingV1Templates(
2543+
project,
2544+
"foo",
2545+
complexPattern
2546+
).size());
2547+
assertEquals(0, MetadataIndexTemplateService.findConflictingV2Templates(
2548+
project,
2549+
"foo",
2550+
complexPattern
2551+
).size());
2552+
}
2553+
25292554
/**
25302555
* Tests to add two component templates but ignores both with is valid
25312556
*

0 commit comments

Comments
 (0)