Skip to content

Commit 17dda1c

Browse files
rmuirjpountz
andcommitted
fix overflows in compound assignments (#11938)
* Count points as longs. * Simplify KnnVectorsWriter. Co-authored-by: Adrien Grand <[email protected]>
1 parent 3097f83 commit 17dda1c

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

lucene/core/src/java/org/apache/lucene/codecs/KnnVectorsWriter.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ public int nextDoc() throws IOException {
108108
protected static class MergedVectorValues extends VectorValues {
109109
private final List<VectorValuesSub> subs;
110110
private final DocIDMerger<VectorValuesSub> docIdMerger;
111-
private final int cost;
112111
private final int size;
113112

114113
private int docId;
@@ -136,12 +135,10 @@ private MergedVectorValues(List<VectorValuesSub> subs, MergeState mergeState)
136135
throws IOException {
137136
this.subs = subs;
138137
docIdMerger = DocIDMerger.of(subs, mergeState.needsIndexSort);
139-
int totalCost = 0, totalSize = 0;
138+
int totalSize = 0;
140139
for (VectorValuesSub sub : subs) {
141-
totalCost += sub.values.cost();
142140
totalSize += sub.values.size();
143141
}
144-
cost = totalCost;
145142
size = totalSize;
146143
docId = -1;
147144
}
@@ -184,7 +181,7 @@ public int size() {
184181

185182
@Override
186183
public long cost() {
187-
return cost;
184+
return size;
188185
}
189186

190187
@Override

lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ private long pointCount(
415415
BiFunction<byte[], byte[], Relation> nodeComparator,
416416
Predicate<byte[]> leafComparator)
417417
throws IOException {
418-
final int[] matchingNodeCount = {0};
418+
final long[] matchingNodeCount = {0};
419419
// create a custom IntersectVisitor that records the number of leafNodes that matched
420420
final IntersectVisitor visitor =
421421
new IntersectVisitor() {
@@ -446,7 +446,7 @@ public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
446446
}
447447

448448
private void pointCount(
449-
IntersectVisitor visitor, PointValues.PointTree pointTree, int[] matchingNodeCount)
449+
IntersectVisitor visitor, PointValues.PointTree pointTree, long[] matchingNodeCount)
450450
throws IOException {
451451
Relation r = visitor.compare(pointTree.getMinPackedValue(), pointTree.getMaxPackedValue());
452452
switch (r) {

lucene/core/src/java/org/apache/lucene/util/OfflineSorter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public class SortInfo {
141141
/** number of partition merges */
142142
public int mergeRounds;
143143
/** number of lines of data read */
144-
public int lineCount;
144+
public long lineCount;
145145
/** time spent merging sorted partitions (in milliseconds) */
146146
public final AtomicLong mergeTimeMS = new AtomicLong();
147147
/** time spent sorting data (in milliseconds) */

0 commit comments

Comments
 (0)