Apache Lucene open-source search software
Fix OffHeapFloatVectorValues#prefetch to use bounded ord count (#16156)
vignesh_A84b7d25dabe6
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 8c0022b8596..1e88ad8715e 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -543,6 +543,9 @@ Bug Fixesinstantiated, so a crafted spatial3d shape stream cannot load arbitrary classes. Also adaptexperimental SerializedObject API to be more type safe. (metsw24-max, Uwe Schindler)+* GITHUB#16156: OffHeapFloatVectorValues#prefetch now bounds its loop by the requested+ count instead of the full ordinal array, matching OffHeapByteVectorValues. (Vignesh)+Other---------------------* GITHUB#15586: Document that scoring and ranking may change across major Lucene versions, and that applications requiring stable ranking should explicitly configure Similarity. (Parveen Saini)diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene95/OffHeapFloatVectorValues.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene95/OffHeapFloatVectorValues.javaindex 3594e017076..7219f536121 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene95/OffHeapFloatVectorValues.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene95/OffHeapFloatVectorValues.java@@ -97,7 +97,7 @@ public abstract class OffHeapFloatVectorValues extends FloatVectorValues impleme}// 1. calculate offset and prefetch immediately- for (int i = 0; i < numOrds; i++) {+ for (int i = 0; i < finalNumOrds; i++) {long offset = (long) ordsToPrefetch[i] * byteSize;slice.prefetch(offset, byteSize);}diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene95/TestOffHeapVectorValues.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene95/TestOffHeapVectorValues.javaindex fd85c1321f8..8e57dac3abe 100644--- a/lucene/core/src/test/org/apache/lucene/codecs/lucene95/TestOffHeapVectorValues.java+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene95/TestOffHeapVectorValues.java@@ -53,6 +53,20 @@ public class TestOffHeapVectorValues extends LuceneTestCase {assertEquals(0, floatIndexInput.getPrefetchCount());}+ public void testPrefetchBoundedByArrayLength() throws IOException {+ // numOrds may exceed the length of the (reused) scratch array. Prefetch must be bounded by the+ // array length so it only prefetches the available ords instead of running past the array end.+ CountingIndexInput byteIndexInput = new CountingIndexInput();+ OffHeapByteVectorValues values = createTestByteVectorValues(byteIndexInput);+ values.prefetch(new int[] {1, 2}, 5);+ assertEquals(2, byteIndexInput.getPrefetchCount());++ CountingIndexInput floatIndexInput = new CountingIndexInput();+ OffHeapFloatVectorValues floatValues = createTestFloatVectorValues(floatIndexInput);+ floatValues.prefetch(new int[] {1, 2}, 5);+ assertEquals(2, floatIndexInput.getPrefetchCount());+ }+private OffHeapByteVectorValues createTestByteVectorValues(IndexInput indexInput)throws IOException {return new OffHeapByteVectorValues.DenseOffHeapVectorValues(