Skip to content

Commit

Permalink
[Refactor] HPPC IntArrayList and ObjectArrayList to j.u.List (opensea…
Browse files Browse the repository at this point in the history
…rch-project#8602)

Refactors usage of obsolete HPPC IntArrayList and ObjectArrayList to
java.util.List.

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
Signed-off-by: Shivansh Arora <hishiv@amazon.com>
  • Loading branch information
nknize authored and shiv0408 committed Apr 25, 2024
1 parent 33dfac4 commit 84d7412
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,13 +53,13 @@ public class MultiGetShardRequest extends SingleShardRequest<MultiGetShardReques
private boolean realtime;
private boolean refresh;

IntArrayList locations;
List<Integer> locations;
List<MultiGetRequest.Item> 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++) {
Expand All @@ -76,7 +75,7 @@ public class MultiGetShardRequest extends SingleShardRequest<MultiGetShardReques
MultiGetShardRequest(MultiGetRequest multiGetRequest, String index, int shardId) {
super(index);
this.shardId = shardId;
locations = new IntArrayList();
locations = new ArrayList<>();
items = new ArrayList<>();
preference = multiGetRequest.preference;
realtime = multiGetRequest.realtime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,20 +47,20 @@
*/
public class MultiGetShardResponse extends ActionResponse {

final IntArrayList locations;
final List<Integer> locations;
final List<GetResponse> responses;
final List<MultiGetResponse.Failure> failures;

MultiGetShardResponse() {
locations = new IntArrayList();
locations = new ArrayList<>();
responses = new ArrayList<>();
failures = new ArrayList<>();
}

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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Integer>[] 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
Expand All @@ -168,7 +167,7 @@ private void innerRun() throws Exception {
context
);
for (int i = 0; i < docIdsToLoad.length; i++) {
IntArrayList entry = docIdsToLoad[i];
List<Integer> entry = docIdsToLoad[i];
SearchPhaseResult queryResult = queryResults.get(i);
if (entry == null) { // no results for this shard ID
if (queryResult != null) {
Expand Down Expand Up @@ -205,7 +204,7 @@ private void innerRun() throws Exception {
protected ShardFetchSearchRequest createFetchRequest(
ShardSearchContextId contextId,
int index,
IntArrayList entry,
List<Integer> entry,
ScoreDoc[] lastEmittedDocPerShard,
OriginalIndices originalIndices,
ShardSearchRequest shardSearchRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Integer>[] fillDocIdsToLoad(int numShards, ScoreDoc[] shardDocs) {
final List<Integer>[] docIdsToLoad = (List<Integer>[]) new ArrayList<?>[numShards];
for (ScoreDoc shardDoc : shardDocs) {
IntArrayList shardDocIdsToLoad = docIdsToLoad[shardDoc.shardIndex];
List<Integer> shardDocIdsToLoad = docIdsToLoad[shardDoc.shardIndex];
if (shardDocIdsToLoad == null) {
shardDocIdsToLoad = docIdsToLoad[shardDoc.shardIndex] = new IntArrayList();
shardDocIdsToLoad = docIdsToLoad[shardDoc.shardIndex] = new ArrayList<>();
}
shardDocIdsToLoad.add(shardDoc.doc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,6 +47,7 @@
import org.opensearch.search.query.ScrollQuerySearchResult;
import org.opensearch.transport.Transport;

import java.util.List;
import java.util.function.BiFunction;

/**
Expand Down Expand Up @@ -104,15 +104,15 @@ public void run() {
return;
}

final IntArrayList[] docIdsToLoad = searchPhaseController.fillDocIdsToLoad(queryResults.length(), scoreDocs);
final List<Integer>[] docIdsToLoad = searchPhaseController.fillDocIdsToLoad(queryResults.length(), scoreDocs);
final ScoreDoc[] lastEmittedDocPerShard = searchPhaseController.getLastEmittedDocPerShard(
reducedQueryPhase,
queryResults.length()
);
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<Integer> docIds = docIdsToLoad[index];
if (docIds != null) {
final QuerySearchResult querySearchResult = queryResults.get(index);
ScoreDoc lastEmittedDoc = lastEmittedDocPerShard[index];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,13 +51,13 @@ public class MultiTermVectorsShardRequest extends SingleShardRequest<MultiTermVe
private int shardId;
private String preference;

IntArrayList locations;
List<Integer> locations;
List<TermVectorsRequest> 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());
Expand All @@ -71,7 +70,7 @@ public class MultiTermVectorsShardRequest extends SingleShardRequest<MultiTermVe
MultiTermVectorsShardRequest(String index, int shardId) {
super(index);
this.shardId = shardId;
locations = new IntArrayList();
locations = new ArrayList<>();
requests = new ArrayList<>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,20 +47,20 @@
*/
public class MultiTermVectorsShardResponse extends ActionResponse {

final IntArrayList locations;
final List<Integer> locations;
final List<TermVectorsResponse> responses;
final List<MultiTermVectorsResponse.Failure> failures;

MultiTermVectorsShardResponse() {
locations = new IntArrayList();
locations = new ArrayList<>();
responses = new ArrayList<>();
failures = new ArrayList<>();
}

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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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<Integer> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,6 +48,7 @@
import org.opensearch.transport.TransportRequest;

import java.io.IOException;
import java.util.Collection;
import java.util.Map;

/**
Expand All @@ -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<Integer> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

package org.opensearch.search.fetch;

import com.carrotsearch.hppc.IntArrayList;
import org.apache.lucene.search.ScoreDoc;
import org.opensearch.action.IndicesRequest;
import org.opensearch.action.OriginalIndices;
Expand All @@ -45,6 +44,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
Expand All @@ -63,7 +63,7 @@ public ShardFetchSearchRequest(
OriginalIndices originalIndices,
ShardSearchContextId id,
ShardSearchRequest shardSearchRequest,
IntArrayList list,
List<Integer> list,
ScoreDoc lastEmittedDoc,
RescoreDocIds rescoreDocIds,
AggregatedDfs aggregatedDfs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -360,7 +359,7 @@ public void onFailure(Exception e) {
result
);
SearchPhaseResult searchPhaseResult = result.get();
IntArrayList intCursors = new IntArrayList(1);
List<Integer> intCursors = new ArrayList(1);
intCursors.add(0);
ShardFetchRequest req = new ShardFetchRequest(searchPhaseResult.getContextId(), intCursors, null/* not a scroll */);
PlainActionFuture<FetchSearchResult> listener = new PlainActionFuture<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<String> concreteIndices = new ObjectArrayList<>();
List<String> 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()]))
);
}
}
}
Expand Down

0 comments on commit 84d7412

Please sign in to comment.