fix overflows in compound assignments (#11938)

* Count points as longs.

* Simplify KnnVectorsWriter.

Co-authored-by: Adrien Grand <jpountz@gmail.com>
This commit is contained in:
Robert Muir 2022-11-16 10:53:34 -05:00 committed by GitHub
parent a5e2525946
commit c5da727493
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 8 deletions

View File

@ -108,7 +108,6 @@ public abstract class KnnVectorsWriter implements Accountable, Closeable {
protected static class MergedVectorValues extends VectorValues {
private final List<VectorValuesSub> subs;
private final DocIDMerger<VectorValuesSub> docIdMerger;
private final int cost;
private final int size;
private int docId;
@ -136,12 +135,10 @@ public abstract class KnnVectorsWriter implements Accountable, Closeable {
throws IOException {
this.subs = subs;
docIdMerger = DocIDMerger.of(subs, mergeState.needsIndexSort);
int totalCost = 0, totalSize = 0;
int totalSize = 0;
for (VectorValuesSub sub : subs) {
totalCost += sub.values.cost();
totalSize += sub.values.size();
}
cost = totalCost;
size = totalSize;
docId = -1;
}
@ -184,7 +181,7 @@ public abstract class KnnVectorsWriter implements Accountable, Closeable {
@Override
public long cost() {
return cost;
return size;
}
@Override

View File

@ -415,7 +415,7 @@ public abstract class PointRangeQuery extends Query {
BiFunction<byte[], byte[], Relation> nodeComparator,
Predicate<byte[]> leafComparator)
throws IOException {
final int[] matchingNodeCount = {0};
final long[] matchingNodeCount = {0};
// create a custom IntersectVisitor that records the number of leafNodes that matched
final IntersectVisitor visitor =
new IntersectVisitor() {
@ -446,7 +446,7 @@ public abstract class PointRangeQuery extends Query {
}
private void pointCount(
IntersectVisitor visitor, PointValues.PointTree pointTree, int[] matchingNodeCount)
IntersectVisitor visitor, PointValues.PointTree pointTree, long[] matchingNodeCount)
throws IOException {
Relation r = visitor.compare(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue());
switch (r) {

View File

@ -141,7 +141,7 @@ public class OfflineSorter {
/** number of partition merges */
public int mergeRounds;
/** number of lines of data read */
public int lineCount;
public long lineCount;
/** time spent merging sorted partitions (in milliseconds) */
public final AtomicLong mergeTimeMS = new AtomicLong();
/** time spent sorting data (in milliseconds) */