Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inject jvm options #1089

Merged
merged 1 commit into from Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
}
}