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

[Fix][Zeta] Set AsyncLogger.ThreadNameStrategy=UNCACHED to avoid thread name cache #8215

Merged
merged 7 commits into from
Dec 6, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<elasticsearch6.client.version>6.3.1</elasticsearch6.client.version>
<elasticsearch7.client.version>7.5.1</elasticsearch7.client.version>
<flink-shaded-hadoop-2.version>2.7.5-7.0</flink-shaded-hadoop-2.version>
<commons-lang3.version>3.5</commons-lang3.version>
<commons-lang3.version>3.8</commons-lang3.version>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<commons-io.version>2.11.0</commons-io.version>
<commons-collections4.version>4.4</commons-collections4.version>
<commons-csv.version>1.10.0</commons-csv.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ set "JAVA_OPTS=%JvmOption%"
set "SEATUNNEL_CONFIG=%CONF_DIR%\seatunnel.yaml"

set "JAVA_OPTS=%JAVA_OPTS% -Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector"
set "JAVA_OPTS=%JAVA_OPTS% -Dlog4j2.isThreadContextMapInheritable=true"
set "JAVA_OPTS=%JAVA_OPTS% -Dlog4j2.isThreadContextMapInheritable=true -DAsyncLogger.ThreadNameStrategy=UNCACHED"

REM Server Debug Config
REM Usage instructions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ done

# Log4j2 Config
JAVA_OPTS="${JAVA_OPTS} -Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector"
JAVA_OPTS="${JAVA_OPTS} -Dlog4j2.isThreadContextMapInheritable=true"
JAVA_OPTS="${JAVA_OPTS} -Dlog4j2.isThreadContextMapInheritable=true -DAsyncLogger.ThreadNameStrategy=UNCACHED"
if [ -e "${CONF_DIR}/log4j2.properties" ]; then
JAVA_OPTS="${JAVA_OPTS} -Dhazelcast.logging.type=log4j2 -Dlog4j2.configurationFile=${CONF_DIR}/log4j2.properties"
JAVA_OPTS="${JAVA_OPTS} -Dseatunnel.logs.path=${APP_DIR}/logs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@
import org.apache.seatunnel.engine.common.exception.SeaTunnelEngineException;
import org.apache.seatunnel.engine.server.SeaTunnelServerStarter;

import org.apache.commons.lang3.JavaVersion;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;

import lombok.extern.slf4j.Slf4j;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/** This command is used to execute the SeaTunnel engine job by SeaTunnel API. */
@Slf4j
public class ServerExecuteCommand implements Command<ServerCommandArgs> {

private final ServerCommandArgs serverCommandArgs;
Expand All @@ -38,6 +46,7 @@ public ServerExecuteCommand(ServerCommandArgs serverCommandArgs) {

@Override
public void execute() {
checkEnvironment();
SeaTunnelConfig seaTunnelConfig = ConfigProvider.locateAndGetSeaTunnelConfig();
String clusterRole = this.serverCommandArgs.getClusterRole();
if (StringUtils.isNotBlank(clusterRole)) {
Expand All @@ -60,4 +69,32 @@ public void execute() {
SeaTunnelServerStarter.createHazelcastInstance(
seaTunnelConfig, Thread.currentThread().getName());
}

private void checkEnvironment() {
if (isAllocatingThreadGetName()) {
log.warn(
"The current JDK version is not recommended. Please upgrade to JDK 1.8.0_102 or higher. "
+ "The current version will affect the performance of log printing. "
+ "For details, please refer to https://issues.apache.org/jira/browse/LOG4J2-2052");
}
}

static boolean isAllocatingThreadGetName() {
// LOG4J2-2052, LOG4J2-2635 JDK 8u102 ("1.8.0_102") removed the String allocation in
// Thread.getName()
if (SystemUtils.IS_JAVA_1_8) {
try {
Pattern javaVersionPattern = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)_(\\d+)");
Matcher m = javaVersionPattern.matcher(System.getProperty("java.version"));
if (m.matches()) {
return Integer.parseInt(m.group(3)) == 0 && Integer.parseInt(m.group(4)) < 102;
}
return true;
} catch (Exception e) {
return true;
}
} else {
return !SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_8);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.seatunnel.core.starter.seatunnel.command;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.JRE;

public class ServerExecuteCommandTest {

@Test
@DisabledOnJre(value = JRE.JAVA_11, disabledReason = "the test case only works on Java 8")
public void testJavaVersionCheck() {
String realVersion = System.getProperty("java.version");
System.setProperty("java.version", "1.8.0_191");
Assertions.assertFalse(ServerExecuteCommand.isAllocatingThreadGetName());
System.setProperty("java.version", "1.8.0_60");
Assertions.assertTrue(ServerExecuteCommand.isAllocatingThreadGetName());
System.setProperty("java.version", realVersion);
}
}
2 changes: 1 addition & 1 deletion tools/dependencies/known-dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commons-codec-1.13.jar
commons-collections4-4.4.jar
commons-compress-1.20.jar
commons-io-2.11.0.jar
commons-lang3-3.5.jar
commons-lang3-3.8.jar
commons-csv-1.10.0.jar
config-1.3.3.jar
disruptor-3.4.4.jar
Expand Down
Loading