Skip to content

Commit 991dd6d

Browse files
committed
Use DirectIODirectory implementation
1 parent 359fe69 commit 991dd6d

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929

3030
import java.io.IOException;
3131

32-
/** Copied from Lucene99FlatVectorsFormat in Lucene 10.1 */
32+
/**
33+
* Copied from Lucene99FlatVectorsFormat in Lucene 10.1
34+
*
35+
* This is copied to change the implementation of {@link #fieldsReader} only.
36+
* The codec format itself is not changed, so we keep the original {@link #NAME}
37+
*/
3338
public class ES818FlatVectorsFormat extends FlatVectorsFormat {
3439

3540
static final String NAME = "Lucene99FlatVectorsFormat";

server/src/main/java/org/elasticsearch/index/store/FsDirectoryFactory.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.nio.file.Files;
3434
import java.nio.file.Path;
3535
import java.util.HashSet;
36+
import java.util.OptionalLong;
3637
import java.util.Set;
3738
import java.util.function.BiPredicate;
3839

@@ -112,10 +113,17 @@ public static boolean isHybridFs(Directory directory) {
112113

113114
static final class HybridDirectory extends NIOFSDirectory implements DirectIODirectory {
114115
private final MMapDirectory delegate;
116+
private final org.apache.lucene.misc.store.DirectIODirectory directIODelegate;
115117

116118
HybridDirectory(LockFactory lockFactory, MMapDirectory delegate) throws IOException {
117119
super(delegate.getDirectory(), lockFactory);
118120
this.delegate = delegate;
121+
this.directIODelegate = new org.apache.lucene.misc.store.DirectIODirectory(delegate) {
122+
@Override
123+
protected boolean useDirectIO(String name, IOContext context, OptionalLong fileLength) {
124+
return true;
125+
}
126+
};
119127
}
120128

121129
@Override
@@ -141,13 +149,8 @@ public IndexInput openInputDirect(String name, IOContext context) throws IOExcep
141149
// we need to do these checks on the outer directory since the inner doesn't know about pending deletes
142150
ensureOpen();
143151
ensureCanRead(name);
144-
// we switch the context here since mmap checks for the READONCE context by identity
145-
context = context == Store.READONCE_CHECKSUM ? IOContext.READONCE : context;
146-
// we only use the mmap to open inputs. Everything else is managed by the NIOFSDirectory otherwise
147-
// we might run into trouble with files that are pendingDelete in one directory but still
148-
// listed in listAll() from the other. We on the other hand don't want to list files from both dirs
149-
// and intersect for perf reasons.
150-
return delegate.openInput(name, context);
152+
153+
return directIODelegate.openInput(name, context);
151154
}
152155

153156
@Override

0 commit comments

Comments
 (0)