From e8a29e98994dba1210f2420470e177dd0f8b9f4b Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 12 Jul 2023 12:31:24 -0400 Subject: [PATCH] [Refactor] HPPC IntArrayList and ObjectArrayList to j.u.List (#8602) (#8661) Refactors usage of obsolete HPPC IntArrayList and ObjectArrayList to java.util.List. (cherry picked from commit 8d2ec7673711be0f075f283e3c4177094d31d450) Signed-off-by: Nicholas Walter Knize Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .../action/get/MultiGetShardRequest.java | 7 +++---- .../action/get/MultiGetShardResponse.java | 7 +++---- .../action/search/FetchSearchPhase.java | 7 +++---- .../action/search/SearchPhaseController.java | 9 ++++----- .../SearchScrollQueryThenFetchAsyncAction.java | 6 +++--- .../MultiTermVectorsShardRequest.java | 7 +++---- .../MultiTermVectorsShardResponse.java | 7 +++---- .../opensearch/common/transport/PortsRange.java | 17 +++++++---------- .../search/fetch/ShardFetchRequest.java | 6 +++--- .../search/fetch/ShardFetchSearchRequest.java | 4 ++-- .../opensearch/search/SearchServiceTests.java | 3 +-- .../java/org/opensearch/test/TestCluster.java | 10 ++++++---- 12 files changed, 41 insertions(+), 49 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/get/MultiGetShardRequest.java b/server/src/main/java/org/opensearch/action/get/MultiGetShardRequest.java index 22d710c38a8c9..23ebf91fe2300 100644 --- a/server/src/main/java/org/opensearch/action/get/MultiGetShardRequest.java +++ b/server/src/main/java/org/opensearch/action/get/MultiGetShardRequest.java @@ -32,7 +32,6 @@ package org.opensearch.action.get; -import com.carrotsearch.hppc.IntArrayList; import org.opensearch.action.ActionRequestValidationException; import org.opensearch.action.support.single.shard.SingleShardRequest; import org.opensearch.common.io.stream.StreamInput; @@ -54,13 +53,13 @@ public class MultiGetShardRequest extends SingleShardRequest locations; List items; MultiGetShardRequest(StreamInput in) throws IOException { super(in); int size = in.readVInt(); - locations = new IntArrayList(size); + locations = new ArrayList<>(size); items = new ArrayList<>(size); for (int i = 0; i < size; i++) { @@ -76,7 +75,7 @@ public class MultiGetShardRequest extends SingleShardRequest(); items = new ArrayList<>(); preference = multiGetRequest.preference; realtime = multiGetRequest.realtime; diff --git a/server/src/main/java/org/opensearch/action/get/MultiGetShardResponse.java b/server/src/main/java/org/opensearch/action/get/MultiGetShardResponse.java index 069f9875185f8..93adaa66f437d 100644 --- a/server/src/main/java/org/opensearch/action/get/MultiGetShardResponse.java +++ b/server/src/main/java/org/opensearch/action/get/MultiGetShardResponse.java @@ -32,7 +32,6 @@ package org.opensearch.action.get; -import com.carrotsearch.hppc.IntArrayList; import org.opensearch.action.ActionResponse; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; @@ -48,12 +47,12 @@ */ public class MultiGetShardResponse extends ActionResponse { - final IntArrayList locations; + final List locations; final List responses; final List failures; MultiGetShardResponse() { - locations = new IntArrayList(); + locations = new ArrayList<>(); responses = new ArrayList<>(); failures = new ArrayList<>(); } @@ -61,7 +60,7 @@ public class MultiGetShardResponse extends ActionResponse { MultiGetShardResponse(StreamInput in) throws IOException { super(in); int size = in.readVInt(); - locations = new IntArrayList(size); + locations = new ArrayList<>(size); responses = new ArrayList<>(size); failures = new ArrayList<>(size); for (int i = 0; i < size; i++) { diff --git a/server/src/main/java/org/opensearch/action/search/FetchSearchPhase.java b/server/src/main/java/org/opensearch/action/search/FetchSearchPhase.java index 85a3d140977bb..ebb2f33f8f37d 100644 --- a/server/src/main/java/org/opensearch/action/search/FetchSearchPhase.java +++ b/server/src/main/java/org/opensearch/action/search/FetchSearchPhase.java @@ -31,7 +31,6 @@ package org.opensearch.action.search; -import com.carrotsearch.hppc.IntArrayList; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.lucene.search.ScoreDoc; @@ -151,7 +150,7 @@ private void innerRun() throws Exception { finishPhase.run(); } else { ScoreDoc[] scoreDocs = reducedQueryPhase.sortedTopDocs.scoreDocs; - final IntArrayList[] docIdsToLoad = searchPhaseController.fillDocIdsToLoad(numShards, scoreDocs); + final List[] docIdsToLoad = searchPhaseController.fillDocIdsToLoad(numShards, scoreDocs); // no docs to fetch -- sidestep everything and return if (scoreDocs.length == 0) { // we have to release contexts here to free up resources @@ -168,7 +167,7 @@ private void innerRun() throws Exception { context ); for (int i = 0; i < docIdsToLoad.length; i++) { - IntArrayList entry = docIdsToLoad[i]; + List entry = docIdsToLoad[i]; SearchPhaseResult queryResult = queryResults.get(i); if (entry == null) { // no results for this shard ID if (queryResult != null) { @@ -205,7 +204,7 @@ private void innerRun() throws Exception { protected ShardFetchSearchRequest createFetchRequest( ShardSearchContextId contextId, int index, - IntArrayList entry, + List entry, ScoreDoc[] lastEmittedDocPerShard, OriginalIndices originalIndices, ShardSearchRequest shardSearchRequest, diff --git a/server/src/main/java/org/opensearch/action/search/SearchPhaseController.java b/server/src/main/java/org/opensearch/action/search/SearchPhaseController.java index a4984db7c4095..133f0a6be4628 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchPhaseController.java +++ b/server/src/main/java/org/opensearch/action/search/SearchPhaseController.java @@ -32,7 +32,6 @@ package org.opensearch.action.search; -import com.carrotsearch.hppc.IntArrayList; import com.carrotsearch.hppc.ObjectObjectHashMap; import org.apache.lucene.index.Term; @@ -277,12 +276,12 @@ public ScoreDoc[] getLastEmittedDocPerShard(ReducedQueryPhase reducedQueryPhase, /** * Builds an array, with potential null elements, with docs to load. */ - public IntArrayList[] fillDocIdsToLoad(int numShards, ScoreDoc[] shardDocs) { - IntArrayList[] docIdsToLoad = new IntArrayList[numShards]; + public List[] fillDocIdsToLoad(int numShards, ScoreDoc[] shardDocs) { + final List[] docIdsToLoad = (List[]) new ArrayList[numShards]; for (ScoreDoc shardDoc : shardDocs) { - IntArrayList shardDocIdsToLoad = docIdsToLoad[shardDoc.shardIndex]; + List shardDocIdsToLoad = docIdsToLoad[shardDoc.shardIndex]; if (shardDocIdsToLoad == null) { - shardDocIdsToLoad = docIdsToLoad[shardDoc.shardIndex] = new IntArrayList(); + shardDocIdsToLoad = docIdsToLoad[shardDoc.shardIndex] = new ArrayList<>(); } shardDocIdsToLoad.add(shardDoc.doc); } diff --git a/server/src/main/java/org/opensearch/action/search/SearchScrollQueryThenFetchAsyncAction.java b/server/src/main/java/org/opensearch/action/search/SearchScrollQueryThenFetchAsyncAction.java index 9c0721ef63ea6..1fa6460a212f7 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchScrollQueryThenFetchAsyncAction.java +++ b/server/src/main/java/org/opensearch/action/search/SearchScrollQueryThenFetchAsyncAction.java @@ -32,7 +32,6 @@ package org.opensearch.action.search; -import com.carrotsearch.hppc.IntArrayList; import org.apache.logging.log4j.Logger; import org.apache.lucene.search.ScoreDoc; import org.opensearch.action.ActionListener; @@ -48,6 +47,7 @@ import org.opensearch.search.query.ScrollQuerySearchResult; import org.opensearch.transport.Transport; +import java.util.List; import java.util.function.BiFunction; /** @@ -104,7 +104,7 @@ public void run() { return; } - final IntArrayList[] docIdsToLoad = searchPhaseController.fillDocIdsToLoad(queryResults.length(), scoreDocs); + final List[] docIdsToLoad = searchPhaseController.fillDocIdsToLoad(queryResults.length(), scoreDocs); final ScoreDoc[] lastEmittedDocPerShard = searchPhaseController.getLastEmittedDocPerShard( reducedQueryPhase, queryResults.length() @@ -112,7 +112,7 @@ public void run() { final CountDown counter = new CountDown(docIdsToLoad.length); for (int i = 0; i < docIdsToLoad.length; i++) { final int index = i; - final IntArrayList docIds = docIdsToLoad[index]; + final List docIds = docIdsToLoad[index]; if (docIds != null) { final QuerySearchResult querySearchResult = queryResults.get(index); ScoreDoc lastEmittedDoc = lastEmittedDocPerShard[index]; diff --git a/server/src/main/java/org/opensearch/action/termvectors/MultiTermVectorsShardRequest.java b/server/src/main/java/org/opensearch/action/termvectors/MultiTermVectorsShardRequest.java index e936dd3a658a3..bf2d4c676f409 100644 --- a/server/src/main/java/org/opensearch/action/termvectors/MultiTermVectorsShardRequest.java +++ b/server/src/main/java/org/opensearch/action/termvectors/MultiTermVectorsShardRequest.java @@ -32,7 +32,6 @@ package org.opensearch.action.termvectors; -import com.carrotsearch.hppc.IntArrayList; import org.opensearch.action.ActionRequestValidationException; import org.opensearch.action.support.single.shard.SingleShardRequest; import org.opensearch.common.io.stream.StreamInput; @@ -52,13 +51,13 @@ public class MultiTermVectorsShardRequest extends SingleShardRequest locations; List requests; MultiTermVectorsShardRequest(StreamInput in) throws IOException { super(in); int size = in.readVInt(); - locations = new IntArrayList(size); + locations = new ArrayList<>(size); requests = new ArrayList<>(size); for (int i = 0; i < size; i++) { locations.add(in.readVInt()); @@ -71,7 +70,7 @@ public class MultiTermVectorsShardRequest extends SingleShardRequest(); requests = new ArrayList<>(); } diff --git a/server/src/main/java/org/opensearch/action/termvectors/MultiTermVectorsShardResponse.java b/server/src/main/java/org/opensearch/action/termvectors/MultiTermVectorsShardResponse.java index c819c591468ea..806510f58f03a 100644 --- a/server/src/main/java/org/opensearch/action/termvectors/MultiTermVectorsShardResponse.java +++ b/server/src/main/java/org/opensearch/action/termvectors/MultiTermVectorsShardResponse.java @@ -32,7 +32,6 @@ package org.opensearch.action.termvectors; -import com.carrotsearch.hppc.IntArrayList; import org.opensearch.action.ActionResponse; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; @@ -48,12 +47,12 @@ */ public class MultiTermVectorsShardResponse extends ActionResponse { - final IntArrayList locations; + final List locations; final List responses; final List failures; MultiTermVectorsShardResponse() { - locations = new IntArrayList(); + locations = new ArrayList<>(); responses = new ArrayList<>(); failures = new ArrayList<>(); } @@ -61,7 +60,7 @@ public class MultiTermVectorsShardResponse extends ActionResponse { MultiTermVectorsShardResponse(StreamInput in) throws IOException { super(in); int size = in.readVInt(); - locations = new IntArrayList(size); + locations = new ArrayList<>(size); responses = new ArrayList<>(size); failures = new ArrayList<>(size); for (int i = 0; i < size; i++) { diff --git a/server/src/main/java/org/opensearch/common/transport/PortsRange.java b/server/src/main/java/org/opensearch/common/transport/PortsRange.java index 30ab5e355f090..daf3e00c062fa 100644 --- a/server/src/main/java/org/opensearch/common/transport/PortsRange.java +++ b/server/src/main/java/org/opensearch/common/transport/PortsRange.java @@ -32,8 +32,8 @@ package org.opensearch.common.transport; -import com.carrotsearch.hppc.IntArrayList; - +import java.util.ArrayList; +import java.util.List; import java.util.StringTokenizer; /** @@ -54,15 +54,12 @@ public String getPortRangeString() { } public int[] ports() throws NumberFormatException { - final IntArrayList ports = new IntArrayList(); - iterate(new PortCallback() { - @Override - public boolean onPortNumber(int portNumber) { - ports.add(portNumber); - return false; - } + final List ports = new ArrayList<>(); + iterate(portNumber -> { + ports.add(portNumber); + return false; }); - return ports.toArray(); + return ports.stream().mapToInt(Integer::intValue).toArray(); } public boolean iterate(PortCallback callback) throws NumberFormatException { diff --git a/server/src/main/java/org/opensearch/search/fetch/ShardFetchRequest.java b/server/src/main/java/org/opensearch/search/fetch/ShardFetchRequest.java index 8bccc4425b46b..5c2a7d5bf974e 100644 --- a/server/src/main/java/org/opensearch/search/fetch/ShardFetchRequest.java +++ b/server/src/main/java/org/opensearch/search/fetch/ShardFetchRequest.java @@ -32,7 +32,6 @@ package org.opensearch.search.fetch; -import com.carrotsearch.hppc.IntArrayList; import org.apache.lucene.search.FieldDoc; import org.apache.lucene.search.ScoreDoc; import org.opensearch.action.search.SearchShardTask; @@ -49,6 +48,7 @@ import org.opensearch.transport.TransportRequest; import java.io.IOException; +import java.util.Collection; import java.util.Map; /** @@ -67,9 +67,9 @@ public class ShardFetchRequest extends TransportRequest { private ScoreDoc lastEmittedDoc; - public ShardFetchRequest(ShardSearchContextId contextId, IntArrayList list, ScoreDoc lastEmittedDoc) { + public ShardFetchRequest(ShardSearchContextId contextId, Collection list, ScoreDoc lastEmittedDoc) { this.contextId = contextId; - this.docIds = list.buffer; + this.docIds = list.stream().mapToInt(Integer::intValue).toArray(); this.size = list.size(); this.lastEmittedDoc = lastEmittedDoc; } diff --git a/server/src/main/java/org/opensearch/search/fetch/ShardFetchSearchRequest.java b/server/src/main/java/org/opensearch/search/fetch/ShardFetchSearchRequest.java index f3c52e3a6abc7..8d92a86f0a017 100644 --- a/server/src/main/java/org/opensearch/search/fetch/ShardFetchSearchRequest.java +++ b/server/src/main/java/org/opensearch/search/fetch/ShardFetchSearchRequest.java @@ -32,7 +32,6 @@ package org.opensearch.search.fetch; -import com.carrotsearch.hppc.IntArrayList; import org.apache.lucene.search.ScoreDoc; import org.opensearch.LegacyESVersion; import org.opensearch.action.IndicesRequest; @@ -46,6 +45,7 @@ import org.opensearch.search.internal.ShardSearchRequest; import java.io.IOException; +import java.util.List; /** * Shard level fetch request used with search. Holds indices taken from the original search request @@ -64,7 +64,7 @@ public ShardFetchSearchRequest( OriginalIndices originalIndices, ShardSearchContextId id, ShardSearchRequest shardSearchRequest, - IntArrayList list, + List list, ScoreDoc lastEmittedDoc, RescoreDocIds rescoreDocIds, AggregatedDfs aggregatedDfs diff --git a/server/src/test/java/org/opensearch/search/SearchServiceTests.java b/server/src/test/java/org/opensearch/search/SearchServiceTests.java index 666b2b002e1e3..9c89e06b6aa5f 100644 --- a/server/src/test/java/org/opensearch/search/SearchServiceTests.java +++ b/server/src/test/java/org/opensearch/search/SearchServiceTests.java @@ -31,7 +31,6 @@ package org.opensearch.search; -import com.carrotsearch.hppc.IntArrayList; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.FilterDirectoryReader; import org.apache.lucene.index.LeafReader; @@ -359,7 +358,7 @@ public void onFailure(Exception e) { result ); SearchPhaseResult searchPhaseResult = result.get(); - IntArrayList intCursors = new IntArrayList(1); + List intCursors = new ArrayList(1); intCursors.add(0); ShardFetchRequest req = new ShardFetchRequest(searchPhaseResult.getContextId(), intCursors, null/* not a scroll */); PlainActionFuture listener = new PlainActionFuture<>(); diff --git a/test/framework/src/main/java/org/opensearch/test/TestCluster.java b/test/framework/src/main/java/org/opensearch/test/TestCluster.java index 478b692fb06ef..3dcaaefea61f9 100644 --- a/test/framework/src/main/java/org/opensearch/test/TestCluster.java +++ b/test/framework/src/main/java/org/opensearch/test/TestCluster.java @@ -32,8 +32,6 @@ package org.opensearch.test; -import com.carrotsearch.hppc.ObjectArrayList; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.action.admin.cluster.state.ClusterStateResponse; @@ -53,6 +51,8 @@ import java.io.Closeable; import java.io.IOException; import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.List; import java.util.Random; import java.util.Set; @@ -189,12 +189,14 @@ public void wipeIndices(String... indices) { // which is the case in the CloseIndexDisableCloseAllTests if ("_all".equals(indices[0])) { ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().execute().actionGet(); - ObjectArrayList concreteIndices = new ObjectArrayList<>(); + List concreteIndices = new ArrayList<>(); for (IndexMetadata indexMetadata : clusterStateResponse.getState().metadata()) { concreteIndices.add(indexMetadata.getIndex().getName()); } if (!concreteIndices.isEmpty()) { - OpenSearchAssertions.assertAcked(client().admin().indices().prepareDelete(concreteIndices.toArray(String.class))); + OpenSearchAssertions.assertAcked( + client().admin().indices().prepareDelete(concreteIndices.toArray(new String[concreteIndices.size()])) + ); } } }