Skip to content

Commit 80ec7ab

Browse files
authored
Update MMapDirectory ReadAdvice function (#132710)
This has changed in lucene branch_10x
1 parent f1bb39a commit 80ec7ab

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.Optional;
4545
import java.util.OptionalLong;
4646
import java.util.Set;
47+
import java.util.function.BiFunction;
4748
import java.util.function.BiPredicate;
4849

4950
public class FsDirectoryFactory implements IndexStorePlugin.DirectoryFactory {
@@ -96,18 +97,11 @@ protected Directory newFSDirectory(Path location, LockFactory lockFactory, Index
9697
}
9798
}
9899

99-
private static Optional<ReadAdvice> overrideReadAdvice(String name, IOContext context) {
100-
if (context.hints().contains(StandardIOBehaviorHint.INSTANCE)) {
101-
return Optional.of(ReadAdvice.NORMAL);
102-
}
103-
return Optional.empty();
104-
}
105-
106100
/** Sets the preload, if any, on the given directory based on the extensions. Returns the same directory instance. */
107101
// visibility and extensibility for testing
108102
public MMapDirectory setMMapFunctions(MMapDirectory mMapDirectory, Set<String> preLoadExtensions) {
109103
mMapDirectory.setPreload(getPreloadFunc(preLoadExtensions));
110-
mMapDirectory.setReadAdviceOverride(FsDirectoryFactory::overrideReadAdvice);
104+
mMapDirectory.setReadAdvice(getReadAdviceFunc());
111105
return mMapDirectory;
112106
}
113107

@@ -123,6 +117,15 @@ static BiPredicate<String, IOContext> getPreloadFunc(Set<String> preLoadExtensio
123117
return MMapDirectory.NO_FILES;
124118
}
125119

120+
private static BiFunction<String, IOContext, Optional<ReadAdvice>> getReadAdviceFunc() {
121+
return (name, context) -> {
122+
if (context.hints().contains(StandardIOBehaviorHint.INSTANCE)) {
123+
return Optional.of(ReadAdvice.NORMAL);
124+
}
125+
return MMapDirectory.ADVISE_BY_CONTEXT.apply(name, context);
126+
};
127+
}
128+
126129
/**
127130
* Returns true iff the directory is a hybrid fs directory
128131
*/

0 commit comments

Comments
 (0)