diff --git a/lucene/core/src/java/org/apache/lucene/store/IOContext.java b/lucene/core/src/java/org/apache/lucene/store/IOContext.java index 3bb37ae1d191..f2c038d1bfde 100644 --- a/lucene/core/src/java/org/apache/lucene/store/IOContext.java +++ b/lucene/core/src/java/org/apache/lucene/store/IOContext.java @@ -54,7 +54,7 @@ public enum Context { * This flag is used for files that are a small fraction of the total index size and are expected * to be heavily accessed in random-access fashion. Some {@link Directory} implementations may * choose to load such files into physical memory (e.g. Java heap) as a way to provide stronger - * guarantees on query latency. + * guarantees on query latency. If this flag is set, then {@link #randomAccess} will be true. */ public final boolean load; @@ -64,7 +64,7 @@ public enum Context { public static final IOContext READ = new IOContext(false, false, false); - public static final IOContext LOAD = new IOContext(false, true, false); + public static final IOContext LOAD = new IOContext(false, true, true); public static final IOContext RANDOM = new IOContext(false, false, true); @@ -90,6 +90,9 @@ private IOContext(boolean readOnce, boolean load, boolean randomAccess) { if (readOnce && randomAccess) { throw new IllegalArgumentException("cannot be both readOnce and randomAccess"); } + if (load && randomAccess == false) { + throw new IllegalArgumentException("cannot be load but not randomAccess"); + } this.context = Context.READ; this.mergeInfo = null; this.readOnce = readOnce; diff --git a/lucene/core/src/java21/org/apache/lucene/store/PosixNativeAccess.java b/lucene/core/src/java21/org/apache/lucene/store/PosixNativeAccess.java index 39c0e4129b8c..b0cf34c9dcf4 100644 --- a/lucene/core/src/java21/org/apache/lucene/store/PosixNativeAccess.java +++ b/lucene/core/src/java21/org/apache/lucene/store/PosixNativeAccess.java @@ -81,6 +81,7 @@ private static MethodHandle findFunction( @Override public void madvise(MemorySegment segment, IOContext context) throws IOException { + // Note: madvise is bypassed if the segment should be preloaded via MemorySegment#load. if (segment.byteSize() == 0L) { return; // empty segments should be excluded, because they may have no address at all }