You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2023/01/03 18:11:59 UTC
[lucene] branch branch_9x updated: Add a sysprop "org.apache.lucene.store.MMapDirectory.enableMemorySegments" (#12062)
This is an automated email from the ASF dual-hosted git repository.
uschindler pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new cc85ca5d5b7 Add a sysprop "org.apache.lucene.store.MMapDirectory.enableMemorySegments" (#12062)
cc85ca5d5b7 is described below
commit cc85ca5d5b7760c967ff11f15675962bdfcd1911
Author: Uwe Schindler <us...@apache.org>
AuthorDate: Tue Jan 3 19:10:28 2023 +0100
Add a sysprop "org.apache.lucene.store.MMapDirectory.enableMemorySegments" (#12062)
---
lucene/CHANGES.txt | 4 +++-
.../org/apache/lucene/store/MMapDirectory.java | 27 ++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 85273fdfe70..17f64af4290 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -71,7 +71,9 @@ New Features
* 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,
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
ranges. (Marc D'Mello)
diff --git a/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java b/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java
index c50a6dd1a46..f251e536b72 100644
--- a/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java
@@ -22,6 +22,7 @@ import java.lang.invoke.MethodType;
import java.nio.channels.ClosedChannelException; // javadoc @link
import java.nio.file.Path;
import java.util.Locale;
+import java.util.Optional;
import java.util.concurrent.Future;
import java.util.function.BiPredicate;
import java.util.logging.Logger;
@@ -113,6 +114,17 @@ public class MMapDirectory extends FSDirectory {
*/
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;
/**
@@ -369,7 +381,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() {
+ if (checkMemorySegmentsSysprop() == false) {
+ return new MappedByteBufferIndexInputProvider();
+ }
final var lookup = MethodHandles.lookup();
final int runtimeVersion = Runtime.version().feature();
if (runtimeVersion == 19) {