You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by be...@apache.org on 2026/06/02 18:27:37 UTC

(lucene) branch main updated: Fix OffHeapFloatVectorValues#prefetch to use bounded ord count (#16156)

This is an automated email from the ASF dual-hosted git repository.

benwtrent pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new 84b7d25dabe Fix OffHeapFloatVectorValues#prefetch to use bounded ord count (#16156)
84b7d25dabe is described below

commit 84b7d25dabe61f4e280f90f1591e9a023e37a4da
Author: vignesh_A <16...@users.noreply.github.com>
AuthorDate: Tue Jun 2 23:57:31 2026 +0530

    Fix OffHeapFloatVectorValues#prefetch to use bounded ord count (#16156)
---
 lucene/CHANGES.txt                                         |  3 +++
 .../lucene/codecs/lucene95/OffHeapFloatVectorValues.java   |  2 +-
 .../lucene/codecs/lucene95/TestOffHeapVectorValues.java    | 14 ++++++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 8c0022b8596..1e88ad8715e 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -543,6 +543,9 @@ Bug Fixes
   instantiated, so a crafted spatial3d shape stream cannot load arbitrary classes. Also adapt
   experimental 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.java
index 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.java
index 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(