Skip to content

Commit

Permalink
[Bug]: gradle check failing with java heap OutOfMemoryError (#4328) (#…
Browse files Browse the repository at this point in the history
…4445)

* [Bug]: gradle check failing with java heap OutOfMemoryError

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

* Fork JavaCompile task

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
(cherry picked from commit ccf575a)
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
reta authored Sep 7, 2022
1 parent 2a46993 commit 652c9ec
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ tasks.register("branchConsistency") {
allprojects {
// configure compiler options
tasks.withType(JavaCompile).configureEach { JavaCompile compile ->
options.fork = true

configure(options.forkOptions) {
memoryMaximumSize = project.property('options.forkOptions.memoryMaximumSize')
}

// See please https://bugs.openjdk.java.net/browse/JDK-8209058
if (BuildParams.runtimeJavaVersion > JavaVersion.VERSION_11) {
compile.options.compilerArgs << '-Werror'
Expand Down Expand Up @@ -353,6 +359,10 @@ allprojects {
// the dependency is added.
gradle.projectsEvaluated {
allprojects {
project.tasks.withType(JavaForkOptions) {
maxHeapSize project.property('options.forkOptions.memoryMaximumSize')
}

if (project.path == ':test:framework') {
// :test:framework:test cannot run before and after :server:test
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,19 @@ static long fallbackRegionSize(JvmInfo jvmInfo) {
// https://hg.openjdk.java.net/jdk/jdk/file/e7d0ec2d06e8/src/hotspot/share/gc/g1/heapRegion.cpp#l67
// based on this JDK "bug":
// https://bugs.openjdk.java.net/browse/JDK-8241670
long averageHeapSize = (jvmInfo.getMem().getHeapMax().getBytes() + JvmInfo.jvmInfo().getMem().getHeapMax().getBytes()) / 2;
long regionSize = Long.highestOneBit(averageHeapSize / 2048);
// JDK-17 updates:
// https://github.com/openjdk/jdk17u/blob/master/src/hotspot/share/gc/g1/heapRegionBounds.hpp
// https://github.com/openjdk/jdk17u/blob/master/src/hotspot/share/gc/g1/heapRegion.cpp#L67
long regionSizeUnrounded = Math.min(
Math.max(JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() / 2048, ByteSizeUnit.MB.toBytes(1)),
ByteSizeUnit.MB.toBytes(32)
);

long regionSize = Long.highestOneBit(regionSizeUnrounded);
if (regionSize != regionSizeUnrounded) {
regionSize <<= 1; /* next power of 2 */
}

if (regionSize < ByteSizeUnit.MB.toBytes(1)) {
regionSize = ByteSizeUnit.MB.toBytes(1);
} else if (regionSize > ByteSizeUnit.MB.toBytes(32)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
package org.opensearch.common.settings;

import org.opensearch.common.settings.Setting.Property;
import org.opensearch.common.unit.ByteSizeUnit;
import org.opensearch.common.unit.ByteSizeValue;
import org.opensearch.common.util.PageCacheRecycler;
import org.opensearch.indices.IndexingMemoryController;
Expand Down Expand Up @@ -83,32 +82,40 @@ public void testIndicesRequestCacheSetting() {
}

public void testCircuitBreakerSettings() {
// default is chosen based on actual heap size
final Settings settings = Settings.builder()
.put(HierarchyCircuitBreakerService.USE_REAL_MEMORY_USAGE_SETTING.getKey(), randomBoolean())
.build();

// default is chosen based on USE_REAL_MEMORY_USAGE_SETTING setting
double defaultTotalPercentage;
if (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() < new ByteSizeValue(1, ByteSizeUnit.GB).getBytes()) {
if (HierarchyCircuitBreakerService.USE_REAL_MEMORY_USAGE_SETTING.get(settings)) {
defaultTotalPercentage = 0.95d;
} else {
defaultTotalPercentage = 0.7d;
}
assertMemorySizeSetting(
HierarchyCircuitBreakerService.TOTAL_CIRCUIT_BREAKER_LIMIT_SETTING,
"indices.breaker.total.limit",
new ByteSizeValue((long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * defaultTotalPercentage))
new ByteSizeValue((long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * defaultTotalPercentage)),
settings
);
assertMemorySizeSetting(
HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_LIMIT_SETTING,
"indices.breaker.fielddata.limit",
new ByteSizeValue((long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.4))
new ByteSizeValue((long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.4)),
settings
);
assertMemorySizeSetting(
HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING,
"indices.breaker.request.limit",
new ByteSizeValue((long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.6))
new ByteSizeValue((long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.6)),
settings
);
assertMemorySizeSetting(
HierarchyCircuitBreakerService.IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_LIMIT_SETTING,
"network.breaker.inflight_requests.limit",
new ByteSizeValue((JvmInfo.jvmInfo().getMem().getHeapMax().getBytes()))
new ByteSizeValue((JvmInfo.jvmInfo().getMem().getHeapMax().getBytes())),
settings
);
}

Expand All @@ -121,10 +128,14 @@ public void testIndicesFieldDataCacheSetting() {
}

private void assertMemorySizeSetting(Setting<ByteSizeValue> setting, String settingKey, ByteSizeValue defaultValue) {
assertMemorySizeSetting(setting, settingKey, defaultValue, Settings.EMPTY);
}

private void assertMemorySizeSetting(Setting<ByteSizeValue> setting, String settingKey, ByteSizeValue defaultValue, Settings settings) {
assertThat(setting, notNullValue());
assertThat(setting.getKey(), equalTo(settingKey));
assertThat(setting.getProperties(), hasItem(Property.NodeScope));
assertThat(setting.getDefault(Settings.EMPTY), equalTo(defaultValue));
assertThat(setting.getDefault(settings), equalTo(defaultValue));
Settings settingWithPercentage = Settings.builder().put(settingKey, "25%").build();
assertThat(
setting.get(settingWithPercentage),
Expand Down

0 comments on commit 652c9ec

Please sign in to comment.