Skip to content

Commit 08d2a76

Browse files
committed
Sometimes DirectIO is not available
1 parent a2ed4c8 commit 08d2a76

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import org.elasticsearch.index.IndexSettings;
2828
import org.elasticsearch.index.codec.vectors.es818.DirectIODirectory;
2929
import org.elasticsearch.index.shard.ShardPath;
30+
import org.elasticsearch.logging.LogManager;
31+
import org.elasticsearch.logging.Logger;
3032
import org.elasticsearch.plugins.IndexStorePlugin;
3133

3234
import java.io.IOException;
@@ -39,6 +41,8 @@
3941

4042
public class FsDirectoryFactory implements IndexStorePlugin.DirectoryFactory {
4143

44+
private static final Logger Log = LogManager.getLogger(FsDirectoryFactory.class);
45+
4246
public static final Setting<LockFactory> INDEX_LOCK_FACTOR_SETTING = new Setting<>("index.store.fs.fs_lock", "native", (s) -> {
4347
return switch (s) {
4448
case "native" -> NativeFSLockFactory.INSTANCE;
@@ -118,12 +122,21 @@ static final class HybridDirectory extends NIOFSDirectory implements DirectIODir
118122
HybridDirectory(LockFactory lockFactory, MMapDirectory delegate) throws IOException {
119123
super(delegate.getDirectory(), lockFactory);
120124
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-
};
125+
126+
org.apache.lucene.misc.store.DirectIODirectory directIO;
127+
try {
128+
directIO = new org.apache.lucene.misc.store.DirectIODirectory(delegate) {
129+
@Override
130+
protected boolean useDirectIO(String name, IOContext context, OptionalLong fileLength) {
131+
return true;
132+
}
133+
};
134+
} catch (Exception e) {
135+
// directio not supported
136+
Log.warn("Could not initialize DirectIO access", e);
137+
directIO = null;
138+
}
139+
this.directIODelegate = directIO;
127140
}
128141

129142
@Override
@@ -146,6 +159,9 @@ public IndexInput openInput(String name, IOContext context) throws IOException {
146159

147160
@Override
148161
public IndexInput openInputDirect(String name, IOContext context) throws IOException {
162+
if (directIODelegate == null) {
163+
return openInput(name, context);
164+
}
149165
// we need to do these checks on the outer directory since the inner doesn't know about pending deletes
150166
ensureOpen();
151167
ensureCanRead(name);

0 commit comments

Comments
 (0)