Skip to content

Commit

Permalink
Add Priam.jvm.options.inject
Browse files Browse the repository at this point in the history
upsert uses commas as the delimiter between options which
doesn't work for a few C* options that use commas in the value.

Inject works by takign the string and adding it to the end of the jvm-server.options
file verbatim. While the comments in that file say it expects one option per line
there is nothign that actually enforces that rule. The line only needs to start with a '-'

Code that parses the options file:
JVM_OPTS_FILE=$CASSANDRA_CONF/jvm${jvmoptions_variant:--clients}.options
if [ $JAVA_VERSION -ge 11 ] ; then
    JVM_DEP_OPTS_FILE=$CASSANDRA_CONF/jvm11${jvmoptions_variant:--clients}.options
else
    JVM_DEP_OPTS_FILE=$CASSANDRA_CONF/jvm8${jvmoptions_variant:--clients}.options
fi

for opt in `grep "^-" $JVM_OPTS_FILE` `grep "^-" $JVM_DEP_OPTS_FILE`
do
  JVM_OPTS="$JVM_OPTS $opt"
done
  • Loading branch information
jrwest committed Apr 14, 2024
1 parent 0461cd9 commit e1017ea
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 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,10 @@ 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,16 +17,15 @@

package com.netflix.priam.tuner;

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

import com.netflix.priam.config.FakeConfiguration;
import com.netflix.priam.config.IConfiguration;
import com.netflix.priam.scheduler.UnsupportedTypeException;
import java.util.*;
import java.util.stream.Collectors;
import org.junit.Test;

import static org.junit.Assert.*;

/** Created by aagrawal on 8/29/17. */
public class JVMOptionTunerTest {
private IConfiguration config;
Expand Down Expand Up @@ -189,6 +188,40 @@ 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 +274,30 @@ 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 +324,10 @@ public String getHeapNewSize() {
public String getJVMUpsertSet() {
return configuredJVMUpsert;
}

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

0 comments on commit e1017ea

Please sign in to comment.