Remove GroupShardsIterator and replace it with plain List (#116891)

There is no point in having `GroupShardsIterator`, it's mostly an
unnecessary layer of indirection as it has no state and a single field
only. It's only value could be seen in it hiding the ability to mutate
the list it wraps, but that hardly justifies the overhead on the search
path and extra code complexity. Moreover, the list it references is not
copied/immutable in any way, so the value of hiding is limited also.
This commit is contained in:
Armin Braun 2025-02-05 21:08:00 +01:00 committed by GitHub
parent c1deef4467
commit 229d89d343
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 159 additions and 436 deletions

View file

@ -17,7 +17,6 @@ import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.routing.GroupShardsIterator;
import org.elasticsearch.cluster.routing.ShardIterator;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.service.ClusterService;
@ -35,6 +34,7 @@ import org.elasticsearch.xpack.core.downsample.DownsampleShardTask;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicReferenceArray;
/**
@ -79,17 +79,12 @@ public class TransportDownsampleIndexerAction extends TransportBroadcastAction<
}
@Override
protected GroupShardsIterator<ShardIterator> shards(
ClusterState clusterState,
DownsampleIndexerAction.Request request,
String[] concreteIndices
) {
protected List<ShardIterator> shards(ClusterState clusterState, DownsampleIndexerAction.Request request, String[] concreteIndices) {
if (concreteIndices.length > 1) {
throw new IllegalArgumentException("multiple indices: " + Arrays.toString(concreteIndices));
}
final GroupShardsIterator<ShardIterator> groups = clusterService.operationRouting()
.searchShards(clusterState, concreteIndices, null, null);
final List<ShardIterator> groups = clusterService.operationRouting().searchShards(clusterState, concreteIndices, null, null);
for (ShardIterator group : groups) {
// fails fast if any non-active groups
if (group.size() == 0) {