Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set randomAccess=true on LOAD. #4

Merged
merged 5 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lucene/core/src/java/org/apache/lucene/store/IOContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand All @@ -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");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks right to me. ++

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivially, maybe add something like this to the javadoc for load:

If this flag is set, then randomAccess will be true.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, done.

}
this.context = Context.READ;
this.mergeInfo = null;
this.readOnce = readOnce;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down