mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
Enable madvise by default for all builds (#110159)
This feature flag has been enabled by default for snapshot builds for some time, no significant bumps or changes in rally. This commit will enable it by default, even in release builds.
This commit is contained in:
parent
97650b02b9
commit
4a77e06233
2 changed files with 2 additions and 56 deletions
|
@ -21,7 +21,6 @@ import org.apache.lucene.store.NativeFSLockFactory;
|
|||
import org.apache.lucene.store.SimpleFSLockFactory;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Setting.Property;
|
||||
import org.elasticsearch.common.util.FeatureFlag;
|
||||
import org.elasticsearch.core.IOUtils;
|
||||
import org.elasticsearch.index.IndexModule;
|
||||
import org.elasticsearch.index.IndexSettings;
|
||||
|
@ -36,8 +35,6 @@ import java.util.Set;
|
|||
|
||||
public class FsDirectoryFactory implements IndexStorePlugin.DirectoryFactory {
|
||||
|
||||
private static final FeatureFlag MADV_RANDOM_FEATURE_FLAG = new FeatureFlag("madv_random");
|
||||
|
||||
public static final Setting<LockFactory> INDEX_LOCK_FACTOR_SETTING = new Setting<>("index.store.fs.fs_lock", "native", (s) -> {
|
||||
return switch (s) {
|
||||
case "native" -> NativeFSLockFactory.INSTANCE;
|
||||
|
@ -69,20 +66,12 @@ public class FsDirectoryFactory implements IndexStorePlugin.DirectoryFactory {
|
|||
// Use Lucene defaults
|
||||
final FSDirectory primaryDirectory = FSDirectory.open(location, lockFactory);
|
||||
if (primaryDirectory instanceof MMapDirectory mMapDirectory) {
|
||||
Directory dir = new HybridDirectory(lockFactory, setPreload(mMapDirectory, lockFactory, preLoadExtensions));
|
||||
if (MADV_RANDOM_FEATURE_FLAG.isEnabled() == false) {
|
||||
dir = disableRandomAdvice(dir);
|
||||
}
|
||||
return dir;
|
||||
return new HybridDirectory(lockFactory, setPreload(mMapDirectory, lockFactory, preLoadExtensions));
|
||||
} else {
|
||||
return primaryDirectory;
|
||||
}
|
||||
case MMAPFS:
|
||||
Directory dir = setPreload(new MMapDirectory(location, lockFactory), lockFactory, preLoadExtensions);
|
||||
if (MADV_RANDOM_FEATURE_FLAG.isEnabled() == false) {
|
||||
dir = disableRandomAdvice(dir);
|
||||
}
|
||||
return dir;
|
||||
return setPreload(new MMapDirectory(location, lockFactory), lockFactory, preLoadExtensions);
|
||||
case SIMPLEFS:
|
||||
case NIOFS:
|
||||
return new NIOFSDirectory(location, lockFactory);
|
||||
|
@ -104,23 +93,6 @@ public class FsDirectoryFactory implements IndexStorePlugin.DirectoryFactory {
|
|||
return mMapDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link FilterDirectory} around the provided {@link Directory} that forcefully disables {@link IOContext#RANDOM random
|
||||
* access}.
|
||||
*/
|
||||
static Directory disableRandomAdvice(Directory dir) {
|
||||
return new FilterDirectory(dir) {
|
||||
@Override
|
||||
public IndexInput openInput(String name, IOContext context) throws IOException {
|
||||
if (context.randomAccess) {
|
||||
context = IOContext.READ;
|
||||
}
|
||||
assert context.randomAccess == false;
|
||||
return super.openInput(name, context);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true iff the directory is a hybrid fs directory
|
||||
*/
|
||||
|
|
|
@ -8,12 +8,9 @@
|
|||
package org.elasticsearch.index.store;
|
||||
|
||||
import org.apache.lucene.store.AlreadyClosedException;
|
||||
import org.apache.lucene.store.ByteBuffersDirectory;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.FilterDirectory;
|
||||
import org.apache.lucene.store.IOContext;
|
||||
import org.apache.lucene.store.IndexInput;
|
||||
import org.apache.lucene.store.IndexOutput;
|
||||
import org.apache.lucene.store.MMapDirectory;
|
||||
import org.apache.lucene.store.NIOFSDirectory;
|
||||
import org.apache.lucene.store.NoLockFactory;
|
||||
|
@ -69,29 +66,6 @@ public class FsDirectoryFactoryTests extends ESTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testDisableRandomAdvice() throws IOException {
|
||||
Directory dir = new FilterDirectory(new ByteBuffersDirectory()) {
|
||||
@Override
|
||||
public IndexInput openInput(String name, IOContext context) throws IOException {
|
||||
assertFalse(context.randomAccess);
|
||||
return super.openInput(name, context);
|
||||
}
|
||||
};
|
||||
Directory noRandomAccessDir = FsDirectoryFactory.disableRandomAdvice(dir);
|
||||
try (IndexOutput out = noRandomAccessDir.createOutput("foo", IOContext.DEFAULT)) {
|
||||
out.writeInt(42);
|
||||
}
|
||||
// Test the tester
|
||||
expectThrows(AssertionError.class, () -> dir.openInput("foo", IOContext.RANDOM));
|
||||
|
||||
// The wrapped directory shouldn't fail regardless of the IOContext
|
||||
for (IOContext context : Arrays.asList(IOContext.READ, IOContext.DEFAULT, IOContext.READONCE, IOContext.RANDOM)) {
|
||||
try (IndexInput in = noRandomAccessDir.openInput("foo", context)) {
|
||||
assertEquals(42, in.readInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Directory newDirectory(Settings settings) throws IOException {
|
||||
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("foo", settings);
|
||||
Path tempDir = createTempDir().resolve(idxSettings.getUUID()).resolve("0");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue