This is an automated email from the ASF dual-hosted git repository.

dlmarion pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/2.1 by this push:
     new 4d016baa4f Make Mini Accumulo hardcoded JVM options mutable (#5999)
4d016baa4f is described below

commit 4d016baa4fdb7526d106005d8d48602b01f7008e
Author: Dave Marion <[email protected]>
AuthorDate: Wed Dec 3 15:39:21 2025 -0500

    Make Mini Accumulo hardcoded JVM options mutable (#5999)
    
    Processes spawned by MiniAccumuloCluster have a pre-configured,
    but not mutable, set of JVM options. Specifically they are
    '-XX:+PerfDisableSharedMem' and '-XX:+AlwaysPreTouch'. This
    change makes the set of JVM options configurable.
    
    This change also refactors some internal code for default
    system properties (-Dapple.awt.UIElement=true and
    -Djava.net.preferIPv4Stack=true), but these changes
    do not make it so that a user can remove them.
---
 .../miniclusterImpl/MiniAccumuloClusterImpl.java   | 15 ++------
 .../miniclusterImpl/MiniAccumuloConfigImpl.java    | 45 +++++++++++++++++++++-
 2 files changed, 47 insertions(+), 13 deletions(-)

diff --git 
a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java
 
b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java
index 91d158ffb6..36939b5ac7 100644
--- 
a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java
+++ 
b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java
@@ -348,21 +348,14 @@ public class MiniAccumuloClusterImpl implements 
AccumuloCluster {
     String javaBin = javaHome + File.separator + "bin" + File.separator + 
"java";
 
     var basicArgs = Stream.of(javaBin, "-Dproc=" + clazz.getSimpleName());
-    var jvmArgs = extraJvmOpts.stream();
-    var propsArgs = config.getSystemProperties().entrySet().stream()
+    var jvmOptions = Stream.concat(config.getJvmOptions().stream(), 
extraJvmOpts.stream());
+    var systemProps = config.getSystemProperties().entrySet().stream()
         .map(e -> String.format("-D%s=%s", e.getKey(), e.getValue()));
 
-    // @formatter:off
-    var hardcodedArgs = Stream.of(
-        "-Dapple.awt.UIElement=true",
-        "-Djava.net.preferIPv4Stack=true",
-        "-XX:+PerfDisableSharedMem",
-        "-XX:+AlwaysPreTouch",
-        Main.class.getName(), clazz.getName());
-    // @formatter:on
+    var classArgs = Stream.of(Main.class.getName(), clazz.getName());
 
     // concatenate all the args sources into a single list of args
-    var argList = Stream.of(basicArgs, jvmArgs, propsArgs, hardcodedArgs, 
Stream.of(args))
+    var argList = Stream.of(basicArgs, jvmOptions, systemProps, classArgs, 
Stream.of(args))
         .flatMap(Function.identity()).collect(toList());
     ProcessBuilder builder = new ProcessBuilder(argList);
 
diff --git 
a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java
 
b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java
index 363fe20478..dbbbf5aecd 100644
--- 
a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java
+++ 
b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java
@@ -30,10 +30,12 @@ import java.io.File;
 import java.io.IOException;
 import java.util.EnumMap;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Objects;
+import java.util.Set;
 import java.util.function.Consumer;
 
 import org.apache.accumulo.compactor.Compactor;
@@ -86,7 +88,8 @@ public class MiniAccumuloConfigImpl {
           MONITOR, Monitor.class, ZOOKEEPER, ZooKeeperServerMain.class, 
TABLET_SERVER,
           TabletServer.class, SCAN_SERVER, ScanServer.class, COMPACTOR, 
Compactor.class));
   private boolean jdwpEnabled = false;
-  private Map<String,String> systemProperties = new HashMap<>();
+  private final Map<String,String> systemProperties = new HashMap<>();
+  private final Set<String> jvmOptions = new HashSet<>();
 
   private String instanceName = "miniInstance";
   private String rootUserName = "root";
@@ -131,6 +134,11 @@ public class MiniAccumuloConfigImpl {
   public MiniAccumuloConfigImpl(File dir, String rootPassword) {
     this.dir = dir;
     this.rootPassword = rootPassword;
+    // Set default options
+    this.jvmOptions.add("-XX:+PerfDisableSharedMem");
+    this.jvmOptions.add("-XX:+AlwaysPreTouch");
+    this.systemProperties.put("-Dapple.awt.UIElement", "true");
+    this.systemProperties.put("-Djava.net.preferIPv4Stack", "true");
   }
 
   /**
@@ -669,7 +677,7 @@ public class MiniAccumuloConfigImpl {
    * @since 1.6.0
    */
   public void setSystemProperties(Map<String,String> systemProperties) {
-    this.systemProperties = new HashMap<>(systemProperties);
+    this.systemProperties.putAll(systemProperties);
   }
 
   /**
@@ -681,6 +689,39 @@ public class MiniAccumuloConfigImpl {
     return new HashMap<>(systemProperties);
   }
 
+  /**
+   * Add a JVM option to the spawned JVM processes. The default set of JVM 
options contains
+   * '-XX:+PerfDisableSharedMem' and '-XX:+AlwaysPreTouch'
+   *
+   * @param option JVM option
+   * @since 2.1.5
+   */
+  public void addJvmOption(String option) {
+    this.jvmOptions.add(option);
+  }
+
+  /**
+   * Remove an option from the set of JVM options. Only options that match the 
{@code option}
+   * exactly will be removed.
+   *
+   * @param option JVM option
+   * @return true if removed, false if not removed
+   * @since 2.1.5
+   */
+  public boolean removeJvmOption(String option) {
+    return this.jvmOptions.remove(option);
+  }
+
+  /**
+   * Get the set of JVM options
+   *
+   * @return set of options
+   * @since 2.1.5
+   */
+  public Set<String> getJvmOptions() {
+    return new HashSet<>(jvmOptions);
+  }
+
   /**
    * Gets the classpath elements to use when spawning processes.
    *

Reply via email to