From 61f8990873644940fa57c14420e528073a21f0f0 Mon Sep 17 00:00:00 2001 From: Dave Marion Date: Wed, 3 Dec 2025 14:00:57 +0000 Subject: [PATCH 1/2] Make Mini Accumulo hardcoded JVM options mutable 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. --- .../MiniAccumuloClusterImpl.java | 8 ++-- .../MiniAccumuloConfigImpl.java | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+), 4 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 91d158ffb63..87cee997616 100644 --- a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java +++ b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java @@ -348,6 +348,7 @@ private ProcessInfo _exec(Class clazz, List extraJvmOpts, String... a String javaBin = javaHome + File.separator + "bin" + File.separator + "java"; var basicArgs = Stream.of(javaBin, "-Dproc=" + clazz.getSimpleName()); + var jvmOptions = config.getJvmOptions().stream(); var jvmArgs = extraJvmOpts.stream(); var propsArgs = config.getSystemProperties().entrySet().stream() .map(e -> String.format("-D%s=%s", e.getKey(), e.getValue())); @@ -356,14 +357,13 @@ private ProcessInfo _exec(Class clazz, List extraJvmOpts, String... a var hardcodedArgs = Stream.of( "-Dapple.awt.UIElement=true", "-Djava.net.preferIPv4Stack=true", - "-XX:+PerfDisableSharedMem", - "-XX:+AlwaysPreTouch", Main.class.getName(), clazz.getName()); // @formatter:on // concatenate all the args sources into a single list of args - var argList = Stream.of(basicArgs, jvmArgs, propsArgs, hardcodedArgs, Stream.of(args)) - .flatMap(Function.identity()).collect(toList()); + var argList = + Stream.of(basicArgs, jvmOptions, jvmArgs, propsArgs, hardcodedArgs, Stream.of(args)) + .flatMap(Function.identity()).collect(toList()); ProcessBuilder builder = new ProcessBuilder(argList); final String classpath = getClasspath(); 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 363fe204784..05e57eba2d0 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.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; @@ -87,6 +89,7 @@ public class MiniAccumuloConfigImpl { TabletServer.class, SCAN_SERVER, ScanServer.class, COMPACTOR, Compactor.class)); private boolean jdwpEnabled = false; private Map systemProperties = new HashMap<>(); + private Set jvmOptions = new HashSet<>(); private String instanceName = "miniInstance"; private String rootUserName = "root"; @@ -131,6 +134,9 @@ 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"); } /** @@ -681,6 +687,38 @@ public Map getSystemProperties() { 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 + * + * @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 getJvmOptions() { + return new HashSet<>(jvmOptions); + } + /** * Gets the classpath elements to use when spawning processes. * From 348d74760dc767f4e47e060e3ead7813bdfa7861 Mon Sep 17 00:00:00 2001 From: Dave Marion Date: Wed, 3 Dec 2025 20:22:16 +0000 Subject: [PATCH 2/2] Implemented PR suggestions --- .../MiniAccumuloClusterImpl.java | 17 +++++------------ .../miniclusterImpl/MiniAccumuloConfigImpl.java | 11 +++++++---- 2 files changed, 12 insertions(+), 16 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 87cee997616..36939b5ac71 100644 --- a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java +++ b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java @@ -348,22 +348,15 @@ private ProcessInfo _exec(Class clazz, List extraJvmOpts, String... a String javaBin = javaHome + File.separator + "bin" + File.separator + "java"; var basicArgs = Stream.of(javaBin, "-Dproc=" + clazz.getSimpleName()); - var jvmOptions = config.getJvmOptions().stream(); - 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", - 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, jvmOptions, jvmArgs, propsArgs, hardcodedArgs, Stream.of(args)) - .flatMap(Function.identity()).collect(toList()); + var argList = Stream.of(basicArgs, jvmOptions, systemProps, classArgs, Stream.of(args)) + .flatMap(Function.identity()).collect(toList()); ProcessBuilder builder = new ProcessBuilder(argList); final String classpath = getClasspath(); 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 05e57eba2d0..dbbbf5aecd5 100644 --- a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java +++ b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloConfigImpl.java @@ -88,8 +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 systemProperties = new HashMap<>(); - private Set jvmOptions = new HashSet<>(); + private final Map systemProperties = new HashMap<>(); + private final Set jvmOptions = new HashSet<>(); private String instanceName = "miniInstance"; private String rootUserName = "root"; @@ -137,6 +137,8 @@ public MiniAccumuloConfigImpl(File dir, String 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"); } /** @@ -675,7 +677,7 @@ public File getClientPropsFile() { * @since 1.6.0 */ public void setSystemProperties(Map systemProperties) { - this.systemProperties = new HashMap<>(systemProperties); + this.systemProperties.putAll(systemProperties); } /** @@ -699,7 +701,8 @@ public void addJvmOption(String option) { } /** - * Remove an option from the set of JVM options + * 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