Skip to content

Commit 6086437

Browse files
authored
[DiskBBQ] Open vector tmp files with ReadAdvice.SEQUENTIAL (#133375)
1 parent e4f5ce7 commit 6086437

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

server/src/main/java/org/elasticsearch/index/codec/vectors/IVFVectorsWriter.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.lucene.store.IndexInput;
2929
import org.apache.lucene.store.IndexOutput;
3030
import org.apache.lucene.store.RandomAccessInput;
31+
import org.apache.lucene.store.ReadAdvice;
3132
import org.apache.lucene.util.LongValues;
3233
import org.apache.lucene.util.VectorUtil;
3334
import org.elasticsearch.core.IOUtils;
@@ -295,9 +296,17 @@ private void mergeOneFieldIVF(FieldInfo fieldInfo, MergeState mergeState) throws
295296
}
296297
}
297298
}
299+
// now open the temp file and build the index structures. It is expected these files to be read in sequential order.
300+
// Even when the file might be sample, the reads will be always in increase order, therefore we set the ReadAdvice to SEQUENTIAL
301+
// so the OS can optimize read ahead in low memory situations.
298302
try (
299-
IndexInput vectors = mergeState.segmentInfo.dir.openInput(tempRawVectorsFileName, IOContext.DEFAULT);
300-
IndexInput docs = docsFileName == null ? null : mergeState.segmentInfo.dir.openInput(docsFileName, IOContext.DEFAULT)
303+
IndexInput vectors = mergeState.segmentInfo.dir.openInput(
304+
tempRawVectorsFileName,
305+
IOContext.DEFAULT.withReadAdvice(ReadAdvice.SEQUENTIAL)
306+
);
307+
IndexInput docs = docsFileName == null
308+
? null
309+
: mergeState.segmentInfo.dir.openInput(docsFileName, IOContext.DEFAULT.withReadAdvice(ReadAdvice.SEQUENTIAL))
301310
) {
302311
final FloatVectorValues floatVectorValues = getFloatVectorValues(fieldInfo, docs, vectors, numVectors);
303312

0 commit comments

Comments
 (0)