Add a sysprop "org.apache.lucene.store.MMapDirectory.enableMemorySegments" (#12062)

This commit is contained in:
Uwe Schindler 2023-01-03 19:10:28 +01:00 committed by GitHub
parent 19cc6cdf66
commit 2f602c01dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -162,7 +162,9 @@ New Features
* GITHUB#12033: Support for Java 19 foreign memory support is now enabled by default, * GITHUB#12033: Support for Java 19 foreign memory support is now enabled by default,
no need to pass "--enable-preview" on the command line. If exactly Java 19 is used, no need to pass "--enable-preview" on the command line. If exactly Java 19 is used,
MMapDirectory will mmap Lucene indexes in chunks of 16 GiB (instead of 1 GiB) and MMapDirectory will mmap Lucene indexes in chunks of 16 GiB (instead of 1 GiB) and
indexes closed while queries are running can no longer crash the JVM. (Uwe Schindler) indexes closed while queries are running can no longer crash the JVM.
To disable this feature, pass the following sysprop on Java command line:
"-Dorg.apache.lucene.store.MMapDirectory.enableMemorySegments=false" (Uwe Schindler)
* GITHUB#11869: RangeOnRangeFacetCounts added, supporting numeric range "relationship" faceting over docvalue-stored * GITHUB#11869: RangeOnRangeFacetCounts added, supporting numeric range "relationship" faceting over docvalue-stored
ranges. (Marc D'Mello) ranges. (Marc D'Mello)

View File

@ -22,6 +22,7 @@ import java.lang.invoke.MethodType;
import java.nio.channels.ClosedChannelException; // javadoc @link import java.nio.channels.ClosedChannelException; // javadoc @link
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Locale; import java.util.Locale;
import java.util.Optional;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.function.BiPredicate; import java.util.function.BiPredicate;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -113,6 +114,17 @@ public class MMapDirectory extends FSDirectory {
*/ */
public static final long DEFAULT_MAX_CHUNK_SIZE; public static final long DEFAULT_MAX_CHUNK_SIZE;
/**
* This sysprop allows to control if {@code MemorySegment} API should be used on supported Java
* versions. By default it is enabled; set to {@code false} to use legacy {@code ByteBuffer}
* implementation. On command line pass {@code
* -Dorg.apache.lucene.store.MMapDirectory.enableMemorySegments=false} to disable.
*
* @lucene.internal
*/
public static final String ENABLE_MEMORY_SEGMENTS_SYSPROP =
"org.apache.lucene.store.MMapDirectory.enableMemorySegments";
final int chunkSizePower; final int chunkSizePower;
/** /**
@ -347,7 +359,22 @@ public class MMapDirectory extends FSDirectory {
} }
} }
private static boolean checkMemorySegmentsSysprop() {
try {
return Optional.ofNullable(System.getProperty(ENABLE_MEMORY_SEGMENTS_SYSPROP))
.map(Boolean::valueOf)
.orElse(Boolean.TRUE);
} catch (
@SuppressWarnings("unused")
SecurityException ignored) {
return true;
}
}
private static MMapIndexInputProvider lookupProvider() { private static MMapIndexInputProvider lookupProvider() {
if (checkMemorySegmentsSysprop() == false) {
return new MappedByteBufferIndexInputProvider();
}
final var lookup = MethodHandles.lookup(); final var lookup = MethodHandles.lookup();
final int runtimeVersion = Runtime.version().feature(); final int runtimeVersion = Runtime.version().feature();
if (runtimeVersion == 19) { if (runtimeVersion == 19) {