Skip to content

Commit

Permalink
Allow choosing Direct IO using index setting
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Jan 23, 2024
1 parent 2d073f4 commit ffad969
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
MapperService.INDEX_MAPPING_FIELD_NAME_LENGTH_LIMIT_SETTING,
BitsetFilterCache.INDEX_LOAD_RANDOM_ACCESS_FILTERS_EAGERLY_SETTING,
IndexModule.INDEX_STORE_TYPE_SETTING,
IndexModule.INDEX_STORE_DIRECT_IO_SETTING,
IndexModule.INDEX_STORE_PRE_LOAD_SETTING,
IndexModule.INDEX_RECOVERY_TYPE_SETTING,
IndexModule.INDEX_QUERY_CACHE_ENABLED_SETTING,
Expand Down
6 changes: 6 additions & 0 deletions server/src/main/java/org/elasticsearch/index/IndexModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ public final class IndexModule {
Property.NodeScope
);

public static final Setting<Boolean> INDEX_STORE_DIRECT_IO_SETTING = Setting.boolSetting(
"index.store.direct_io",
false,
Property.IndexScope
);

public static final Setting<String> INDEX_RECOVERY_TYPE_SETTING = new Setting<>(
"index.recovery.type",
"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.elasticsearch.index.store;

import org.apache.lucene.misc.store.DirectIODirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.FileSwitchDirectory;
Expand Down Expand Up @@ -61,23 +62,32 @@ protected Directory newFSDirectory(Path location, LockFactory lockFactory, Index
type = IndexModule.Type.fromSettingsKey(storeType);
}
Set<String> preLoadExtensions = new HashSet<>(indexSettings.getValue(IndexModule.INDEX_STORE_PRE_LOAD_SETTING));
FSDirectory directory = null;
switch (type) {
case HYBRIDFS:
// Use Lucene defaults
final FSDirectory primaryDirectory = FSDirectory.open(location, lockFactory);
if (primaryDirectory instanceof MMapDirectory mMapDirectory) {
return new HybridDirectory(lockFactory, setPreload(mMapDirectory, lockFactory, preLoadExtensions));
} else {
return primaryDirectory;
directory = FSDirectory.open(location, lockFactory);
if (directory instanceof MMapDirectory mMapDirectory) {
directory = new HybridDirectory(lockFactory, setPreload(mMapDirectory, lockFactory, preLoadExtensions));
}
break;
case MMAPFS:
return setPreload(new MMapDirectory(location, lockFactory), lockFactory, preLoadExtensions);
directory = setPreload(new MMapDirectory(location, lockFactory), lockFactory, preLoadExtensions);
break;
case SIMPLEFS:
case NIOFS:
return new NIOFSDirectory(location, lockFactory);
directory = new NIOFSDirectory(location, lockFactory);
break;
default:
throw new AssertionError("unexpected built-in store type [" + type + "]");
}

final boolean useDirectIO = indexSettings.getValue(IndexModule.INDEX_STORE_DIRECT_IO_SETTING);
if (useDirectIO) {
return new DirectIODirectory(directory);
}

return directory;
}

public static MMapDirectory setPreload(MMapDirectory mMapDirectory, LockFactory lockFactory, Set<String> preLoadExtensions)
Expand Down

0 comments on commit ffad969

Please sign in to comment.