Skip to content

Commit 88cd3df

Browse files
committed
[Metadata Immutability] Change different indices lookup objects from array type to lists
Changed the arrays to immutable List instances, added new versions of the getters which returns List instances. Resolves #8647 Signed-off-by: Abdul Muneer Kolarkunnu <muneer.kolarkunnu@netapp.com>
1 parent f53e220 commit 88cd3df

File tree

8 files changed

+24
-72
lines changed

8 files changed

+24
-72
lines changed

CHANGELOG-3.0.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2525
- Add task completion count in search backpressure stats API ([#10028](https://github.com/opensearch-project/OpenSearch/pull/10028/))
2626
- Deprecate CamelCase `PathHierarchy` tokenizer name in favor to lowercase `path_hierarchy` ([#10894](https://github.com/opensearch-project/OpenSearch/pull/10894))
2727
- Breaking change: Do not request "search_pipelines" metrics by default in NodesInfoRequest ([#12497](https://github.com/opensearch-project/OpenSearch/pull/12497))
28+
- Modify the utility APIs in the Metadata to get different indices ([#14557](https://github.com/opensearch-project/OpenSearch/pull/14557))
2829

2930
### Deprecated
3031

CHANGELOG.md

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1313
- Add batching supported processor base type AbstractBatchingProcessor ([#14554](https://github.com/opensearch-project/OpenSearch/pull/14554))
1414
- Fix race condition while parsing derived fields from search definition ([14445](https://github.com/opensearch-project/OpenSearch/pull/14445))
1515
- Add allowlist setting for ingest-common processors ([#14439](https://github.com/opensearch-project/OpenSearch/issues/14439))
16-
- Add new APIs in the Metadata to get different indices in the form of List ([#14557](https://github.com/opensearch-project/OpenSearch/pull/14557))
1716

1817
### Dependencies
1918
- Bump `org.gradle.test-retry` from 1.5.8 to 1.5.9 ([#13442](https://github.com/opensearch-project/OpenSearch/pull/13442))

server/src/main/java/org/opensearch/action/admin/cluster/health/TransportClusterHealthAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ private ClusterHealthResponse clusterHealth(
493493
String[] concreteIndices;
494494
if (request.level().equals(ClusterHealthRequest.Level.AWARENESS_ATTRIBUTES)) {
495495
String awarenessAttribute = request.getAwarenessAttribute();
496-
concreteIndices = clusterState.getMetadata().getConcreteAllIndices();
496+
concreteIndices = clusterState.getMetadata().getConcreteAllIndices().toArray(String[]::new);
497497
return new ClusterHealthResponse(
498498
clusterState.getClusterName().value(),
499499
clusterState,

server/src/main/java/org/opensearch/cluster/health/ClusterStateHealth.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public final class ClusterStateHealth implements Iterable<ClusterIndexHealth>, W
7373
* @param clusterState The current cluster state. Must not be null.
7474
*/
7575
public ClusterStateHealth(final ClusterState clusterState) {
76-
this(clusterState, clusterState.metadata().getConcreteAllIndices());
76+
this(clusterState, clusterState.metadata().getConcreteAllIndices().toArray(String[]::new));
7777
}
7878

7979
/**

server/src/main/java/org/opensearch/cluster/metadata/IndexNameExpressionResolver.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ public Map<String, Set<String>> resolveSearchRoutingAllIndices(Metadata metadata
706706
if (routing != null) {
707707
Set<String> r = Sets.newHashSet(Strings.splitStringByCommaToArray(routing));
708708
Map<String, Set<String>> routings = new HashMap<>();
709-
Set<String> concreteIndices = metadata.getConcreteAllIndicesList();
709+
Set<String> concreteIndices = metadata.getConcreteAllIndices();
710710
for (String index : concreteIndices) {
711711
routings.put(index, r);
712712
}
@@ -746,7 +746,7 @@ static boolean isExplicitAllPattern(Collection<String> aliasesOrIndices) {
746746
*/
747747
boolean isPatternMatchingAllIndices(Metadata metadata, String[] indicesOrAliases, String[] concreteIndices) {
748748
// if we end up matching on all indices, check, if its a wildcard parameter, or a "-something" structure
749-
if (concreteIndices.length == metadata.getConcreteAllIndicesList().size() && indicesOrAliases.length > 0) {
749+
if (concreteIndices.length == metadata.getConcreteAllIndices().size() && indicesOrAliases.length > 0) {
750750

751751
// we might have something like /-test1,+test1 that would identify all indices
752752
// or something like /-test1 with test1 index missing and IndicesOptions.lenient()
@@ -1182,17 +1182,17 @@ private boolean isEmptyOrTrivialWildcard(List<String> expressions) {
11821182

11831183
private static List<String> resolveEmptyOrTrivialWildcard(IndicesOptions options, Metadata metadata) {
11841184
if (options.expandWildcardsOpen() && options.expandWildcardsClosed() && options.expandWildcardsHidden()) {
1185-
return new ArrayList<>(metadata.getConcreteAllIndicesList());
1185+
return List.copyOf(metadata.getConcreteAllIndices());
11861186
} else if (options.expandWildcardsOpen() && options.expandWildcardsClosed()) {
1187-
return metadata.getConcreteVisibleIndicesList();
1187+
return metadata.getConcreteVisibleIndices();
11881188
} else if (options.expandWildcardsOpen() && options.expandWildcardsHidden()) {
1189-
return metadata.getConcreteAllOpenIndicesList();
1189+
return metadata.getConcreteAllOpenIndices();
11901190
} else if (options.expandWildcardsOpen()) {
1191-
return metadata.getConcreteVisibleOpenIndicesList();
1191+
return metadata.getConcreteVisibleOpenIndices();
11921192
} else if (options.expandWildcardsClosed() && options.expandWildcardsHidden()) {
1193-
return metadata.getConcreteAllClosedIndicesList();
1193+
return metadata.getConcreteAllClosedIndices();
11941194
} else if (options.expandWildcardsClosed()) {
1195-
return metadata.getConcreteVisibleClosedIndicesList();
1195+
return metadata.getConcreteVisibleClosedIndices();
11961196
} else {
11971197
return Collections.emptyList();
11981198
}

server/src/main/java/org/opensearch/cluster/metadata/Metadata.java

+12-54
Original file line numberDiff line numberDiff line change
@@ -601,86 +601,44 @@ private static String mergePaths(String path, String field) {
601601
}
602602

603603
/**
604-
* Returns all the concrete indices in the format of array of strings.
604+
* Returns all the concrete indices.
605605
*/
606-
public String[] getConcreteAllIndices() {
607-
return allIndices.toArray(String[]::new);
608-
}
609-
610-
/**
611-
* Returns all the concrete indices in the format of set of strings.
612-
*/
613-
public Set<String> getConcreteAllIndicesList() {
606+
public Set<String> getConcreteAllIndices() {
614607
return allIndices;
615608
}
616609

617610
/**
618-
* Returns all the concrete indices that are not hidden in the format of array of strings.
619-
*/
620-
public String[] getConcreteVisibleIndices() {
621-
return visibleIndices.toArray(String[]::new);
622-
}
623-
624-
/**
625-
* Returns all the concrete indices that are not hidden in the format of list of strings.
611+
* Returns all the concrete indices that are not hidden.
626612
*/
627-
public List<String> getConcreteVisibleIndicesList() {
613+
public List<String> getConcreteVisibleIndices() {
628614
return visibleIndices;
629615
}
630616

631617
/**
632-
* Returns all of the concrete indices that are open in the format of array of strings.
633-
*/
634-
public String[] getConcreteAllOpenIndices() {
635-
return allOpenIndices.toArray(String[]::new);
636-
}
637-
638-
/**
639-
* Returns all of the concrete indices that are open in the format of list of strings.
618+
* Returns all of the concrete indices that are open.
640619
*/
641-
public List<String> getConcreteAllOpenIndicesList() {
620+
public List<String> getConcreteAllOpenIndices() {
642621
return allOpenIndices;
643622
}
644623

645624
/**
646-
* Returns all of the concrete indices that are open and not hidden in the format of array of strings.
625+
* Returns all of the concrete indices that are open and not hidden.
647626
*/
648-
public String[] getConcreteVisibleOpenIndices() {
649-
return visibleOpenIndices.toArray(String[]::new);
650-
}
651-
652-
/**
653-
* Returns all of the concrete indices that are open and not hidden in the format of list of strings.
654-
*/
655-
public List<String> getConcreteVisibleOpenIndicesList() {
627+
public List<String> getConcreteVisibleOpenIndices() {
656628
return visibleOpenIndices;
657629
}
658630

659631
/**
660-
* Returns all of the concrete indices that are closed in the format of array of strings.
661-
*/
662-
public String[] getConcreteAllClosedIndices() {
663-
return allClosedIndices.toArray(String[]::new);
664-
}
665-
666-
/**
667-
* Returns all of the concrete indices that are closed in the format of list of strings.
632+
* Returns all of the concrete indices that are closed.
668633
*/
669-
public List<String> getConcreteAllClosedIndicesList() {
634+
public List<String> getConcreteAllClosedIndices() {
670635
return allClosedIndices;
671636
}
672637

673638
/**
674-
* Returns all of the concrete indices that are closed and not hidden in the format of array of strings.
675-
*/
676-
public String[] getConcreteVisibleClosedIndices() {
677-
return visibleClosedIndices.toArray(String[]::new);
678-
}
679-
680-
/**
681-
* Returns all of the concrete indices that are closed and not hidden in the format of list of strings.
639+
* Returns all of the concrete indices that are closed and not hidden.
682640
*/
683-
public List<String> getConcreteVisibleClosedIndicesList() {
641+
public List<String> getConcreteVisibleClosedIndices() {
684642
return visibleClosedIndices;
685643
}
686644

server/src/main/java/org/opensearch/index/recovery/RemoteStoreRestoreService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public RemoteRestoreResult restore(
165165
}
166166
} else {
167167
List<String> filteredIndices = filterIndices(
168-
List.of(currentState.metadata().getConcreteAllIndices()),
168+
List.copyOf(currentState.metadata().getConcreteAllIndices()),
169169
indexNames,
170170
IndicesOptions.fromOptions(true, true, true, true)
171171
);

server/src/test/java/org/opensearch/cluster/metadata/MetadataTests.java

-6
Original file line numberDiff line numberDiff line change
@@ -1599,17 +1599,11 @@ private static void compareMetadata(
15991599
if (compareIndicesLookups == true) {
16001600
assertEquals(previousMetadata.indices(), newMetadata.indices());
16011601
assertEquals(previousMetadata.getConcreteAllIndices(), newMetadata.getConcreteAllIndices());
1602-
assertEquals(previousMetadata.getConcreteAllIndicesList(), newMetadata.getConcreteAllIndicesList());
16031602
assertEquals(previousMetadata.getConcreteAllClosedIndices(), newMetadata.getConcreteAllClosedIndices());
1604-
assertEquals(previousMetadata.getConcreteAllClosedIndicesList(), newMetadata.getConcreteAllClosedIndicesList());
16051603
assertEquals(previousMetadata.getConcreteAllOpenIndices(), newMetadata.getConcreteAllOpenIndices());
1606-
assertEquals(previousMetadata.getConcreteAllOpenIndicesList(), newMetadata.getConcreteAllOpenIndicesList());
16071604
assertEquals(previousMetadata.getConcreteVisibleIndices(), newMetadata.getConcreteVisibleIndices());
1608-
assertEquals(previousMetadata.getConcreteVisibleIndicesList(), newMetadata.getConcreteVisibleIndicesList());
16091605
assertEquals(previousMetadata.getConcreteVisibleClosedIndices(), newMetadata.getConcreteVisibleClosedIndices());
1610-
assertEquals(previousMetadata.getConcreteVisibleClosedIndicesList(), newMetadata.getConcreteVisibleClosedIndicesList());
16111606
assertEquals(previousMetadata.getConcreteVisibleOpenIndices(), newMetadata.getConcreteVisibleOpenIndices());
1612-
assertEquals(previousMetadata.getConcreteVisibleOpenIndicesList(), newMetadata.getConcreteVisibleOpenIndicesList());
16131607
assertEquals(previousMetadata.getIndicesLookup(), newMetadata.getIndicesLookup());
16141608
assertEquals(previousMetadata.getCustoms().get(DataStreamMetadata.TYPE), newMetadata.getCustoms().get(DataStreamMetadata.TYPE));
16151609
}

0 commit comments

Comments
 (0)