diff --git a/server/src/internalClusterTest/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandIT.java b/server/src/internalClusterTest/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandIT.java index 4e9e4b4d641d..a1fd526e886c 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandIT.java @@ -32,7 +32,6 @@ import org.elasticsearch.cli.ProcessInfo; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRoutingState; @@ -531,8 +530,7 @@ public class RemoveCorruptedShardDataCommandIT extends ESIntegTestCase { nodeNameToNodeId.put(cursor.getValue().getName(), cursor.getKey()); } - final GroupShardsIterator shardIterators = state.getRoutingTable() - .activePrimaryShardsGrouped(new String[] { indexName }, false); + final List shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(new String[] { indexName }, false); final List iterators = iterableAsArrayList(shardIterators); final ShardRouting shardRouting = iterators.iterator().next().nextOrNull(); assertThat(shardRouting, notNullValue()); @@ -571,8 +569,7 @@ public class RemoveCorruptedShardDataCommandIT extends ESIntegTestCase { private Path getPathToShardData(String indexName, String dirSuffix) { ClusterState state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState(); - GroupShardsIterator shardIterators = state.getRoutingTable() - .activePrimaryShardsGrouped(new String[] { indexName }, false); + List shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(new String[] { indexName }, false); List iterators = iterableAsArrayList(shardIterators); ShardIterator shardIterator = RandomPicks.randomFrom(random(), iterators); ShardRouting shardRouting = shardIterator.nextOrNull(); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/index/store/CorruptedFileIT.java b/server/src/internalClusterTest/java/org/elasticsearch/index/store/CorruptedFileIT.java index 1594514d2f41..141f24e283b0 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/index/store/CorruptedFileIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/index/store/CorruptedFileIT.java @@ -34,7 +34,6 @@ import org.elasticsearch.cluster.ClusterStateObserver; import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; @@ -311,8 +310,7 @@ public class CorruptedFileIT extends ESIntegTestCase { } assertThat(response.getStatus(), is(ClusterHealthStatus.RED)); ClusterState state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState(); - GroupShardsIterator shardIterators = state.getRoutingTable() - .activePrimaryShardsGrouped(new String[] { "test" }, false); + List shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(new String[] { "test" }, false); for (ShardIterator iterator : shardIterators) { ShardRouting routing; while ((routing = iterator.nextOrNull()) != null) { @@ -667,7 +665,7 @@ public class CorruptedFileIT extends ESIntegTestCase { private int numShards(String... index) { ClusterState state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState(); - GroupShardsIterator shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(index, false); + List shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(index, false); return shardIterators.size(); } @@ -695,8 +693,7 @@ public class CorruptedFileIT extends ESIntegTestCase { private ShardRouting corruptRandomPrimaryFile(final boolean includePerCommitFiles) throws IOException { ClusterState state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState(); Index test = state.metadata().index("test").getIndex(); - GroupShardsIterator shardIterators = state.getRoutingTable() - .activePrimaryShardsGrouped(new String[] { "test" }, false); + List shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(new String[] { "test" }, false); List iterators = iterableAsArrayList(shardIterators); ShardIterator shardIterator = RandomPicks.randomFrom(random(), iterators); ShardRouting shardRouting = shardIterator.nextOrNull(); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/index/suggest/stats/SuggestStatsIT.java b/server/src/internalClusterTest/java/org/elasticsearch/index/suggest/stats/SuggestStatsIT.java index 5cb468da7099..9256065f0d0c 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/index/suggest/stats/SuggestStatsIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/index/suggest/stats/SuggestStatsIT.java @@ -14,7 +14,6 @@ import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.index.search.stats.SearchStats; @@ -24,6 +23,7 @@ import org.elasticsearch.search.suggest.term.TermSuggestionBuilder; import org.elasticsearch.test.ESIntegTestCase; import java.util.HashSet; +import java.util.List; import java.util.Set; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -146,7 +146,7 @@ public class SuggestStatsIT extends ESIntegTestCase { private Set nodeIdsWithIndex(String... indices) { ClusterState state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState(); - GroupShardsIterator allAssignedShardsGrouped = state.routingTable().allAssignedShardsGrouped(indices, true); + List allAssignedShardsGrouped = state.routingTable().allAssignedShardsGrouped(indices, true); Set nodes = new HashSet<>(); for (ShardIterator shardIterator : allAssignedShardsGrouped) { for (ShardRouting routing : shardIterator) { @@ -161,7 +161,7 @@ public class SuggestStatsIT extends ESIntegTestCase { protected int numAssignedShards(String... indices) { ClusterState state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState(); - GroupShardsIterator allAssignedShardsGrouped = state.routingTable().allAssignedShardsGrouped(indices, true); + List allAssignedShardsGrouped = state.routingTable().allAssignedShardsGrouped(indices, true); return allAssignedShardsGrouped.size(); } } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/search/stats/SearchStatsIT.java b/server/src/internalClusterTest/java/org/elasticsearch/search/stats/SearchStatsIT.java index 2530dd35946f..ee7f76e6be3f 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/search/stats/SearchStatsIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/search/stats/SearchStatsIT.java @@ -14,7 +14,6 @@ import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.settings.Settings; @@ -165,7 +164,7 @@ public class SearchStatsIT extends ESIntegTestCase { private Set nodeIdsWithIndex(String... indices) { ClusterState state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState(); - GroupShardsIterator allAssignedShardsGrouped = state.routingTable().allAssignedShardsGrouped(indices, true); + List allAssignedShardsGrouped = state.routingTable().allAssignedShardsGrouped(indices, true); Set nodes = new HashSet<>(); for (ShardIterator shardIterator : allAssignedShardsGrouped) { for (ShardRouting routing : shardIterator) { @@ -248,7 +247,7 @@ public class SearchStatsIT extends ESIntegTestCase { protected int numAssignedShards(String... indices) { ClusterState state = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState(); - GroupShardsIterator allAssignedShardsGrouped = state.routingTable().allAssignedShardsGrouped(indices, true); + List allAssignedShardsGrouped = state.routingTable().allAssignedShardsGrouped(indices, true); return allAssignedShardsGrouped.size(); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java index dd21b11ad18c..b13d0b031c5d 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/shards/TransportClusterSearchShardsAction.java @@ -19,7 +19,6 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.ResolvedExpression; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.service.ClusterService; @@ -34,6 +33,7 @@ import org.elasticsearch.transport.TransportService; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -101,7 +101,7 @@ public class TransportClusterSearchShardsAction extends TransportMasterNodeReadA } Set nodeIds = new HashSet<>(); - GroupShardsIterator groupShardsIterator = clusterService.operationRouting() + List groupShardsIterator = clusterService.operationRouting() .searchShards(clusterState, concreteIndices, routingMap, request.preference()); ShardRouting shard; ClusterSearchShardsGroup[] groupResponses = new ClusterSearchShardsGroup[groupShardsIterator.size()]; diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/diskusage/TransportAnalyzeIndexDiskUsageAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/diskusage/TransportAnalyzeIndexDiskUsageAction.java index 6c0eb7971409..4a3f398656c1 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/diskusage/TransportAnalyzeIndexDiskUsageAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/diskusage/TransportAnalyzeIndexDiskUsageAction.java @@ -21,7 +21,6 @@ import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.service.ClusterService; @@ -214,13 +213,8 @@ public class TransportAnalyzeIndexDiskUsageAction extends TransportBroadcastActi } @Override - protected GroupShardsIterator shards( - ClusterState clusterState, - AnalyzeIndexDiskUsageRequest request, - String[] concreteIndices - ) { - final GroupShardsIterator groups = clusterService.operationRouting() - .searchShards(clusterState, concreteIndices, null, null); + protected List shards(ClusterState clusterState, AnalyzeIndexDiskUsageRequest request, String[] concreteIndices) { + final List groups = clusterService.operationRouting().searchShards(clusterState, concreteIndices, null, null); for (ShardIterator group : groups) { // fails fast if any non-active groups if (group.size() == 0) { diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java index e01f36471267..10d755c75b1c 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java @@ -22,7 +22,6 @@ import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.ResolvedExpression; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.service.ClusterService; @@ -145,7 +144,7 @@ public class TransportValidateQueryAction extends TransportBroadcastAction< } @Override - protected GroupShardsIterator shards(ClusterState clusterState, ValidateQueryRequest request, String[] concreteIndices) { + protected List shards(ClusterState clusterState, ValidateQueryRequest request, String[] concreteIndices) { final String routing; if (request.allShards()) { routing = null; diff --git a/server/src/main/java/org/elasticsearch/action/fieldcaps/RequestDispatcher.java b/server/src/main/java/org/elasticsearch/action/fieldcaps/RequestDispatcher.java index fce925d86853..15577632176f 100644 --- a/server/src/main/java/org/elasticsearch/action/fieldcaps/RequestDispatcher.java +++ b/server/src/main/java/org/elasticsearch/action/fieldcaps/RequestDispatcher.java @@ -18,7 +18,6 @@ import org.elasticsearch.action.NoShardAvailableActionException; import org.elasticsearch.action.OriginalIndices; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.service.ClusterService; @@ -93,7 +92,7 @@ final class RequestDispatcher { this.onComplete = new RunOnce(onComplete); this.indexSelectors = ConcurrentCollections.newConcurrentMap(); for (String index : indices) { - final GroupShardsIterator shardIts; + final List shardIts; try { shardIts = clusterService.operationRouting().searchShards(clusterState, new String[] { index }, null, null); } catch (Exception e) { @@ -250,7 +249,7 @@ final class RequestDispatcher { private final Set unmatchedShardIds = new HashSet<>(); private final Map failures = new HashMap<>(); - IndexSelector(GroupShardsIterator shardIts) { + IndexSelector(List shardIts) { for (ShardIterator shardIt : shardIts) { for (ShardRouting shard : shardIt) { nodeToShards.computeIfAbsent(shard.currentNodeId(), node -> new ArrayList<>()).add(shard); diff --git a/server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java b/server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java index 9f47e1f9773a..44752d6f3360 100644 --- a/server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java @@ -22,7 +22,6 @@ import org.elasticsearch.action.search.TransportSearchAction.SearchTimeProvider; import org.elasticsearch.action.support.SubscribableListener; import org.elasticsearch.action.support.TransportActions; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.util.Maps; @@ -60,9 +59,9 @@ import java.util.stream.Collectors; import static org.elasticsearch.core.Strings.format; /** - * This is an abstract base class that encapsulates the logic to fan out to all shards in provided {@link GroupShardsIterator} + * This is an abstract base class that encapsulates the logic to fan out to all shards in provided {@link List} * and collect the results. If a shard request returns a failure this class handles the advance to the next replica of the shard until - * the shards replica iterator is exhausted. Each shard is referenced by position in the {@link GroupShardsIterator} which is later + * the shards replica iterator is exhausted. Each shard is referenced by position in the {@link List} which is later * referred to as the {@code shardIndex}. * The fan out and collect algorithm is traditionally used as the initial phase which can either be a query execution or collection of * distributed frequencies @@ -93,8 +92,8 @@ abstract class AbstractSearchAsyncAction exten private final SearchTimeProvider timeProvider; private final SearchResponse.Clusters clusters; - protected final GroupShardsIterator toSkipShardsIts; - protected final GroupShardsIterator shardsIts; + protected final List toSkipShardsIts; + protected final List shardsIts; private final SearchShardIterator[] shardIterators; private final AtomicInteger outstandingShards; private final int maxConcurrentRequestsPerNode; @@ -116,7 +115,7 @@ abstract class AbstractSearchAsyncAction exten Executor executor, SearchRequest request, ActionListener listener, - GroupShardsIterator shardsIts, + List shardsIts, SearchTimeProvider timeProvider, ClusterState clusterState, SearchTask task, @@ -135,8 +134,8 @@ abstract class AbstractSearchAsyncAction exten iterators.add(iterator); } } - this.toSkipShardsIts = new GroupShardsIterator<>(toSkipIterators); - this.shardsIts = new GroupShardsIterator<>(iterators); + this.toSkipShardsIts = toSkipIterators; + this.shardsIts = iterators; outstandingShards = new AtomicInteger(shardsIts.size()); this.shardIterators = iterators.toArray(new SearchShardIterator[0]); // we later compute the shard index based on the natural order of the shards @@ -171,8 +170,8 @@ abstract class AbstractSearchAsyncAction exten SearchSourceBuilder sourceBuilder ) { progressListener.notifyListShards( - SearchProgressListener.buildSearchShards(this.shardsIts), - SearchProgressListener.buildSearchShards(toSkipShardsIts), + SearchProgressListener.buildSearchShardsFromIter(this.shardsIts), + SearchProgressListener.buildSearchShardsFromIter(toSkipShardsIts), clusters, sourceBuilder == null || sourceBuilder.size() > 0, timeProvider diff --git a/server/src/main/java/org/elasticsearch/action/search/CanMatchPreFilterSearchPhase.java b/server/src/main/java/org/elasticsearch/action/search/CanMatchPreFilterSearchPhase.java index d45a8a6f01cd..f7b258a9f6b7 100644 --- a/server/src/main/java/org/elasticsearch/action/search/CanMatchPreFilterSearchPhase.java +++ b/server/src/main/java/org/elasticsearch/action/search/CanMatchPreFilterSearchPhase.java @@ -12,7 +12,6 @@ package org.elasticsearch.action.search; import org.apache.logging.log4j.Logger; import org.apache.lucene.util.FixedBitSet; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.common.util.Maps; import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.CountDown; @@ -61,8 +60,8 @@ final class CanMatchPreFilterSearchPhase { private final Logger logger; private final SearchRequest request; - private final GroupShardsIterator shardsIts; - private final ActionListener> listener; + private final List shardsIts; + private final ActionListener> listener; private final TransportSearchAction.SearchTimeProvider timeProvider; private final BiFunction nodeIdToConnection; private final SearchTransportService searchTransportService; @@ -86,12 +85,12 @@ final class CanMatchPreFilterSearchPhase { Map concreteIndexBoosts, Executor executor, SearchRequest request, - GroupShardsIterator shardsIts, + List shardsIts, TransportSearchAction.SearchTimeProvider timeProvider, SearchTask task, boolean requireAtLeastOneMatch, CoordinatorRewriteContextProvider coordinatorRewriteContextProvider, - ActionListener> listener + ActionListener> listener ) { this.logger = logger; this.searchTransportService = searchTransportService; @@ -169,10 +168,9 @@ final class CanMatchPreFilterSearchPhase { if (matchedShardLevelRequests.isEmpty()) { finishPhase(); } else { - GroupShardsIterator matchingShards = new GroupShardsIterator<>(matchedShardLevelRequests); // verify missing shards only for the shards that we hit for the query - checkNoMissingShards(matchingShards); - new Round(matchingShards).run(); + checkNoMissingShards(matchedShardLevelRequests); + new Round(matchedShardLevelRequests).run(); } } @@ -202,12 +200,12 @@ final class CanMatchPreFilterSearchPhase { minAndMaxes[shardIndex] = minAndMax; } - private void checkNoMissingShards(GroupShardsIterator shards) { + private void checkNoMissingShards(List shards) { assert assertSearchCoordinationThread(); SearchPhase.doCheckNoMissingShards("can_match", request, shards, SearchPhase::makeMissingShardsError); } - private Map> groupByNode(GroupShardsIterator shards) { + private Map> groupByNode(List shards) { Map> requests = new HashMap<>(); for (int i = 0; i < shards.size(); i++) { final SearchShardIterator shardRoutings = shards.get(i); @@ -230,11 +228,11 @@ final class CanMatchPreFilterSearchPhase { * to retry on other available shard copies. */ class Round extends AbstractRunnable { - private final GroupShardsIterator shards; + private final List shards; private final CountDown countDown; private final AtomicReferenceArray failedResponses; - Round(GroupShardsIterator shards) { + Round(List shards) { this.shards = shards; this.countDown = new CountDown(shards.size()); this.failedResponses = new AtomicReferenceArray<>(shardsIts.size()); @@ -328,7 +326,7 @@ final class CanMatchPreFilterSearchPhase { finishPhase(); } else { // trigger another round, forcing execution - executor.execute(new Round(new GroupShardsIterator<>(remainingShards)) { + executor.execute(new Round(remainingShards) { @Override public boolean isForceExecution() { return true; @@ -419,7 +417,7 @@ final class CanMatchPreFilterSearchPhase { listener.onFailure(new SearchPhaseExecutionException("can_match", msg, cause, ShardSearchFailure.EMPTY_ARRAY)); } - private synchronized GroupShardsIterator getIterator(GroupShardsIterator shardsIts) { + private synchronized List getIterator(List shardsIts) { // TODO: pick the local shard when possible if (requireAtLeastOneMatch && numPossibleMatches == 0) { // this is a special case where we have no hit but we need to get at least one search response in order @@ -452,14 +450,10 @@ final class CanMatchPreFilterSearchPhase { return shardsIts; } FieldSortBuilder fieldSort = FieldSortBuilder.getPrimaryFieldSortOrNull(request.source()); - return new GroupShardsIterator<>(sortShards(shardsIts, minAndMaxes, fieldSort.order())); + return sortShards(shardsIts, minAndMaxes, fieldSort.order()); } - private static List sortShards( - GroupShardsIterator shardsIts, - MinAndMax[] minAndMaxes, - SortOrder order - ) { + private static List sortShards(List shardsIts, MinAndMax[] minAndMaxes, SortOrder order) { int bound = shardsIts.size(); List toSort = new ArrayList<>(bound); for (int i = 0; i < bound; i++) { diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchDfsQueryThenFetchAsyncAction.java b/server/src/main/java/org/elasticsearch/action/search/SearchDfsQueryThenFetchAsyncAction.java index 5c5c47b5fcc4..056806fbb0b0 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchDfsQueryThenFetchAsyncAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchDfsQueryThenFetchAsyncAction.java @@ -20,7 +20,6 @@ import org.apache.lucene.util.SetOnce; import org.elasticsearch.action.ActionListener; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.search.SearchPhaseResult; import org.elasticsearch.search.SearchShardTarget; @@ -56,7 +55,7 @@ final class SearchDfsQueryThenFetchAsyncAction extends AbstractSearchAsyncAction SearchPhaseResults queryPhaseResultConsumer, SearchRequest request, ActionListener listener, - GroupShardsIterator shardsIts, + List shardsIts, TransportSearchAction.SearchTimeProvider timeProvider, ClusterState clusterState, SearchTask task, diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchPhase.java b/server/src/main/java/org/elasticsearch/action/search/SearchPhase.java index 702369dc3839..1308a2fb61cf 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchPhase.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchPhase.java @@ -8,11 +8,11 @@ */ package org.elasticsearch.action.search; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.search.SearchPhaseResult; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.transport.Transport; +import java.util.List; import java.util.Objects; import java.util.function.Function; @@ -45,14 +45,14 @@ abstract class SearchPhase { + "]. Consider using `allow_partial_search_results` setting to bypass this error."; } - protected void doCheckNoMissingShards(String phaseName, SearchRequest request, GroupShardsIterator shardsIts) { + protected void doCheckNoMissingShards(String phaseName, SearchRequest request, List shardsIts) { doCheckNoMissingShards(phaseName, request, shardsIts, this::missingShardsErrorMessage); } protected static void doCheckNoMissingShards( String phaseName, SearchRequest request, - GroupShardsIterator shardsIts, + List shardsIts, Function makeErrorMessage ) { assert request.allowPartialSearchResults() != null : "SearchRequest missing setting for allowPartialSearchResults"; diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchProgressListener.java b/server/src/main/java/org/elasticsearch/action/search/SearchProgressListener.java index a7f92700435a..6016a0c7a1eb 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchProgressListener.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchProgressListener.java @@ -13,7 +13,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.search.SearchResponse.Clusters; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.search.SearchPhaseResult; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.aggregations.InternalAggregations; @@ -21,7 +20,6 @@ import org.elasticsearch.search.query.QuerySearchResult; import java.util.List; import java.util.Objects; -import java.util.stream.StreamSupport; /** * A listener that allows to track progress of the {@link TransportSearchAction}. @@ -225,7 +223,7 @@ public abstract class SearchProgressListener { .toList(); } - static List buildSearchShards(GroupShardsIterator its) { - return StreamSupport.stream(its.spliterator(), false).map(e -> new SearchShard(e.getClusterAlias(), e.shardId())).toList(); + static List buildSearchShardsFromIter(List its) { + return its.stream().map(e -> new SearchShard(e.getClusterAlias(), e.shardId())).toList(); } } diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncAction.java b/server/src/main/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncAction.java index f75b84abc2f0..088a16deb76d 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncAction.java @@ -14,7 +14,6 @@ import org.apache.lucene.search.TopFieldDocs; import org.elasticsearch.action.ActionListener; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.search.SearchPhaseResult; import org.elasticsearch.search.SearchShardTarget; @@ -25,6 +24,7 @@ import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.transport.Transport; +import java.util.List; import java.util.Map; import java.util.concurrent.Executor; import java.util.function.BiFunction; @@ -52,7 +52,7 @@ class SearchQueryThenFetchAsyncAction extends AbstractSearchAsyncAction resultConsumer, SearchRequest request, ActionListener listener, - GroupShardsIterator shardsIts, + List shardsIts, TransportSearchAction.SearchTimeProvider timeProvider, ClusterState clusterState, SearchTask task, diff --git a/server/src/main/java/org/elasticsearch/action/search/TransportOpenPointInTimeAction.java b/server/src/main/java/org/elasticsearch/action/search/TransportOpenPointInTimeAction.java index 6c95a3c8fd43..b8d0a928e05a 100644 --- a/server/src/main/java/org/elasticsearch/action/search/TransportOpenPointInTimeAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/TransportOpenPointInTimeAction.java @@ -23,7 +23,6 @@ import org.elasticsearch.action.support.ChannelActionListener; import org.elasticsearch.action.support.HandledTransportAction; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.StreamInput; @@ -49,6 +48,7 @@ import org.elasticsearch.transport.TransportResponseHandler; import org.elasticsearch.transport.TransportService; import java.io.IOException; +import java.util.List; import java.util.Map; import java.util.concurrent.Executor; import java.util.function.BiFunction; @@ -150,7 +150,7 @@ public class TransportOpenPointInTimeAction extends HandledTransportAction shardIterators, + List shardIterators, TransportSearchAction.SearchTimeProvider timeProvider, BiFunction connectionLookup, ClusterState clusterState, @@ -212,7 +212,7 @@ public class TransportOpenPointInTimeAction extends HandledTransportAction shardIterators, + List shardIterators, TransportSearchAction.SearchTimeProvider timeProvider, BiFunction connectionLookup, ClusterState clusterState, diff --git a/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java b/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java index 4b13d1642b60..6f075c6f3500 100644 --- a/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java @@ -11,6 +11,7 @@ package org.elasticsearch.action.search; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.TransportVersions; import org.elasticsearch.action.ActionListener; @@ -41,7 +42,6 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.ResolvedExpression; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.OperationRouting; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; @@ -1286,7 +1286,7 @@ public class TransportSearchAction extends HandledTransportAction shardIterators = mergeShardsIterators(localShardIterators, remoteShardIterators); + final List shardIterators = mergeShardsIterators(localShardIterators, remoteShardIterators); failIfOverShardCountLimit(clusterService, shardIterators.size()); @@ -1420,7 +1420,7 @@ public class TransportSearchAction extends HandledTransportAction mergeShardsIterators( + static List mergeShardsIterators( List localShardIterators, List remoteShardIterators ) { @@ -1430,7 +1430,8 @@ public class TransportSearchAction extends HandledTransportAction shardIterators, + List shardIterators, SearchTimeProvider timeProvider, BiFunction connectionLookup, ClusterState clusterState, @@ -1462,7 +1463,7 @@ public class TransportSearchAction extends HandledTransportAction shardIterators, + List shardIterators, SearchTimeProvider timeProvider, BiFunction connectionLookup, ClusterState clusterState, @@ -1855,7 +1856,7 @@ public class TransportSearchAction extends HandledTransportAction shardRoutings = clusterService.operationRouting() + List shardRoutings = clusterService.operationRouting() .searchShards( clusterState, concreteIndices, diff --git a/server/src/main/java/org/elasticsearch/action/search/TransportSearchShardsAction.java b/server/src/main/java/org/elasticsearch/action/search/TransportSearchShardsAction.java index 614a3e9cf22a..83889b7cf752 100644 --- a/server/src/main/java/org/elasticsearch/action/search/TransportSearchShardsAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/TransportSearchShardsAction.java @@ -9,6 +9,7 @@ package org.elasticsearch.action.search; +import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionType; import org.elasticsearch.action.RemoteClusterActionType; @@ -18,7 +19,6 @@ import org.elasticsearch.action.support.HandledTransportAction; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.ResolvedExpression; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.index.Index; import org.elasticsearch.index.query.Rewriteable; @@ -138,15 +138,14 @@ public class TransportSearchShardsAction extends HandledTransportAction shardIts = GroupShardsIterator.sortAndCreate( - transportSearchAction.getLocalShardsIterator( - clusterState, - searchRequest, - searchShardsRequest.clusterAlias(), - indicesAndAliases, - concreteIndexNames - ) + List shardIts = transportSearchAction.getLocalShardsIterator( + clusterState, + searchRequest, + searchShardsRequest.clusterAlias(), + indicesAndAliases, + concreteIndexNames ); + CollectionUtil.timSort(shardIts); if (SearchService.canRewriteToMatchNone(searchRequest.source()) == false) { delegate.onResponse(new SearchShardsResponse(toGroups(shardIts), clusterState.nodes().getAllNodes(), aliasFilters)); } else { @@ -170,7 +169,7 @@ public class TransportSearchShardsAction extends HandledTransportAction toGroups(GroupShardsIterator shardIts) { + private static List toGroups(List shardIts) { List groups = new ArrayList<>(shardIts.size()); for (SearchShardIterator shardIt : shardIts) { boolean skip = shardIt.skip(); diff --git a/server/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastAction.java b/server/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastAction.java index 836eedd960f1..6fabf515ac75 100644 --- a/server/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastAction.java +++ b/server/src/main/java/org/elasticsearch/action/support/broadcast/TransportBroadcastAction.java @@ -22,7 +22,6 @@ import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; -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.transport.TransportService; import org.elasticsearch.transport.Transports; import java.io.IOException; +import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReferenceArray; @@ -108,7 +108,7 @@ public abstract class TransportBroadcastAction< * Determines the shards this operation will be executed on. The operation is executed once per shard iterator, typically * on the first shard in it. If the operation fails, it will be retried on the next shard in the iterator. */ - protected abstract GroupShardsIterator shards(ClusterState clusterState, Request request, String[] concreteIndices); + protected abstract List shards(ClusterState clusterState, Request request, String[] concreteIndices); protected abstract ClusterBlockException checkGlobalBlock(ClusterState state, Request request); @@ -121,7 +121,7 @@ public abstract class TransportBroadcastAction< final ActionListener listener; final ClusterState clusterState; final DiscoveryNodes nodes; - final GroupShardsIterator shardsIts; + final List shardsIts; final int expectedOps; final AtomicInteger counterOps = new AtomicInteger(); // ShardResponse or Exception diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/TransportTermVectorsAction.java b/server/src/main/java/org/elasticsearch/action/termvectors/TransportTermVectorsAction.java index 02479a9f8d14..8a2e9168c3bd 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/TransportTermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/TransportTermVectorsAction.java @@ -14,7 +14,6 @@ import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.single.shard.TransportSingleShardAction; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.Writeable; @@ -65,13 +64,8 @@ public class TransportTermVectorsAction extends TransportSingleShardAction groupShardsIter = operationRouting.searchShards( - state, - new String[] { request.concreteIndex() }, - null, - request.request().preference() - ); - return groupShardsIter.iterator().next(); + return operationRouting.searchShards(state, new String[] { request.concreteIndex() }, null, request.request().preference()) + .getFirst(); } return operationRouting.useOnlyPromotableShardsForStateless( diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/GroupShardsIterator.java b/server/src/main/java/org/elasticsearch/cluster/routing/GroupShardsIterator.java deleted file mode 100644 index 590a1bbb1692..000000000000 --- a/server/src/main/java/org/elasticsearch/cluster/routing/GroupShardsIterator.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.cluster.routing; - -import org.apache.lucene.util.CollectionUtil; -import org.elasticsearch.common.util.Countable; - -import java.util.Iterator; -import java.util.List; - -/** - * This class implements a compilation of {@link ShardIterator}s. Each {@link ShardIterator} - * iterated by this {@link Iterable} represents a group of shards. - * ShardsIterators are always returned in ascending order independently of their order at construction - * time. The incoming iterators are sorted to ensure consistent iteration behavior across Nodes / JVMs. -*/ -public final class GroupShardsIterator & Countable> implements Iterable { - - private final List iterators; - - /** - * Constructs a new sorted GroupShardsIterator from the given list. Items are sorted based on their natural ordering. - * @see PlainShardIterator#compareTo(ShardIterator) - */ - public static & Countable> GroupShardsIterator sortAndCreate(List iterators) { - CollectionUtil.timSort(iterators); - return new GroupShardsIterator<>(iterators); - } - - /** - * Constructs a new GroupShardsIterator from the given list. - */ - public GroupShardsIterator(List iterators) { - this.iterators = iterators; - } - - /** - * Return the number of groups - * @return number of groups - */ - public int size() { - return iterators.size(); - } - - @Override - public Iterator iterator() { - return iterators.iterator(); - } - - public ShardIt get(int index) { - return iterators.get(index); - } -} diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java b/server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java index 49da00eae8a5..1c0dafb799ea 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java @@ -9,6 +9,7 @@ package org.elasticsearch.cluster.routing; +import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -27,6 +28,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -95,7 +97,7 @@ public class OperationRouting { } } - public GroupShardsIterator searchShards( + public List searchShards( ClusterState clusterState, String[] concreteIndices, @Nullable Map> routing, @@ -104,7 +106,7 @@ public class OperationRouting { return searchShards(clusterState, concreteIndices, routing, preference, null, null); } - public GroupShardsIterator searchShards( + public List searchShards( ClusterState clusterState, String[] concreteIndices, @Nullable Map> routing, @@ -127,7 +129,9 @@ public class OperationRouting { set.add(PlainShardIterator.allSearchableShards(iterator)); } } - return GroupShardsIterator.sortAndCreate(new ArrayList<>(set)); + var res = new ArrayList<>(set); + CollectionUtil.timSort(res); + return res; } public static ShardIterator getShards(ClusterState clusterState, ShardId shardId) { diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java index 60cf6b10417f..1f3aadedcb53 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java @@ -9,6 +9,7 @@ package org.elasticsearch.cluster.routing; +import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.TransportVersions; import org.elasticsearch.cluster.Diff; import org.elasticsearch.cluster.Diffable; @@ -194,7 +195,7 @@ public class RoutingTable implements Iterable, Diffable allActiveShardsGrouped(String[] indices, boolean includeEmpty) { + public List allActiveShardsGrouped(String[] indices, boolean includeEmpty) { return allSatisfyingPredicateShardsGrouped(indices, includeEmpty, ShardRouting::active); } @@ -203,11 +204,11 @@ public class RoutingTable implements Iterable, Diffable allAssignedShardsGrouped(String[] indices, boolean includeEmpty) { + public List allAssignedShardsGrouped(String[] indices, boolean includeEmpty) { return allSatisfyingPredicateShardsGrouped(indices, includeEmpty, ShardRouting::assignedToNode); } - private GroupShardsIterator allSatisfyingPredicateShardsGrouped( + private List allSatisfyingPredicateShardsGrouped( String[] indices, boolean includeEmpty, Predicate predicate @@ -232,7 +233,8 @@ public class RoutingTable implements Iterable, Diffable, Diffable activePrimaryShardsGrouped(String[] indices, boolean includeEmpty) { + public List activePrimaryShardsGrouped(String[] indices, boolean includeEmpty) { // use list here since we need to maintain identity across shards ArrayList set = new ArrayList<>(); for (String index : indices) { @@ -303,7 +305,8 @@ public class RoutingTable implements Iterable, Diffable shards( + protected List shards( ClusterState clusterState, AnalyzeIndexDiskUsageRequest request, String[] concreteIndices @@ -308,7 +307,7 @@ public class TransportAnalyzeIndexDiskUsageActionTests extends ESTestCase { for (Map.Entry> e : targetShards.entrySet()) { shardIterators.add(new PlainShardIterator(e.getKey(), e.getValue())); } - return new GroupShardsIterator<>(shardIterators); + return shardIterators; } }; } diff --git a/server/src/test/java/org/elasticsearch/action/search/AbstractSearchAsyncActionTests.java b/server/src/test/java/org/elasticsearch/action/search/AbstractSearchAsyncActionTests.java index 47ff4ca6f060..11085558dbe1 100644 --- a/server/src/test/java/org/elasticsearch/action/search/AbstractSearchAsyncActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/AbstractSearchAsyncActionTests.java @@ -13,7 +13,6 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.OriginalIndices; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.common.UUIDs; import org.elasticsearch.core.Tuple; import org.elasticsearch.index.Index; @@ -83,9 +82,7 @@ public class AbstractSearchAsyncActionTests extends ESTestCase { null, request, listener, - new GroupShardsIterator<>( - Collections.singletonList(new SearchShardIterator(null, new ShardId("index", "_na", 0), Collections.emptyList(), null)) - ), + Collections.singletonList(new SearchShardIterator(null, new ShardId("index", "_na", 0), Collections.emptyList(), null)), timeProvider, ClusterState.EMPTY_STATE, null, diff --git a/server/src/test/java/org/elasticsearch/action/search/CanMatchPreFilterSearchPhaseTests.java b/server/src/test/java/org/elasticsearch/action/search/CanMatchPreFilterSearchPhaseTests.java index 1460270c4829..fb134a2b3136 100644 --- a/server/src/test/java/org/elasticsearch/action/search/CanMatchPreFilterSearchPhaseTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/CanMatchPreFilterSearchPhaseTests.java @@ -10,6 +10,7 @@ package org.elasticsearch.action.search; import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.OriginalIndices; import org.elasticsearch.action.search.CanMatchNodeResponse.ResponseOrFailure; @@ -22,7 +23,6 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeUtils; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.allocation.DataTier; import org.elasticsearch.common.Strings; import org.elasticsearch.common.UUIDs; @@ -135,9 +135,9 @@ public class CanMatchPreFilterSearchPhaseTests extends ESTestCase { } }; - AtomicReference> result = new AtomicReference<>(); + AtomicReference> result = new AtomicReference<>(); CountDownLatch latch = new CountDownLatch(1); - GroupShardsIterator shardsIter = getShardsIter( + List shardsIter = getShardsIter( "idx", new OriginalIndices(new String[] { "idx" }, SearchRequest.DEFAULT_INDICES_OPTIONS), 2, @@ -232,9 +232,9 @@ public class CanMatchPreFilterSearchPhaseTests extends ESTestCase { } }; - AtomicReference> result = new AtomicReference<>(); + AtomicReference> result = new AtomicReference<>(); CountDownLatch latch = new CountDownLatch(1); - GroupShardsIterator shardsIter = getShardsIter( + List shardsIter = getShardsIter( "idx", new OriginalIndices(new String[] { "idx" }, SearchRequest.DEFAULT_INDICES_OPTIONS), 2, @@ -325,9 +325,9 @@ public class CanMatchPreFilterSearchPhaseTests extends ESTestCase { } }; - AtomicReference> result = new AtomicReference<>(); + AtomicReference> result = new AtomicReference<>(); CountDownLatch latch = new CountDownLatch(1); - GroupShardsIterator shardsIter = getShardsIter( + List shardsIter = getShardsIter( "logs", new OriginalIndices(new String[] { "logs" }, SearchRequest.DEFAULT_INDICES_OPTIONS), randomIntBetween(2, 20), @@ -427,9 +427,9 @@ public class CanMatchPreFilterSearchPhaseTests extends ESTestCase { } }; - AtomicReference> result = new AtomicReference<>(); + AtomicReference> result = new AtomicReference<>(); CountDownLatch latch = new CountDownLatch(1); - GroupShardsIterator shardsIter = getShardsIter( + List shardsIter = getShardsIter( "logs", new OriginalIndices(new String[] { "logs" }, SearchRequest.DEFAULT_INDICES_OPTIONS), numShards, @@ -1202,7 +1202,7 @@ public class CanMatchPreFilterSearchPhaseTests extends ESTestCase { false, new ActionListener<>() { @Override - public void onResponse(GroupShardsIterator searchShardIterators) { + public void onResponse(List searchShardIterators) { fail(null, "unexpected success with result [%s] while expecting to handle failure with [%s]", searchShardIterators); latch.countDown(); } @@ -1268,7 +1268,7 @@ public class CanMatchPreFilterSearchPhaseTests extends ESTestCase { boolean allowPartialResults, BiConsumer, List> canMatchResultsConsumer ) throws Exception { - AtomicReference> result = new AtomicReference<>(); + AtomicReference> result = new AtomicReference<>(); CountDownLatch latch = new CountDownLatch(1); Tuple> canMatchAndShardRequests = getCanMatchPhaseAndRequests( dataStreams, @@ -1305,7 +1305,7 @@ public class CanMatchPreFilterSearchPhaseTests extends ESTestCase { SuggestBuilder suggest, List unassignedIndices, boolean allowPartialResults, - ActionListener> canMatchActionListener + ActionListener> canMatchActionListener ) { Map lookup = new ConcurrentHashMap<>(); DiscoveryNode primaryNode = DiscoveryNodeUtils.create("node_1"); @@ -1324,7 +1324,7 @@ public class CanMatchPreFilterSearchPhaseTests extends ESTestCase { String[] indices = indicesToSearch.toArray(new String[0]); OriginalIndices originalIndices = new OriginalIndices(indices, SearchRequest.DEFAULT_INDICES_OPTIONS); - final List originalShardIters = new ArrayList<>(); + final List shardIters = new ArrayList<>(); for (var dataStream : dataStreams) { boolean atLeastOnePrimaryAssigned = false; for (var dataStreamIndex : dataStream.getIndices()) { @@ -1333,9 +1333,9 @@ public class CanMatchPreFilterSearchPhaseTests extends ESTestCase { boolean withAssignedPrimaries = randomBoolean() || atLeastOnePrimaryAssigned == false; int numShards = randomIntBetween(1, 6); if (unassignedIndices.contains(dataStreamIndex)) { - originalShardIters.addAll(getShardsIter(dataStreamIndex, originalIndices, numShards, false, null, null)); + shardIters.addAll(getShardsIter(dataStreamIndex, originalIndices, numShards, false, null, null)); } else { - originalShardIters.addAll( + shardIters.addAll( getShardsIter(dataStreamIndex, originalIndices, numShards, false, withAssignedPrimaries ? primaryNode : null, null) ); atLeastOnePrimaryAssigned |= withAssignedPrimaries; @@ -1345,14 +1345,14 @@ public class CanMatchPreFilterSearchPhaseTests extends ESTestCase { for (Index regularIndex : regularIndices) { if (unassignedIndices.contains(regularIndex)) { - originalShardIters.addAll(getShardsIter(regularIndex, originalIndices, randomIntBetween(1, 6), false, null, null)); + shardIters.addAll(getShardsIter(regularIndex, originalIndices, randomIntBetween(1, 6), false, null, null)); } else { - originalShardIters.addAll( + shardIters.addAll( getShardsIter(regularIndex, originalIndices, randomIntBetween(1, 6), randomBoolean(), primaryNode, replicaNode) ); } } - GroupShardsIterator shardsIter = GroupShardsIterator.sortAndCreate(originalShardIters); + CollectionUtil.timSort(shardIters); final SearchRequest searchRequest = new SearchRequest(); searchRequest.indices(indices); @@ -1415,7 +1415,6 @@ public class CanMatchPreFilterSearchPhaseTests extends ESTestCase { System::nanoTime ); - AtomicReference> result = new AtomicReference<>(); return new Tuple<>( new CanMatchPreFilterSearchPhase( logger, @@ -1425,7 +1424,7 @@ public class CanMatchPreFilterSearchPhaseTests extends ESTestCase { Collections.emptyMap(), threadPool.executor(ThreadPool.Names.SEARCH_COORDINATION), searchRequest, - shardsIter, + shardIters, timeProvider, null, true, diff --git a/server/src/test/java/org/elasticsearch/action/search/MockSearchPhaseContext.java b/server/src/test/java/org/elasticsearch/action/search/MockSearchPhaseContext.java index e8e12300c23e..97d420b7cd3c 100644 --- a/server/src/test/java/org/elasticsearch/action/search/MockSearchPhaseContext.java +++ b/server/src/test/java/org/elasticsearch/action/search/MockSearchPhaseContext.java @@ -13,7 +13,6 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.OriginalIndices; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -62,7 +61,7 @@ public final class MockSearchPhaseContext extends AbstractSearchAsyncAction(List.of()), + List.of(), null, ClusterState.EMPTY_STATE, new SearchTask(0, "n/a", "n/a", () -> "test", null, Collections.emptyMap()), diff --git a/server/src/test/java/org/elasticsearch/action/search/SearchAsyncActionTests.java b/server/src/test/java/org/elasticsearch/action/search/SearchAsyncActionTests.java index 7e9e6f623cab..647d16977181 100644 --- a/server/src/test/java/org/elasticsearch/action/search/SearchAsyncActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/SearchAsyncActionTests.java @@ -15,7 +15,6 @@ import org.elasticsearch.action.support.ActionTestUtils; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeUtils; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.UnassignedInfo; @@ -67,7 +66,7 @@ public class SearchAsyncActionTests extends ESTestCase { DiscoveryNode replicaNode = DiscoveryNodeUtils.create("node_2"); AtomicInteger contextIdGenerator = new AtomicInteger(0); - GroupShardsIterator shardsIter = getShardsIter( + List shardsIter = getShardsIter( "idx", new OriginalIndices(new String[] { "idx" }, SearchRequest.DEFAULT_INDICES_OPTIONS), numShards, @@ -182,7 +181,7 @@ public class SearchAsyncActionTests extends ESTestCase { DiscoveryNode replicaNode = DiscoveryNodeUtils.create("node_1"); AtomicInteger contextIdGenerator = new AtomicInteger(0); - GroupShardsIterator shardsIter = getShardsIter( + List shardsIter = getShardsIter( "idx", new OriginalIndices(new String[] { "idx" }, SearchRequest.DEFAULT_INDICES_OPTIONS), numShards, @@ -285,7 +284,7 @@ public class SearchAsyncActionTests extends ESTestCase { Map> nodeToContextMap = newConcurrentMap(); AtomicInteger contextIdGenerator = new AtomicInteger(0); int numShards = randomIntBetween(1, 10); - GroupShardsIterator shardsIter = getShardsIter( + List shardsIter = getShardsIter( "idx", new OriginalIndices(new String[] { "idx" }, SearchRequest.DEFAULT_INDICES_OPTIONS), numShards, @@ -415,7 +414,7 @@ public class SearchAsyncActionTests extends ESTestCase { Map> nodeToContextMap = newConcurrentMap(); AtomicInteger contextIdGenerator = new AtomicInteger(0); int numShards = randomIntBetween(2, 10); - GroupShardsIterator shardsIter = getShardsIter( + List shardsIter = getShardsIter( "idx", new OriginalIndices(new String[] { "idx" }, SearchRequest.DEFAULT_INDICES_OPTIONS), numShards, @@ -534,7 +533,7 @@ public class SearchAsyncActionTests extends ESTestCase { DiscoveryNode replicaNode = DiscoveryNodeUtils.create("node_1"); AtomicInteger contextIdGenerator = new AtomicInteger(0); - GroupShardsIterator shardsIter = getShardsIter( + List shardsIter = getShardsIter( "idx", new OriginalIndices(new String[] { "idx" }, SearchRequest.DEFAULT_INDICES_OPTIONS), numShards, @@ -647,7 +646,7 @@ public class SearchAsyncActionTests extends ESTestCase { searchShardIterator.reset(); searchShardIterators.add(searchShardIterator); } - GroupShardsIterator shardsIter = new GroupShardsIterator<>(searchShardIterators); + List shardsIter = searchShardIterators; Map lookup = Map.of(primaryNode.getId(), new MockConnection(primaryNode)); CountDownLatch latch = new CountDownLatch(1); @@ -706,7 +705,7 @@ public class SearchAsyncActionTests extends ESTestCase { assertThat(searchResponse.get().getSuccessfulShards(), equalTo(shardsIter.size())); } - static GroupShardsIterator getShardsIter( + static List getShardsIter( String index, OriginalIndices originalIndices, int numShards, @@ -714,9 +713,7 @@ public class SearchAsyncActionTests extends ESTestCase { DiscoveryNode primaryNode, DiscoveryNode replicaNode ) { - return new GroupShardsIterator<>( - getShardsIter(new Index(index, "_na_"), originalIndices, numShards, doReplicas, primaryNode, replicaNode) - ); + return getShardsIter(new Index(index, "_na_"), originalIndices, numShards, doReplicas, primaryNode, replicaNode); } static List getShardsIter( diff --git a/server/src/test/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncActionTests.java b/server/src/test/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncActionTests.java index 661a9fd8c854..be693a2d7d29 100644 --- a/server/src/test/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncActionTests.java @@ -19,7 +19,6 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeUtils; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.breaker.NoopCircuitBreaker; import org.elasticsearch.common.lucene.search.TopDocsAndMaxScore; @@ -42,6 +41,7 @@ import org.elasticsearch.test.InternalAggregationTestCase; import org.elasticsearch.transport.Transport; import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; @@ -150,7 +150,7 @@ public class SearchQueryThenFetchAsyncActionTests extends ESTestCase { } }; CountDownLatch latch = new CountDownLatch(1); - GroupShardsIterator shardsIter = SearchAsyncActionTests.getShardsIter( + List shardsIter = SearchAsyncActionTests.getShardsIter( "idx", new OriginalIndices(new String[] { "idx" }, SearchRequest.DEFAULT_INDICES_OPTIONS), numShards, diff --git a/server/src/test/java/org/elasticsearch/action/search/SearchShardIteratorTests.java b/server/src/test/java/org/elasticsearch/action/search/SearchShardIteratorTests.java index 2ecdc1be9c36..79736427f634 100644 --- a/server/src/test/java/org/elasticsearch/action/search/SearchShardIteratorTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/SearchShardIteratorTests.java @@ -12,7 +12,8 @@ package org.elasticsearch.action.search; import org.elasticsearch.action.OriginalIndices; import org.elasticsearch.action.OriginalIndicesTests; import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.cluster.routing.GroupShardsIteratorTests; +import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.cluster.routing.TestShardRouting; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.test.ESTestCase; @@ -24,10 +25,24 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED; import static org.hamcrest.Matchers.equalTo; public class SearchShardIteratorTests extends ESTestCase { + public static List randomShardRoutings(ShardId shardId) { + return randomShardRoutings(shardId, randomIntBetween(0, 2)); + } + + private static List randomShardRoutings(ShardId shardId, int numReplicas) { + List shardRoutings = new ArrayList<>(); + shardRoutings.add(TestShardRouting.newShardRouting(shardId, randomAlphaOfLengthBetween(5, 10), true, STARTED)); + for (int j = 0; j < numReplicas; j++) { + shardRoutings.add(TestShardRouting.newShardRouting(shardId, randomAlphaOfLengthBetween(5, 10), false, STARTED)); + } + return shardRoutings; + } + public void testShardId() { ShardId shardId = new ShardId(randomAlphaOfLengthBetween(5, 10), randomAlphaOfLength(10), randomInt()); SearchShardIterator searchShardIterator = new SearchShardIterator(null, shardId, Collections.emptyList(), OriginalIndices.NONE); @@ -149,19 +164,14 @@ public class SearchShardIteratorTests extends ESTestCase { for (String uuid : uuids) { ShardId shardId = new ShardId(index, uuid, i); shardIterators.add( - new SearchShardIterator( - null, - shardId, - GroupShardsIteratorTests.randomShardRoutings(shardId), - OriginalIndicesTests.randomOriginalIndices() - ) + new SearchShardIterator(null, shardId, randomShardRoutings(shardId), OriginalIndicesTests.randomOriginalIndices()) ); for (String cluster : clusters) { shardIterators.add( new SearchShardIterator( cluster, shardId, - GroupShardsIteratorTests.randomShardRoutings(shardId), + randomShardRoutings(shardId), OriginalIndicesTests.randomOriginalIndices() ) ); @@ -207,11 +217,6 @@ public class SearchShardIteratorTests extends ESTestCase { private static SearchShardIterator randomSearchShardIterator() { String clusterAlias = randomBoolean() ? null : randomAlphaOfLengthBetween(5, 10); ShardId shardId = new ShardId(randomAlphaOfLengthBetween(5, 10), randomAlphaOfLength(10), randomIntBetween(0, Integer.MAX_VALUE)); - return new SearchShardIterator( - clusterAlias, - shardId, - GroupShardsIteratorTests.randomShardRoutings(shardId), - OriginalIndicesTests.randomOriginalIndices() - ); + return new SearchShardIterator(clusterAlias, shardId, randomShardRoutings(shardId), OriginalIndicesTests.randomOriginalIndices()); } } diff --git a/server/src/test/java/org/elasticsearch/action/search/TransportSearchActionTests.java b/server/src/test/java/org/elasticsearch/action/search/TransportSearchActionTests.java index 8196c01ee8bb..f244af80ad9f 100644 --- a/server/src/test/java/org/elasticsearch/action/search/TransportSearchActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/TransportSearchActionTests.java @@ -37,8 +37,6 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeUtils; import org.elasticsearch.cluster.node.VersionInformation; -import org.elasticsearch.cluster.routing.GroupShardsIterator; -import org.elasticsearch.cluster.routing.GroupShardsIteratorTests; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRoutingState; @@ -151,7 +149,7 @@ public class TransportSearchActionTests extends ESTestCase { String clusterAlias ) { ShardId shardId = new ShardId(index, id); - List shardRoutings = GroupShardsIteratorTests.randomShardRoutings(shardId); + List shardRoutings = SearchShardIteratorTests.randomShardRoutings(shardId); return new SearchShardIterator(clusterAlias, shardId, shardRoutings, originalIndices); } @@ -250,7 +248,7 @@ public class TransportSearchActionTests extends ESTestCase { Collections.shuffle(localShardIterators, random()); Collections.shuffle(remoteShardIterators, random()); - GroupShardsIterator groupShardsIterator = TransportSearchAction.mergeShardsIterators( + List groupShardsIterator = TransportSearchAction.mergeShardsIterators( localShardIterators, remoteShardIterators ); diff --git a/server/src/test/java/org/elasticsearch/cluster/action/shard/ShardFailedClusterStateTaskExecutorTests.java b/server/src/test/java/org/elasticsearch/cluster/action/shard/ShardFailedClusterStateTaskExecutorTests.java index 6dd39da53362..75b6882abd7e 100644 --- a/server/src/test/java/org/elasticsearch/cluster/action/shard/ShardFailedClusterStateTaskExecutorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/action/shard/ShardFailedClusterStateTaskExecutorTests.java @@ -21,7 +21,6 @@ import org.elasticsearch.cluster.action.shard.ShardStateAction.FailedShardUpdate import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.RoutingNodesHelper; import org.elasticsearch.cluster.routing.RoutingTable; @@ -237,7 +236,7 @@ public class ShardFailedClusterStateTaskExecutorTests extends ESAllocationTestCa private List createExistingShards(ClusterState currentState, String reason) { List shards = new ArrayList<>(); - GroupShardsIterator shardGroups = currentState.routingTable().allAssignedShardsGrouped(new String[] { INDEX }, true); + List shardGroups = currentState.routingTable().allAssignedShardsGrouped(new String[] { INDEX }, true); for (ShardIterator shardIt : shardGroups) { for (ShardRouting shard : shardIt) { shards.add(shard); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/GroupShardsIteratorTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/GroupShardsIteratorTests.java deleted file mode 100644 index d354658396a0..000000000000 --- a/server/src/test/java/org/elasticsearch/cluster/routing/GroupShardsIteratorTests.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.cluster.routing; - -import org.apache.lucene.util.CollectionUtil; -import org.elasticsearch.action.OriginalIndicesTests; -import org.elasticsearch.action.search.SearchShardIterator; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.test.ESTestCase; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED; - -public class GroupShardsIteratorTests extends ESTestCase { - - public static List randomShardRoutings(ShardId shardId) { - return randomShardRoutings(shardId, randomIntBetween(0, 2)); - } - - private static List randomShardRoutings(ShardId shardId, int numReplicas) { - List shardRoutings = new ArrayList<>(); - shardRoutings.add(TestShardRouting.newShardRouting(shardId, randomAlphaOfLengthBetween(5, 10), true, STARTED)); - for (int j = 0; j < numReplicas; j++) { - shardRoutings.add(TestShardRouting.newShardRouting(shardId, randomAlphaOfLengthBetween(5, 10), false, STARTED)); - } - return shardRoutings; - } - - public void testIterate() { - List list = new ArrayList<>(); - Index index = new Index("foo", "na"); - { - ShardId shardId = new ShardId(index, 0); - list.add(new PlainShardIterator(shardId, randomShardRoutings(shardId))); - } - list.add(new PlainShardIterator(new ShardId(index, 1), Collections.emptyList())); - { - ShardId shardId = new ShardId(index, 2); - list.add(new PlainShardIterator(shardId, randomShardRoutings(shardId))); - } - { - ShardId shardId = new ShardId(index, 0); - list.add(new PlainShardIterator(shardId, randomShardRoutings(shardId))); - } - { - ShardId shardId = new ShardId(index, 1); - list.add(new PlainShardIterator(shardId, randomShardRoutings(shardId))); - } - index = new Index("foo_2", "na"); - { - ShardId shardId = new ShardId(index, 0); - list.add(new PlainShardIterator(shardId, randomShardRoutings(shardId))); - } - { - ShardId shardId = new ShardId(index, 1); - list.add(new PlainShardIterator(shardId, randomShardRoutings(shardId))); - } - - Collections.shuffle(list, random()); - { - GroupShardsIterator unsorted = new GroupShardsIterator<>(list); - GroupShardsIterator iter = new GroupShardsIterator<>(list); - List actualIterators = new ArrayList<>(); - for (ShardIterator shardsIterator : iter) { - actualIterators.add(shardsIterator); - } - assertEquals(actualIterators, list); - } - { - GroupShardsIterator iter = GroupShardsIterator.sortAndCreate(list); - List actualIterators = new ArrayList<>(); - for (ShardIterator shardsIterator : iter) { - actualIterators.add(shardsIterator); - } - CollectionUtil.timSort(actualIterators); - assertEquals(actualIterators, list); - } - } - - public void testOrderingWithSearchShardIterators() { - String[] indices = generateRandomStringArray(10, 10, false, false); - Arrays.sort(indices); - String[] uuids = generateRandomStringArray(5, 10, false, false); - Arrays.sort(uuids); - String[] clusters = generateRandomStringArray(5, 10, false, false); - Arrays.sort(clusters); - - List sorted = new ArrayList<>(); - int numShards = randomIntBetween(1, 10); - for (int i = 0; i < numShards; i++) { - for (String index : indices) { - for (String uuid : uuids) { - ShardId shardId = new ShardId(index, uuid, i); - SearchShardIterator shardIterator = new SearchShardIterator( - null, - shardId, - GroupShardsIteratorTests.randomShardRoutings(shardId), - OriginalIndicesTests.randomOriginalIndices() - ); - sorted.add(shardIterator); - for (String cluster : clusters) { - SearchShardIterator remoteIterator = new SearchShardIterator( - cluster, - shardId, - GroupShardsIteratorTests.randomShardRoutings(shardId), - OriginalIndicesTests.randomOriginalIndices() - ); - sorted.add(remoteIterator); - } - } - } - } - - List shuffled = new ArrayList<>(sorted); - Collections.shuffle(shuffled, random()); - { - List actualIterators = new ArrayList<>(); - GroupShardsIterator iter = new GroupShardsIterator<>(shuffled); - for (SearchShardIterator searchShardIterator : iter) { - actualIterators.add(searchShardIterator); - } - assertEquals(shuffled, actualIterators); - } - { - List actualIterators = new ArrayList<>(); - GroupShardsIterator iter = GroupShardsIterator.sortAndCreate(shuffled); - for (SearchShardIterator searchShardIterator : iter) { - actualIterators.add(searchShardIterator); - } - assertEquals(sorted, actualIterators); - } - } -} diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/OperationRoutingTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/OperationRoutingTests.java index 6c244008097f..7337e28da1dc 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/OperationRoutingTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/OperationRoutingTests.java @@ -162,7 +162,7 @@ public class OperationRoutingTests extends ESTestCase { for (int i = 0; i < numRepeatedSearches; i++) { List searchedShards = new ArrayList<>(numShards); Set selectedNodes = Sets.newHashSetWithExpectedSize(numShards); - final GroupShardsIterator groupIterator = opRouting.searchShards(state, indexNames, null, sessionKey); + final List groupIterator = opRouting.searchShards(state, indexNames, null, sessionKey); assertThat("One group per index shard", groupIterator.size(), equalTo(numIndices * numShards)); for (ShardIterator shardIterator : groupIterator) { @@ -283,14 +283,7 @@ public class OperationRoutingTests extends ESTestCase { TestThreadPool threadPool = new TestThreadPool("test"); ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool); ResponseCollectorService collector = new ResponseCollectorService(clusterService); - GroupShardsIterator groupIterator = opRouting.searchShards( - state, - indexNames, - null, - null, - collector, - new HashMap<>() - ); + List groupIterator = opRouting.searchShards(state, indexNames, null, null, collector, new HashMap<>()); assertThat("One group per index shard", groupIterator.size(), equalTo(numIndices * numShards)); @@ -369,14 +362,7 @@ public class OperationRoutingTests extends ESTestCase { ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool); ResponseCollectorService collector = new ResponseCollectorService(clusterService); - GroupShardsIterator groupIterator = opRouting.searchShards( - state, - indexNames, - null, - null, - collector, - new HashMap<>() - ); + List groupIterator = opRouting.searchShards(state, indexNames, null, null, collector, new HashMap<>()); assertThat("One group per index shard", groupIterator.size(), equalTo(numIndices * numShards)); // We have two nodes, where the second has more load @@ -435,14 +421,7 @@ public class OperationRoutingTests extends ESTestCase { Map outstandingRequests = new HashMap<>(); // Check that we choose to search over both nodes - GroupShardsIterator groupIterator = opRouting.searchShards( - state, - indexNames, - null, - null, - collector, - outstandingRequests - ); + List groupIterator = opRouting.searchShards(state, indexNames, null, null, collector, outstandingRequests); Set nodeIds = new HashSet<>(); nodeIds.add(groupIterator.get(0).nextOrNull().currentNodeId()); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/PlainShardIteratorTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/PlainShardIteratorTests.java index 0d6cc3fad1e5..a7d3ed95320c 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/PlainShardIteratorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/PlainShardIteratorTests.java @@ -9,6 +9,7 @@ package org.elasticsearch.cluster.routing; +import org.elasticsearch.action.search.SearchShardIteratorTests; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.EqualsHashCodeTestUtils; @@ -55,7 +56,7 @@ public class PlainShardIteratorTests extends ESTestCase { for (String index : indices) { for (String uuid : uuids) { ShardId shardId = new ShardId(index, uuid, i); - shardIterators.add(new PlainShardIterator(shardId, GroupShardsIteratorTests.randomShardRoutings(shardId))); + shardIterators.add(new PlainShardIterator(shardId, SearchShardIteratorTests.randomShardRoutings(shardId))); } } } @@ -86,6 +87,6 @@ public class PlainShardIteratorTests extends ESTestCase { private static PlainShardIterator randomPlainShardIterator() { ShardId shardId = new ShardId(randomAlphaOfLengthBetween(5, 10), randomAlphaOfLength(10), randomIntBetween(1, Integer.MAX_VALUE)); - return new PlainShardIterator(shardId, GroupShardsIteratorTests.randomShardRoutings(shardId)); + return new PlainShardIterator(shardId, SearchShardIteratorTests.randomShardRoutings(shardId)); } } diff --git a/server/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java b/server/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java index 2d9055f71808..7997cb1cef45 100644 --- a/server/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java @@ -17,7 +17,6 @@ import org.elasticsearch.cluster.TestShardRoutingRoleStrategies; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.OperationRouting; import org.elasticsearch.cluster.routing.PlainShardIterator; import org.elasticsearch.cluster.routing.RotationShardShuffler; @@ -357,12 +356,7 @@ public class RoutingIteratorTests extends ESAllocationTestCase { new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) ); - GroupShardsIterator shardIterators = operationRouting.searchShards( - clusterState, - new String[] { "test" }, - null, - "_shards:0" - ); + List shardIterators = operationRouting.searchShards(clusterState, new String[] { "test" }, null, "_shards:0"); assertThat(shardIterators.size(), equalTo(1)); assertThat(shardIterators.iterator().next().shardId().id(), equalTo(0)); diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportForgetFollowerAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportForgetFollowerAction.java index 431210264ebb..f126a546ae85 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportForgetFollowerAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportForgetFollowerAction.java @@ -16,7 +16,6 @@ import org.elasticsearch.action.support.replication.ReplicationResponse; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.PlainShardsIterator; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; @@ -141,8 +140,7 @@ public class TransportForgetFollowerAction extends TransportBroadcastByNodeActio final ForgetFollowerAction.Request request, final String[] concreteIndices ) { - final GroupShardsIterator activePrimaryShards = clusterState.routingTable() - .activePrimaryShardsGrouped(concreteIndices, false); + final List activePrimaryShards = clusterState.routingTable().activePrimaryShardsGrouped(concreteIndices, false); final List shardRoutings = new ArrayList<>(); final Iterator it = activePrimaryShards.iterator(); while (it.hasNext()) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/termsenum/action/TransportTermsEnumAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/termsenum/action/TransportTermsEnumAction.java index 08e89a0fcab0..c264f084c017 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/termsenum/action/TransportTermsEnumAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/termsenum/action/TransportTermsEnumAction.java @@ -25,7 +25,6 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.service.ClusterService; @@ -205,8 +204,7 @@ public class TransportTermsEnumAction extends HandledTransportAction shards = clusterService.operationRouting() - .searchShards(clusterState, singleIndex, null, null); + List shards = clusterService.operationRouting().searchShards(clusterState, singleIndex, null, null); for (ShardIterator copiesOfShard : shards) { ShardRouting selectedCopyOfShard = null; diff --git a/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleIndexerAction.java b/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleIndexerAction.java index 3d3fe3650ebd..8c396c493495 100644 --- a/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleIndexerAction.java +++ b/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleIndexerAction.java @@ -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 shards( - ClusterState clusterState, - DownsampleIndexerAction.Request request, - String[] concreteIndices - ) { + protected List shards(ClusterState clusterState, DownsampleIndexerAction.Request request, String[] concreteIndices) { if (concreteIndices.length > 1) { throw new IllegalArgumentException("multiple indices: " + Arrays.toString(concreteIndices)); } - final GroupShardsIterator groups = clusterService.operationRouting() - .searchShards(clusterState, concreteIndices, null, null); + final List groups = clusterService.operationRouting().searchShards(clusterState, concreteIndices, null, null); for (ShardIterator group : groups) { // fails fast if any non-active groups if (group.size() == 0) { diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichShardMultiSearchAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichShardMultiSearchAction.java index c43dc99f147b..a7167e176cbe 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichShardMultiSearchAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichShardMultiSearchAction.java @@ -25,10 +25,8 @@ import org.elasticsearch.action.support.single.shard.SingleShardRequest; import org.elasticsearch.action.support.single.shard.TransportSingleShardAction; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.Preference; -import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardsIterator; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; @@ -216,10 +214,7 @@ public class EnrichShardMultiSearchAction extends ActionType result = clusterService.operationRouting() - .searchShards(state, new String[] { index }, null, Preference.LOCAL.type()); - return result.get(0); + return clusterService.operationRouting().searchShards(state, new String[] { index }, null, Preference.LOCAL.type()).getFirst(); } @Override diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/AbstractLookupService.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/AbstractLookupService.java index cb2582db2ad3..87dc3ead5a82 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/AbstractLookupService.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/enrich/AbstractLookupService.java @@ -15,7 +15,6 @@ import org.elasticsearch.action.support.ChannelActionListener; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.service.ClusterService; @@ -207,7 +206,7 @@ public abstract class AbstractLookupService> outListener) { ClusterState clusterState = clusterService.state(); - GroupShardsIterator shardIterators = clusterService.operationRouting() + List shardIterators = clusterService.operationRouting() .searchShards(clusterState, new String[] { request.index }, Map.of(), "_local"); if (shardIterators.size() != 1) { outListener.onFailure(new EsqlIllegalArgumentException("target index {} has more than one shard", request.index));