From 541b8bd802df3e90a2acdf6898871f9ee85afe34 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Mon, 15 Jul 2024 14:31:38 -0400 Subject: [PATCH] Use single data structure to keep track of system indices Signed-off-by: Craig Perkins --- .../org/opensearch/indices/SystemIndexRegistry.java | 2 -- .../java/org/opensearch/indices/SystemIndices.java | 10 ++++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/org/opensearch/indices/SystemIndexRegistry.java b/server/src/main/java/org/opensearch/indices/SystemIndexRegistry.java index ba57532502d82..9f24a687ba51a 100644 --- a/server/src/main/java/org/opensearch/indices/SystemIndexRegistry.java +++ b/server/src/main/java/org/opensearch/indices/SystemIndexRegistry.java @@ -45,7 +45,6 @@ public class SystemIndexRegistry { ); private volatile static String[] SYSTEM_INDEX_PATTERNS = new String[0]; - volatile static Collection SYSTEM_INDEX_DESCRIPTORS = Collections.emptyList(); volatile static Map> SYSTEM_INDEX_DESCRIPTORS_MAP = Collections.emptyMap(); static void register(Map> pluginAndModulesDescriptors) { @@ -58,7 +57,6 @@ static void register(Map> pluginAndMod descriptors.add(TASK_INDEX_DESCRIPTOR); SYSTEM_INDEX_DESCRIPTORS_MAP = descriptorsMap; - SYSTEM_INDEX_DESCRIPTORS = descriptors.stream().collect(Collectors.toUnmodifiableList()); SYSTEM_INDEX_PATTERNS = descriptors.stream().map(SystemIndexDescriptor::getIndexPattern).toArray(String[]::new); } diff --git a/server/src/main/java/org/opensearch/indices/SystemIndices.java b/server/src/main/java/org/opensearch/indices/SystemIndices.java index bbf58fe91512f..a0b2cab060214 100644 --- a/server/src/main/java/org/opensearch/indices/SystemIndices.java +++ b/server/src/main/java/org/opensearch/indices/SystemIndices.java @@ -63,7 +63,9 @@ public class SystemIndices { public SystemIndices(Map> pluginAndModulesDescriptors) { SystemIndexRegistry.register(pluginAndModulesDescriptors); - this.runAutomaton = buildCharacterRunAutomaton(SystemIndexRegistry.SYSTEM_INDEX_DESCRIPTORS); + this.runAutomaton = buildCharacterRunAutomaton( + SystemIndexRegistry.SYSTEM_INDEX_DESCRIPTORS_MAP.values().stream().flatMap(Collection::stream).collect(Collectors.toList()) + ); } /** @@ -91,7 +93,11 @@ public boolean isSystemIndex(String indexName) { * @throws IllegalStateException if multiple descriptors match the name */ public @Nullable SystemIndexDescriptor findMatchingDescriptor(String name) { - final List matchingDescriptors = SystemIndexRegistry.SYSTEM_INDEX_DESCRIPTORS.stream() + List allDescriptors = SystemIndexRegistry.SYSTEM_INDEX_DESCRIPTORS_MAP.values() + .stream() + .flatMap(Collection::stream) + .collect(Collectors.toList()); + final List matchingDescriptors = allDescriptors.stream() .filter(descriptor -> descriptor.matchesIndexPattern(name)) .collect(Collectors.toList());