Skip to content

Commit

Permalink
SOLR-17190: Replace org.apache.solr.util.LongSet with hppc LongHashSet (
Browse files Browse the repository at this point in the history
  • Loading branch information
magibney authored Mar 5, 2024
1 parent b0af29f commit 4a02d1a
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 198 deletions.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ Other Changes
* SOLR-17066: GenericSolrRequest now has a `setRequiresCollection` setter that allows it to specify whether
it should make use of the client-level default collection/core. (Jason Gerlowski)

* SOLR-17190: Replace org.apache.solr.util.LongSet with hppc LongHashSet (Michael Gibney)

================== 9.5.0 ==================
New Features
---------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import static org.apache.solr.common.params.CommonParams.VERSION_FIELD;
import static org.apache.solr.search.QueryUtils.makeQueryable;

import com.carrotsearch.hppc.LongHashSet;
import com.carrotsearch.hppc.LongSet;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
Expand Down Expand Up @@ -94,7 +96,6 @@
import org.apache.solr.update.PeerSyncWithLeader;
import org.apache.solr.update.UpdateLog;
import org.apache.solr.update.processor.AtomicUpdateDocumentMerger;
import org.apache.solr.util.LongSet;
import org.apache.solr.util.RefCounted;
import org.apache.solr.util.TestInjection;
import org.slf4j.Logger;
Expand Down Expand Up @@ -1342,7 +1343,7 @@ public void processGetUpdates(ResponseBuilder rb) throws IOException {

// TODO: get this from cache instead of rebuilding?
try (UpdateLog.RecentUpdates recentUpdates = ulog.getRecentUpdates()) {
LongSet updateVersions = new LongSet(versions.size());
LongSet updateVersions = new LongHashSet(versions.size());
for (Long version : versions) {
try {
Object o = recentUpdates.lookup(version);
Expand Down
14 changes: 7 additions & 7 deletions solr/core/src/java/org/apache/solr/search/facet/UniqueAgg.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package org.apache.solr.search.facet;

import com.carrotsearch.hppc.LongHashSet;
import com.carrotsearch.hppc.LongSet;
import com.carrotsearch.hppc.cursors.LongCursor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -27,8 +30,6 @@
import org.apache.solr.common.util.CollectionUtil;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.util.LongIterator;
import org.apache.solr.util.LongSet;

public class UniqueAgg extends StrAggValueSource {
public static final String UNIQUE = "unique";
Expand Down Expand Up @@ -146,7 +147,7 @@ public void resize(Resizer resizer) {
protected void collectValues(int doc, int slot) throws IOException {
LongSet set = sets[slot];
if (set == null) {
set = sets[slot] = new LongSet(16);
set = sets[slot] = new LongHashSet(16);
}
collectValues(doc, set);
}
Expand All @@ -172,7 +173,7 @@ private long getNonShardValue(int slot) {
*/
private int getCardinality(int slot) {
LongSet set = sets[slot];
return set == null ? 0 : set.cardinality();
return set == null ? 0 : set.size();
}

public Object getShardValue(int slot) throws IOException {
Expand All @@ -188,9 +189,8 @@ public Object getShardValue(int slot) throws IOException {
if (unique <= maxExplicit) {
List<Long> lst = new ArrayList<>(Math.min(unique, maxExplicit));
if (set != null) {
LongIterator iter = set.iterator();
while (iter.hasNext()) {
lst.add(iter.next());
for (LongCursor v : set) {
lst.add(v.value);
}
}
map.add(VALS, lst);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.apache.solr.search.join;

import com.carrotsearch.hppc.LongHashSet;
import com.carrotsearch.hppc.LongSet;
import com.carrotsearch.hppc.cursors.LongCursor;
import java.io.IOException;
import org.apache.lucene.document.DoublePoint;
import org.apache.lucene.document.FloatPoint;
Expand All @@ -30,14 +33,12 @@
import org.apache.solr.schema.NumberType;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.DocSet;
import org.apache.solr.util.LongIterator;
import org.apache.solr.util.LongSet;

/**
* @lucene.internal
*/
public class GraphPointsCollector extends GraphEdgeCollector {
final LongSet set = new LongSet(256);
final LongSet set = new LongHashSet(256);

SortedNumericDocValues values = null;

Expand Down Expand Up @@ -70,7 +71,7 @@ void addEdgeIdsToResult(int doc) throws IOException {

@Override
public Query getResultQuery(SchemaField matchField, boolean useAutomaton) {
if (set.cardinality() == 0) return null;
if (set.isEmpty()) return null;

Query q = null;

Expand All @@ -81,38 +82,34 @@ public Query getResultQuery(SchemaField matchField, boolean useAutomaton) {
boolean multiValued = collectField.multiValued();

if (ntype == NumberType.LONG || ntype == NumberType.DATE) {
long[] vals = new long[set.cardinality()];
long[] vals = new long[set.size()];
int i = 0;
for (LongIterator iter = set.iterator(); iter.hasNext(); ) {
long bits = iter.next();
long v = bits;
vals[i++] = v;
for (LongCursor c : set) {
vals[i++] = c.value;
}
q = LongPoint.newSetQuery(matchField.getName(), vals);
} else if (ntype == NumberType.INTEGER) {
int[] vals = new int[set.cardinality()];
int[] vals = new int[set.size()];
int i = 0;
for (LongIterator iter = set.iterator(); iter.hasNext(); ) {
long bits = iter.next();
int v = (int) bits;
vals[i++] = v;
for (LongCursor c : set) {
vals[i++] = (int) c.value;
}
q = IntPoint.newSetQuery(matchField.getName(), vals);
} else if (ntype == NumberType.DOUBLE) {
double[] vals = new double[set.cardinality()];
double[] vals = new double[set.size()];
int i = 0;
for (LongIterator iter = set.iterator(); iter.hasNext(); ) {
long bits = iter.next();
for (LongCursor c : set) {
long bits = c.value;
double v =
multiValued ? NumericUtils.sortableLongToDouble(bits) : Double.longBitsToDouble(bits);
vals[i++] = v;
}
q = DoublePoint.newSetQuery(matchField.getName(), vals);
} else if (ntype == NumberType.FLOAT) {
float[] vals = new float[set.cardinality()];
float[] vals = new float[set.size()];
int i = 0;
for (LongIterator iter = set.iterator(); iter.hasNext(); ) {
long bits = iter.next();
for (LongCursor c : set) {
long bits = c.value;
float v =
multiValued
? NumericUtils.sortableIntToFloat((int) bits)
Expand Down
5 changes: 3 additions & 2 deletions solr/core/src/java/org/apache/solr/update/UpdateLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import static org.apache.solr.update.processor.DistributedUpdateProcessor.DistribPhase.FROMLEADER;
import static org.apache.solr.update.processor.DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM;

import com.carrotsearch.hppc.LongHashSet;
import com.carrotsearch.hppc.LongSet;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Meter;
import java.io.Closeable;
Expand Down Expand Up @@ -80,7 +82,6 @@
import org.apache.solr.update.processor.DistributedUpdateProcessor;
import org.apache.solr.update.processor.UpdateRequestProcessor;
import org.apache.solr.update.processor.UpdateRequestProcessorChain;
import org.apache.solr.util.LongSet;
import org.apache.solr.util.OrderedExecutor;
import org.apache.solr.util.RefCounted;
import org.apache.solr.util.TestInjection;
Expand Down Expand Up @@ -1545,7 +1546,7 @@ public Set<Long> getBufferUpdates() {

public List<Long> getVersions(int n, long maxVersion) {
List<Long> ret = new ArrayList<>(n);
LongSet set = new LongSet(n);
LongSet set = new LongHashSet(n);
final int nInput = n;

for (List<Update> singleList : updateList) {
Expand Down
144 changes: 0 additions & 144 deletions solr/core/src/java/org/apache/solr/util/LongSet.java

This file was deleted.

Loading

0 comments on commit 4a02d1a

Please sign in to comment.