Skip to content

Commit 9741bae

Browse files
committed
More comments
1 parent 4b0f835 commit 9741bae

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexAction.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,10 @@ static void resolveIndices(
683683
dataStreams.sort(Comparator.comparing(ResolvedIndexAbstraction::getName));
684684
}
685685

686+
/**
687+
* Merge the results from remote clusters into the local results lists.
688+
* This will also do index mode filtering (if requested), as the remote cluster might be too old to do it itself.
689+
*/
686690
private static void mergeResults(
687691
Map<String, Response> remoteResponses,
688692
List<ResolvedIndex> indices,
@@ -694,7 +698,7 @@ private static void mergeResults(
694698
String clusterAlias = responseEntry.getKey();
695699
Response response = responseEntry.getValue();
696700
for (ResolvedIndex index : response.indices) {
697-
// We want to filter here because the linked cluster might be too old to be able to filter
701+
// We want to filter by mode here because the linked cluster might be too old to be able to filter
698702
if (indexModes.isEmpty() == false && indexModes.contains(index.getMode()) == false) {
699703
continue;
700704
}
@@ -703,11 +707,12 @@ private static void mergeResults(
703707
Set<String> indexNames = indices.stream().map(ResolvedIndexAbstraction::getName).collect(Collectors.toSet());
704708
for (ResolvedAlias alias : response.aliases) {
705709
if (indexModes.isEmpty() == false) {
706-
// We need to filter out aliases that point to no indices after index mode filtering
710+
// We filter out indices that are not included in the main index list after index mode filtering
707711
String[] filteredIndices = Arrays.stream(alias.getIndices())
708712
.filter(idxName -> indexNames.contains(RemoteClusterAware.buildRemoteIndexName(clusterAlias, idxName)))
709713
.toArray(String[]::new);
710714
if (filteredIndices.length == 0) {
715+
// If this alias points to no indices after filtering, we skip it
711716
continue;
712717
}
713718
alias = new ResolvedAlias(RemoteClusterAware.buildRemoteIndexName(clusterAlias, alias.getName()), filteredIndices);
@@ -718,10 +723,12 @@ private static void mergeResults(
718723
}
719724
for (ResolvedDataStream dataStream : response.dataStreams) {
720725
if (indexModes.isEmpty() == false) {
726+
// We filter out indices that are not included in the main index list after index mode filtering
721727
String[] filteredBackingIndices = Arrays.stream(dataStream.getBackingIndices())
722728
.filter(idxName -> indexNames.contains(RemoteClusterAware.buildRemoteIndexName(clusterAlias, idxName)))
723729
.toArray(String[]::new);
724730
if (filteredBackingIndices.length == 0) {
731+
// If this data stream points to no backing indices after filtering, we skip it
725732
continue;
726733
}
727734
dataStream = new ResolvedDataStream(

0 commit comments

Comments
 (0)