Skip to content

Commit

Permalink
Merge pull request #1089 from Netflix/jwest/inject-jvm-options
Browse files Browse the repository at this point in the history
inject jvm options
  • Loading branch information
jrwest committed Apr 22, 2024
2 parents 0461cd9 + eed6f3e commit 5ce3496
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
Expand Up @@ -74,6 +74,10 @@ default String getJVMUpsertSet() {
return StringUtils.EMPTY;
}

default String getJVMInjectSet() {
return StringUtils.EMPTY;
}

/** @return Path to Cassandra startup script */
default String getCassStartupScript() {
return "/etc/init.d/cassandra start";
Expand Down
Expand Up @@ -223,6 +223,11 @@ public String getJVMUpsertSet() {
return config.get(PRIAM_PRE + ".jvm.options.upsert");
}

@Override
public String getJVMInjectSet() {
return config.get(PRIAM_PRE + ".jvm.options.inject");
}

@Override
public String getFlushCronExpression() {
return config.get(PRIAM_PRE + ".flush.cron", "-1");
Expand Down
Expand Up @@ -153,6 +153,9 @@ protected Map<String, List<String>> updateJVMOptions() throws Exception {
.collect(Collectors.toList()));
}

final String injectSet = config.getJVMInjectSet();
if (injectSet != null && !injectSet.trim().isEmpty()) configuredOptions.add(injectSet);

HashMap<String, List<String>> options = new HashMap<String, List<String>>() {};
options.put("configuredJVMOptions", configuredOptions);
options.put("configuredJVMVersionOptions", configuredVersionOptions);
Expand Down
Expand Up @@ -17,8 +17,7 @@

package com.netflix.priam.tuner;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

import com.netflix.priam.config.FakeConfiguration;
import com.netflix.priam.config.IConfiguration;
Expand Down Expand Up @@ -189,6 +188,39 @@ public void testG1GCUpsertExclude() throws Exception {
assertTrue(allJVMOptions.contains(youngHeap));
}

@Test
public void testInject() throws Exception {
JVMOption youngHeap = new JVMOption("-Xmn", "3G", true, true);
JVMOption maxHeap = new JVMOption("-Xmx", "12G", false, true);

JVMOption option1 = new JVMOption("-Dsample");
JVMOption option2 = new JVMOption("-Dsample2", "10", false, false);
StringBuffer upsert =
new StringBuffer(option1.toJVMOptionString() + "," + option2.toJVMOptionString());

String upsertString =
"-Dcassandra.schema_delay_ms=60000 -Dcassandra.skip_schema_check_for_versions=ver1,ver2";
config = new GCConfiguration(GCType.G1GC, "", upsert.toString(), "3G", "12G", upsertString);

JVMOptionsTuner tuner = new JVMOptionsTuner(config);
List<String> configuredJVMOptions = tuner.updateJVMOptions().get("configuredJVMOptions");

for (String s :
new String[] {
option1.toJVMOptionString(), option2.toJVMOptionString(), upsertString
}) {
boolean found = false;
for (String f : configuredJVMOptions) {
if (f.equalsIgnoreCase(s)) {
found = true;
break;
}
}

assertTrue("could not find " + s + " in jvm options", found);
}
}

private List<JVMOption> getConfiguredJVMOptions(IConfiguration config) throws Exception {
return getConfiguredJVMOptions(config, true);
}
Expand Down Expand Up @@ -241,17 +273,36 @@ private class GCConfiguration extends FakeConfiguration {
private String configuredHeapNewSize;
private String configuredHeapSize;

private String configuredJVMInject;

GCConfiguration(
GCType gcType,
String configuredJVMExclude,
String configuredJVMUpsert,
String configuredHeapNewSize,
String configuredHeapSize) {
this(
gcType,
configuredJVMExclude,
configuredJVMUpsert,
configuredHeapNewSize,
configuredHeapSize,
"");
}

GCConfiguration(
GCType gcType,
String configuredJVMExclude,
String configuredJVMUpsert,
String configuredHeapNewSize,
String configuredHeapSize,
String configuredJVMInject) {
this.gcType = gcType;
this.configuredJVMExclude = configuredJVMExclude;
this.configuredJVMUpsert = configuredJVMUpsert;
this.configuredHeapNewSize = configuredHeapNewSize;
this.configuredHeapSize = configuredHeapSize;
this.configuredJVMInject = configuredJVMInject;
}

@Override
Expand All @@ -278,5 +329,10 @@ public String getHeapNewSize() {
public String getJVMUpsertSet() {
return configuredJVMUpsert;
}

@Override
public String getJVMInjectSet() {
return configuredJVMInject;
}
}
}

0 comments on commit 5ce3496

Please sign in to comment.