4444import java .util .Optional ;
4545import java .util .OptionalLong ;
4646import java .util .Set ;
47+ import java .util .function .BiFunction ;
4748import java .util .function .BiPredicate ;
4849
4950public 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