Skip to content

Commit

Permalink
Use single data structure to keep track of system indices
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Jul 15, 2024
1 parent 9e20ebc commit 541b8bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class SystemIndexRegistry {
);

private volatile static String[] SYSTEM_INDEX_PATTERNS = new String[0];
volatile static Collection<SystemIndexDescriptor> SYSTEM_INDEX_DESCRIPTORS = Collections.emptyList();
volatile static Map<String, Collection<SystemIndexDescriptor>> SYSTEM_INDEX_DESCRIPTORS_MAP = Collections.emptyMap();

static void register(Map<String, Collection<SystemIndexDescriptor>> pluginAndModulesDescriptors) {
Expand All @@ -58,7 +57,6 @@ static void register(Map<String, Collection<SystemIndexDescriptor>> 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);
}

Expand Down
10 changes: 8 additions & 2 deletions server/src/main/java/org/opensearch/indices/SystemIndices.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public class SystemIndices {

public SystemIndices(Map<String, Collection<SystemIndexDescriptor>> 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())
);
}

/**
Expand Down Expand Up @@ -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<SystemIndexDescriptor> matchingDescriptors = SystemIndexRegistry.SYSTEM_INDEX_DESCRIPTORS.stream()
List<SystemIndexDescriptor> allDescriptors = SystemIndexRegistry.SYSTEM_INDEX_DESCRIPTORS_MAP.values()
.stream()
.flatMap(Collection::stream)
.collect(Collectors.toList());
final List<SystemIndexDescriptor> matchingDescriptors = allDescriptors.stream()
.filter(descriptor -> descriptor.matchesIndexPattern(name))
.collect(Collectors.toList());

Expand Down

0 comments on commit 541b8bd

Please sign in to comment.