Skip to content

Commit c34de40

Browse files
authored
Only use direct IO when opening with Default IOContext and using the hybrid directory (#128697)
This commit updates the DIO format so that it only use direct IO when opening with Default IOContext and using the hybrid directory.
1 parent c79150f commit c34de40

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.lucene.store.IOContext;
3232
import org.apache.lucene.store.MergeInfo;
3333
import org.elasticsearch.common.util.set.Sets;
34+
import org.elasticsearch.index.store.FsDirectoryFactory;
3435

3536
import java.io.IOException;
3637
import java.util.Set;
@@ -66,24 +67,30 @@ public FlatVectorsWriter fieldsWriter(SegmentWriteState state) throws IOExceptio
6667
return new Lucene99FlatVectorsWriter(state, vectorsScorer);
6768
}
6869

70+
static boolean shouldUseDirectIO(SegmentReadState state) {
71+
return FsDirectoryFactory.isHybridFs(state.directory);
72+
}
73+
6974
@Override
7075
public FlatVectorsReader fieldsReader(SegmentReadState state) throws IOException {
71-
// only override the context for the random-access use case
72-
SegmentReadState directIOState = state.context.context() == IOContext.Context.DEFAULT
73-
? new SegmentReadState(
76+
if (shouldUseDirectIO(state) && state.context.context() == IOContext.Context.DEFAULT) {
77+
// only override the context for the random-access use case
78+
SegmentReadState directIOState = new SegmentReadState(
7479
state.directory,
7580
state.segmentInfo,
7681
state.fieldInfos,
7782
new DirectIOContext(state.context.hints()),
7883
state.segmentSuffix
79-
)
80-
: state;
81-
// Use mmap for merges and direct I/O for searches.
82-
// TODO: Open the mmap file with sequential access instead of random (current behavior).
83-
return new MergeReaderWrapper(
84-
new Lucene99FlatVectorsReader(directIOState, vectorsScorer),
85-
new Lucene99FlatVectorsReader(state, vectorsScorer)
86-
);
84+
);
85+
// Use mmap for merges and direct I/O for searches.
86+
// TODO: Open the mmap file with sequential access instead of random (current behavior).
87+
return new MergeReaderWrapper(
88+
new Lucene99FlatVectorsReader(directIOState, vectorsScorer),
89+
new Lucene99FlatVectorsReader(state, vectorsScorer)
90+
);
91+
} else {
92+
return new Lucene99FlatVectorsReader(state, vectorsScorer);
93+
}
8794
}
8895

8996
@Override

0 commit comments

Comments
 (0)