Skip to content

[6.8] Handle -1 gc_threshold settings explicitly (#54546) #54609

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

Merged
merged 1 commit into from
Apr 1, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ private static TimeValue getValidThreshold(Settings settings, String key, String

if (threshold == null) {
throw new IllegalArgumentException("missing gc_threshold for [" + getThresholdName(key, level) + "]");
} else if (threshold.nanos() < 0) {
final String settingValue = settings.get(level);
throw new IllegalArgumentException("invalid gc_threshold [" + getThresholdName(key, level) + "] value [" +
settingValue + "]: value cannot be negative");
}

return threshold;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void testDisabledSetting() throws InterruptedException {

public void testNegativeSetting() throws InterruptedException {
String collector = randomAlphaOfLength(5);
final String timeValue = "-" + randomTimeValue();
final String timeValue = "-" + randomTimeValue(2,1000); // -1 is handled separately
Settings settings = Settings.builder().put("monitor.jvm.gc.collector." + collector + ".warn", timeValue).build();
execute(settings, (command, interval, name) -> null, e -> {
assertThat(e, instanceOf(IllegalArgumentException.class));
Expand All @@ -71,6 +71,17 @@ public void testNegativeSetting() throws InterruptedException {
}, true, null);
}

public void testNegativeOneSetting() throws InterruptedException {
String collector = randomAlphaOfLength(5);
final String timeValue = "-1" + randomFrom("", "d", "h", "m", "s", "ms", "nanos");
Settings settings = Settings.builder().put("monitor.jvm.gc.collector." + collector + ".warn", timeValue).build();
execute(settings, (command, interval, name) -> null, e -> {
assertThat(e, instanceOf(IllegalArgumentException.class));
assertThat(e.getMessage(), equalTo("invalid gc_threshold [monitor.jvm.gc.collector." + collector + ".warn] " +
"value [" + timeValue + "]: value cannot be negative"));
}, true, null);
}

public void testMissingSetting() throws InterruptedException {
String collector = randomAlphaOfLength(5);
Set<AbstractMap.SimpleEntry<String, String>> entries = new HashSet<>();
Expand Down