2727import org .elasticsearch .index .IndexSettings ;
2828import org .elasticsearch .index .codec .vectors .es818 .DirectIODirectory ;
2929import org .elasticsearch .index .shard .ShardPath ;
30+ import org .elasticsearch .logging .LogManager ;
31+ import org .elasticsearch .logging .Logger ;
3032import org .elasticsearch .plugins .IndexStorePlugin ;
3133
3234import java .io .IOException ;
3941
4042public 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