Skip to content

Commit fe92fc8

Browse files
committed
Specify a hint that no special behavior should be used
1 parent 4a09806 commit fe92fc8

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

plugins/store-smb/src/main/java/org/elasticsearch/index/store/smb/SmbMmapFsDirectoryFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public final class SmbMmapFsDirectoryFactory extends FsDirectoryFactory {
2525
@Override
2626
protected Directory newFSDirectory(Path location, LockFactory lockFactory, IndexSettings indexSettings) throws IOException {
2727
return new SmbDirectoryWrapper(
28-
setPreload(
28+
setMMapFunctions(
2929
new MMapDirectory(location, lockFactory),
3030
new HashSet<>(indexSettings.getValue(IndexModule.INDEX_STORE_PRE_LOAD_SETTING))
3131
)

server/src/main/java/org/elasticsearch/index/IndexVersions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private static Version parseUnchecked(String version) {
163163
public static final IndexVersion UPGRADE_TO_LUCENE_10_2_1 = def(9_023_00_0, Version.LUCENE_10_2_1);
164164
public static final IndexVersion DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ = def(9_024_0_00, Version.LUCENE_10_2_1);
165165
public static final IndexVersion SEMANTIC_TEXT_DEFAULTS_TO_BBQ = def(9_025_0_00, Version.LUCENE_10_2_1);
166-
166+
167167
public static final IndexVersion UPGRADE_TO_LUCENE_10_3_0 = def(9_050_00_0, Version.LUCENE_10_3_0);
168168
/*
169169
* STOP! READ THIS FIRST! No, really,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.index;
11+
12+
import org.apache.lucene.store.IOContext;
13+
14+
/**
15+
* A hint that no special behavior should be set on open files
16+
*/
17+
public enum StandardIOBehaviorHint implements IOContext.FileOpenHint {
18+
INSTANCE
19+
}

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
import org.apache.lucene.store.MMapDirectory;
2121
import org.apache.lucene.store.NIOFSDirectory;
2222
import org.apache.lucene.store.NativeFSLockFactory;
23+
import org.apache.lucene.store.ReadAdvice;
2324
import org.apache.lucene.store.SimpleFSLockFactory;
2425
import org.elasticsearch.common.settings.Setting;
2526
import org.elasticsearch.common.settings.Setting.Property;
2627
import org.elasticsearch.core.IOUtils;
2728
import org.elasticsearch.index.IndexModule;
2829
import org.elasticsearch.index.IndexSettings;
30+
import org.elasticsearch.index.StandardIOBehaviorHint;
2931
import org.elasticsearch.index.codec.vectors.es818.DirectIOIndexInputSupplier;
3032
import org.elasticsearch.index.shard.ShardPath;
3133
import org.elasticsearch.logging.LogManager;
@@ -36,6 +38,7 @@
3638
import java.nio.file.Files;
3739
import java.nio.file.Path;
3840
import java.util.HashSet;
41+
import java.util.Optional;
3942
import java.util.OptionalLong;
4043
import java.util.Set;
4144
import java.util.function.BiPredicate;
@@ -75,12 +78,12 @@ protected Directory newFSDirectory(Path location, LockFactory lockFactory, Index
7578
// Use Lucene defaults
7679
final FSDirectory primaryDirectory = FSDirectory.open(location, lockFactory);
7780
if (primaryDirectory instanceof MMapDirectory mMapDirectory) {
78-
return new HybridDirectory(lockFactory, setPreload(mMapDirectory, preLoadExtensions));
81+
return new HybridDirectory(lockFactory, setMMapFunctions(mMapDirectory, preLoadExtensions));
7982
} else {
8083
return primaryDirectory;
8184
}
8285
case MMAPFS:
83-
return setPreload(new MMapDirectory(location, lockFactory), preLoadExtensions);
86+
return setMMapFunctions(new MMapDirectory(location, lockFactory), preLoadExtensions);
8487
case SIMPLEFS:
8588
case NIOFS:
8689
return new NIOFSDirectory(location, lockFactory);
@@ -89,10 +92,18 @@ protected Directory newFSDirectory(Path location, LockFactory lockFactory, Index
8992
}
9093
}
9194

95+
private static Optional<ReadAdvice> overrideReadAdvice(String name, IOContext context) {
96+
if (context.hints().contains(StandardIOBehaviorHint.INSTANCE)) {
97+
return Optional.of(ReadAdvice.NORMAL);
98+
}
99+
return Optional.empty();
100+
}
101+
92102
/** Sets the preload, if any, on the given directory based on the extensions. Returns the same directory instance. */
93103
// visibility and extensibility for testing
94-
public MMapDirectory setPreload(MMapDirectory mMapDirectory, Set<String> preLoadExtensions) {
104+
public MMapDirectory setMMapFunctions(MMapDirectory mMapDirectory, Set<String> preLoadExtensions) {
95105
mMapDirectory.setPreload(getPreloadFunc(preLoadExtensions));
106+
mMapDirectory.setReadAdviceOverride(FsDirectoryFactory::overrideReadAdvice);
96107
return mMapDirectory;
97108
}
98109

server/src/test/java/org/elasticsearch/index/store/FsDirectoryFactoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static class PreLoadExposingFsDirectoryFactory extends FsDirectoryFactory {
8888
final Map<MMapDirectory, BiPredicate<String, IOContext>> preLoadFuncMap = new HashMap<>();
8989

9090
@Override
91-
public MMapDirectory setPreload(MMapDirectory mMapDirectory, Set<String> preLoadExtensions) {
91+
public MMapDirectory setMMapFunctions(MMapDirectory mMapDirectory, Set<String> preLoadExtensions) {
9292
var preLoadFunc = FsDirectoryFactory.getPreloadFunc(preLoadExtensions);
9393
mMapDirectory.setPreload(preLoadFunc);
9494
preLoadFuncMap.put(mMapDirectory, preLoadFunc);

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/store/input/CachedBlobContainerIndexInput.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import org.apache.logging.log4j.LogManager;
1111
import org.apache.logging.log4j.Logger;
1212
import org.apache.lucene.store.IOContext;
13-
import org.apache.lucene.store.ReadAdvice;
1413
import org.elasticsearch.blobcache.BlobCacheUtils;
1514
import org.elasticsearch.blobcache.common.ByteRange;
15+
import org.elasticsearch.index.StandardIOBehaviorHint;
1616
import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot.FileInfo;
1717
import org.elasticsearch.xpack.searchablesnapshots.cache.common.CacheFile;
1818
import org.elasticsearch.xpack.searchablesnapshots.store.IndexInputStats;
@@ -36,7 +36,7 @@ public class CachedBlobContainerIndexInput extends MetadataCachingIndexInput {
3636
* a complete part of the {@link #fileInfo} at once in the cache and should not be
3737
* used for anything else than what the {@link #prefetchPart(int, Supplier)} method does.
3838
*/
39-
public static final IOContext CACHE_WARMING_CONTEXT = new IOContext(IOContext.Context.DEFAULT, null, null, ReadAdvice.NORMAL);
39+
public static final IOContext CACHE_WARMING_CONTEXT = IOContext.DEFAULT.withHints(StandardIOBehaviorHint.INSTANCE);
4040

4141
private static final Logger logger = LogManager.getLogger(CachedBlobContainerIndexInput.class);
4242

0 commit comments

Comments
 (0)