Skip to content

Commit 8ec65ef

Browse files
authored
Only use direct IO when opening with Default IOContext and using the hybrid directory (#129530)
This commit updates the DIO format so that it only use direct IO when opening with Default IOContext and using the hybrid directory. I also took the opportunity to better align the code with where we ultimately want to get to (what is in the lucene_snapshot branch).
1 parent 1a615fc commit 8ec65ef

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

muted-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,12 +472,6 @@ tests:
472472
- class: org.elasticsearch.packaging.test.DockerTests
473473
method: test040JavaUsesTheOsProvidedKeystore
474474
issue: https://github.com/elastic/elasticsearch/issues/128230
475-
- class: org.elasticsearch.index.codec.vectors.es818.ES818HnswBinaryQuantizedVectorsFormatTests
476-
method: testSimpleOffHeapSizeFSDir
477-
issue: https://github.com/elastic/elasticsearch/issues/128799
478-
- class: org.elasticsearch.index.codec.vectors.es818.ES818BinaryQuantizedVectorsFormatTests
479-
method: testSimpleOffHeapSizeFSDir
480-
issue: https://github.com/elastic/elasticsearch/issues/128800
481475
- class: org.elasticsearch.packaging.test.DockerTests
482476
method: test150MachineDependentHeap
483477
issue: https://github.com/elastic/elasticsearch/issues/128120

server/src/main/java/org/elasticsearch/index/codec/vectors/es818/DirectIOLucene99FlatVectorsFormat.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import org.apache.lucene.codecs.lucene99.Lucene99FlatVectorsWriter;
2828
import org.apache.lucene.index.SegmentReadState;
2929
import org.apache.lucene.index.SegmentWriteState;
30+
import org.apache.lucene.store.FilterDirectory;
31+
import org.apache.lucene.store.IOContext;
32+
import org.elasticsearch.index.store.FsDirectoryFactory;
3033

3134
import java.io.IOException;
3235

@@ -61,9 +64,15 @@ public FlatVectorsWriter fieldsWriter(SegmentWriteState state) throws IOExceptio
6164
return new Lucene99FlatVectorsWriter(state, vectorsScorer);
6265
}
6366

67+
static boolean shouldUseDirectIO(SegmentReadState state) {
68+
assert ES818BinaryQuantizedVectorsFormat.USE_DIRECT_IO;
69+
return FsDirectoryFactory.isHybridFs(state.directory)
70+
&& FilterDirectory.unwrap(state.directory) instanceof DirectIOIndexInputSupplier;
71+
}
72+
6473
@Override
6574
public FlatVectorsReader fieldsReader(SegmentReadState state) throws IOException {
66-
if (DirectIOLucene99FlatVectorsReader.shouldUseDirectIO(state)) {
75+
if (shouldUseDirectIO(state) && state.context.context() == IOContext.Context.DEFAULT) {
6776
// Use mmap for merges and direct I/O for searches.
6877
// TODO: Open the mmap file with sequential access instead of random (current behavior).
6978
return new MergeReaderWrapper(

server/src/main/java/org/elasticsearch/index/codec/vectors/es818/DirectIOLucene99FlatVectorsReader.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@
5757
@SuppressForbidden(reason = "Copied from lucene")
5858
public class DirectIOLucene99FlatVectorsReader extends FlatVectorsReader implements OffHeapStats {
5959

60-
private static final boolean USE_DIRECT_IO = Boolean.parseBoolean(System.getProperty("vector.rescoring.directio", "true"));
61-
6260
private static final long SHALLOW_SIZE = RamUsageEstimator.shallowSizeOfInstance(DirectIOLucene99FlatVectorsReader.class);
6361

6462
private final IntObjectHashMap<FieldEntry> fields = new IntObjectHashMap<>();
@@ -89,10 +87,6 @@ public DirectIOLucene99FlatVectorsReader(SegmentReadState state, FlatVectorsScor
8987
}
9088
}
9189

92-
public static boolean shouldUseDirectIO(SegmentReadState state) {
93-
return USE_DIRECT_IO && FilterDirectory.unwrap(state.directory) instanceof DirectIOIndexInputSupplier;
94-
}
95-
9690
private int readMetadata(SegmentReadState state) throws IOException {
9791
String metaFileName = IndexFileNames.segmentFileName(
9892
state.segmentInfo.name,
@@ -130,7 +124,8 @@ private static IndexInput openDataInput(
130124
) throws IOException {
131125
String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, fileExtension);
132126
// use direct IO for accessing raw vector data for searches
133-
IndexInput in = USE_DIRECT_IO && FilterDirectory.unwrap(state.directory) instanceof DirectIOIndexInputSupplier did
127+
assert ES818BinaryQuantizedVectorsFormat.USE_DIRECT_IO;
128+
IndexInput in = FilterDirectory.unwrap(state.directory) instanceof DirectIOIndexInputSupplier did
134129
? did.openInputDirect(fileName, context)
135130
: state.directory.openInput(fileName, context);
136131
boolean success = false;

server/src/main/java/org/elasticsearch/index/codec/vectors/es818/ES818BinaryQuantizedVectorsFormat.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.lucene.codecs.hnsw.FlatVectorsFormat;
2424
import org.apache.lucene.codecs.hnsw.FlatVectorsReader;
2525
import org.apache.lucene.codecs.hnsw.FlatVectorsWriter;
26+
import org.apache.lucene.codecs.lucene99.Lucene99FlatVectorsFormat;
2627
import org.apache.lucene.index.SegmentReadState;
2728
import org.apache.lucene.index.SegmentWriteState;
2829
import org.elasticsearch.index.codec.vectors.OptimizedScalarQuantizer;
@@ -86,6 +87,8 @@
8687
*/
8788
public class ES818BinaryQuantizedVectorsFormat extends FlatVectorsFormat {
8889

90+
static final boolean USE_DIRECT_IO = Boolean.parseBoolean(System.getProperty("vector.rescoring.directio", "true"));
91+
8992
public static final String BINARIZED_VECTOR_COMPONENT = "BVEC";
9093
public static final String NAME = "ES818BinaryQuantizedVectorsFormat";
9194

@@ -97,9 +100,9 @@ public class ES818BinaryQuantizedVectorsFormat extends FlatVectorsFormat {
97100
static final String VECTOR_DATA_EXTENSION = "veb";
98101
static final int DIRECT_MONOTONIC_BLOCK_SHIFT = 16;
99102

100-
private static final DirectIOLucene99FlatVectorsFormat rawVectorFormat = new DirectIOLucene99FlatVectorsFormat(
101-
FlatVectorScorerUtil.getLucene99FlatVectorsScorer()
102-
);
103+
private static final FlatVectorsFormat rawVectorFormat = USE_DIRECT_IO
104+
? new DirectIOLucene99FlatVectorsFormat(FlatVectorScorerUtil.getLucene99FlatVectorsScorer())
105+
: new Lucene99FlatVectorsFormat(FlatVectorScorerUtil.getLucene99FlatVectorsScorer());
103106

104107
private static final ES818BinaryFlatVectorsScorer scorer = new ES818BinaryFlatVectorsScorer(
105108
FlatVectorScorerUtil.getLucene99FlatVectorsScorer()

0 commit comments

Comments
 (0)