Skip to content

Commit

Permalink
Moving empty IndicesStats creation to Response class
Browse files Browse the repository at this point in the history
Signed-off-by: Harsh Garg <[email protected]>
  • Loading branch information
Harsh Garg committed Oct 23, 2024
1 parent 016fcaf commit 40cc55a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.opensearch.action.admin.cluster.state.ClusterStateResponse;
import org.opensearch.action.admin.indices.stats.IndicesStatsRequest;
import org.opensearch.action.admin.indices.stats.IndicesStatsResponse;
import org.opensearch.action.admin.indices.stats.ShardStats;
import org.opensearch.action.pagination.PageParams;
import org.opensearch.action.pagination.ShardPaginationStrategy;
import org.opensearch.action.support.ActionFilters;
Expand All @@ -28,7 +27,6 @@
import org.opensearch.tasks.Task;
import org.opensearch.transport.TransportService;

import java.util.Collections;
import java.util.Objects;

import static org.opensearch.common.breaker.ResponseLimitSettings.LimitEntity.SHARDS;
Expand All @@ -42,13 +40,6 @@ public class TransportCatShardsAction extends HandledTransportAction<CatShardsRe

private final NodeClient client;
private final ResponseLimitSettings responseLimitSettings;
private static final IndicesStatsResponse EMPTY_INDICES_STATS_RESPONSE = new IndicesStatsResponse(
new ShardStats[0],
0,
0,
0,
Collections.emptyList()
);

@Inject
public TransportCatShardsAction(
Expand Down Expand Up @@ -119,7 +110,7 @@ public void onResponse(ClusterStateResponse clusterStateResponse) {
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(EMPTY_INDICES_STATS_RESPONSE);
catShardsResponse.setIndicesStatsResponse(IndicesStatsResponse.getEmptyResponse());
cancellableListener.onResponse(catShardsResponse);
return;
}
Expand Down
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 @@ -43,7 +43,6 @@
import org.opensearch.action.admin.indices.stats.IndexStats;
import org.opensearch.action.admin.indices.stats.IndicesStatsRequest;
import org.opensearch.action.admin.indices.stats.IndicesStatsResponse;
import org.opensearch.action.admin.indices.stats.ShardStats;
import org.opensearch.action.pagination.IndexPaginationStrategy;
import org.opensearch.action.pagination.PageToken;
import org.opensearch.action.support.GroupedActionListener;
Expand Down Expand Up @@ -105,13 +104,6 @@ public class RestIndicesAction extends AbstractListAction {
"Parameter [master_timeout] is deprecated and will be removed in 3.0. To support inclusive language, please use [cluster_manager_timeout] instead.";
private static final String DUPLICATE_PARAMETER_ERROR_MESSAGE =
"Please only use one of the request parameters [master_timeout, cluster_manager_timeout].";
private static final IndicesStatsResponse EMPTY_INDICES_STATS_RESPONSE = new IndicesStatsResponse(
new ShardStats[0],
0,
0,
0,
Collections.emptyList()
);

private final ResponseLimitSettings responseLimitSettings;

Expand Down Expand Up @@ -223,7 +215,7 @@ public void onResponse(ClusterStateResponse clusterStateResponse) {
// For paginated queries, if strategy outputs no indices to be returned,
// avoid fetching indices stats.
if (shouldSkipIndicesStatsRequest(paginationStrategy)) {
groupedListener.onResponse(EMPTY_INDICES_STATS_RESPONSE);
groupedListener.onResponse(IndicesStatsResponse.getEmptyResponse());
} else {
sendIndicesStatsRequest(
indicesToBeQueried,
Expand Down

0 comments on commit 40cc55a

Please sign in to comment.