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

Avoid making further transport calls if paginationStrategy outputs empty entities #16444

Merged
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 @@
: 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;

Check warning on line 115 in server/src/main/java/org/opensearch/action/admin/cluster/shards/TransportCatShardsAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/shards/TransportCatShardsAction.java#L113-L115

Added lines #L113 - L115 were not covered by tests
}
IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
indicesStatsRequest.setShouldCancelOnTimeout(true);
indicesStatsRequest.all();
Expand Down Expand Up @@ -159,4 +165,8 @@
}
}
}

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 @@
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());

Check warning on line 236 in server/src/main/java/org/opensearch/action/admin/indices/stats/IndicesStatsResponse.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/indices/stats/IndicesStatsResponse.java#L236

Added line #L236 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,19 @@
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());

Check warning on line 218 in server/src/main/java/org/opensearch/rest/action/cat/RestIndicesAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/rest/action/cat/RestIndicesAction.java#L218

Added line #L218 was not covered by tests
} else {
sendIndicesStatsRequest(

Check warning on line 220 in server/src/main/java/org/opensearch/rest/action/cat/RestIndicesAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/rest/action/cat/RestIndicesAction.java#L220

Added line #L220 was not covered by tests
indicesToBeQueried,
subRequestIndicesOptions,
includeUnloadedSegments,
client,
ActionListener.wrap(groupedListener::onResponse, groupedListener::onFailure)

Check warning on line 225 in server/src/main/java/org/opensearch/rest/action/cat/RestIndicesAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/rest/action/cat/RestIndicesAction.java#L225

Added line #L225 was not covered by tests
);
}

sendClusterHealthRequest(
indicesToBeQueried,
Expand Down Expand Up @@ -1093,4 +1099,8 @@
};
}

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

}
Loading