Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Avoid making further transport calls if paginationStrategy outputs empty entities #16456

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ public void onResponse(ClusterStateResponse clusterStateResponse) {
: paginationStrategy.getRequestedEntities()
);
catShardsResponse.setPageToken(Objects.isNull(paginationStrategy) ? null : paginationStrategy.getResponseToken());
// For paginated queries, if strategy outputs no shards to be returned, avoid fetching IndicesStats.
if (shouldSkipIndicesStatsRequest(paginationStrategy)) {
catShardsResponse.setIndicesStatsResponse(IndicesStatsResponse.getEmptyResponse());
cancellableListener.onResponse(catShardsResponse);
return;
}
IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
indicesStatsRequest.setShouldCancelOnTimeout(true);
indicesStatsRequest.all();
Expand Down Expand Up @@ -159,4 +165,8 @@ private void validateRequestLimit(
}
}
}

private boolean shouldSkipIndicesStatsRequest(ShardPaginationStrategy paginationStrategy) {
return Objects.nonNull(paginationStrategy) && paginationStrategy.getRequestedEntities().isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.opensearch.core.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -230,4 +231,8 @@ static final class Fields {
public String toString() {
return Strings.toString(MediaTypeRegistry.JSON, this, true, false);
}

public static IndicesStatsResponse getEmptyResponse() {
return new IndicesStatsResponse(new ShardStats[0], 0, 0, 0, Collections.emptyList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,19 @@ public void onResponse(ClusterStateResponse clusterStateResponse) {
groupedListener.onResponse(getSettingsResponse);
groupedListener.onResponse(clusterStateResponse);

sendIndicesStatsRequest(
indicesToBeQueried,
subRequestIndicesOptions,
includeUnloadedSegments,
client,
ActionListener.wrap(groupedListener::onResponse, groupedListener::onFailure)
);
// For paginated queries, if strategy outputs no indices to be returned,
// avoid fetching indices stats.
if (shouldSkipIndicesStatsRequest(paginationStrategy)) {
groupedListener.onResponse(IndicesStatsResponse.getEmptyResponse());
} else {
sendIndicesStatsRequest(
indicesToBeQueried,
subRequestIndicesOptions,
includeUnloadedSegments,
client,
ActionListener.wrap(groupedListener::onResponse, groupedListener::onFailure)
);
}

sendClusterHealthRequest(
indicesToBeQueried,
Expand Down Expand Up @@ -1086,4 +1092,8 @@ public Tuple<String, Settings> next() {
};
}

private boolean shouldSkipIndicesStatsRequest(IndexPaginationStrategy paginationStrategy) {
return Objects.nonNull(paginationStrategy) && paginationStrategy.getRequestedEntities().isEmpty();
}

}
Loading