You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by pe...@apache.org on 2022/05/12 02:27:54 UTC
[pulsar] branch branch-2.10 updated: [cherry-pick][pulsar-sql] Java version trim agent presto332 branch2.10 (#15371)
This is an automated email from the ASF dual-hosted git repository.
penghui pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.10 by this push:
new e6ae5ece482 [cherry-pick][pulsar-sql] Java version trim agent presto332 branch2.10 (#15371)
e6ae5ece482 is described below
commit e6ae5ece482d165c71a7a96825f68a89ab7e62b3
Author: ran <ga...@126.com>
AuthorDate: Thu May 12 10:27:47 2022 +0800
[cherry-pick][pulsar-sql] Java version trim agent presto332 branch2.10 (#15371)
---
conf/presto/jvm.config | 1 +
pulsar-sql/java-version-trim-agent/pom.xml | 58 ++++++++++++++++++++++
.../pulsar/sql/agent/TrimJavaVersionAgent.java | 51 +++++++++++++++++++
.../org/apache/pulsar/sql/agent/package-info.java | 22 ++++++++
pulsar-sql/pom.xml | 1 +
pulsar-sql/presto-distribution/pom.xml | 7 +++
.../presto-distribution/src/assembly/assembly.xml | 5 ++
pulsar-sql/presto-pulsar/pom.xml | 6 +++
src/check-binary-license.sh | 2 +-
.../latest-version-image/conf/presto/jvm.config | 1 +
.../presto/TestPrestoQueryTieredStorage.java | 1 -
11 files changed, 153 insertions(+), 2 deletions(-)
diff --git a/conf/presto/jvm.config b/conf/presto/jvm.config
index 4a431b63367..3e1cdd6a24b 100644
--- a/conf/presto/jvm.config
+++ b/conf/presto/jvm.config
@@ -27,3 +27,4 @@
-XX:+ExitOnOutOfMemoryError
-Dpresto-temporarily-allow-java8=true
-Djdk.attach.allowAttachSelf=true
+-javaagent:java-version-trim-agent.jar
\ No newline at end of file
diff --git a/pulsar-sql/java-version-trim-agent/pom.xml b/pulsar-sql/java-version-trim-agent/pom.xml
new file mode 100644
index 00000000000..b4ee1158573
--- /dev/null
+++ b/pulsar-sql/java-version-trim-agent/pom.xml
@@ -0,0 +1,58 @@
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>pulsar-sql</artifactId>
+ <groupId>org.apache.pulsar</groupId>
+ <version>2.10.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>java-version-trim-agent</artifactId>
+ <name>Pulsar SQL :: Java Version Trim Agent</name>
+
+ <build>
+ <finalName>java-version-trim-agent</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.1.0</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ </manifest>
+ <manifestEntries>
+ <Premain-Class>org.apache.pulsar.sql.agent.TrimJavaVersionAgent</Premain-Class>
+ <Agent-Class>org.apache.pulsar.sql.agent.TrimJavaVersionAgent</Agent-Class>
+ <Can-Redefine-Classes>true</Can-Redefine-Classes>
+ <Can-Retransform-Classes>true</Can-Retransform-Classes>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git a/pulsar-sql/java-version-trim-agent/src/main/java/org/apache/pulsar/sql/agent/TrimJavaVersionAgent.java b/pulsar-sql/java-version-trim-agent/src/main/java/org/apache/pulsar/sql/agent/TrimJavaVersionAgent.java
new file mode 100644
index 00000000000..7cb422bd27a
--- /dev/null
+++ b/pulsar-sql/java-version-trim-agent/src/main/java/org/apache/pulsar/sql/agent/TrimJavaVersionAgent.java
@@ -0,0 +1,51 @@
+/**
+ * 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.pulsar.sql.agent;
+
+import java.lang.instrument.Instrumentation;
+import java.util.logging.Logger;
+
+/**
+ * The presto 332 couldn't parse Java version like this `11.0.14.1`,
+ * so add java version trim agent to walk around the problem.
+ *
+ * After the presto upgrade to 332+, we could remove this.
+ */
+public class TrimJavaVersionAgent {
+
+ private static final Logger logger = Logger.getLogger(TrimJavaVersionAgent.class.getName());
+
+ private static final String JAVA_VERSION = "java.version";
+
+ public static String trimJavaVersion(String javaVersion) {
+ String[] arr = javaVersion.split("\\.");
+ if (arr.length <= 3) {
+ return javaVersion;
+ }
+ return arr[0] + "." + arr[1] + "." + arr[2];
+ }
+
+ public static void premain(String agentArgs, Instrumentation inst) {
+ String javaVersion = System.getProperty(JAVA_VERSION);
+ String trimVersion = trimJavaVersion(javaVersion);
+ logger.info("original java version " + javaVersion + " => trim java version " + trimVersion);
+ System.setProperty(JAVA_VERSION, trimVersion);
+ }
+
+}
diff --git a/pulsar-sql/java-version-trim-agent/src/main/java/org/apache/pulsar/sql/agent/package-info.java b/pulsar-sql/java-version-trim-agent/src/main/java/org/apache/pulsar/sql/agent/package-info.java
new file mode 100644
index 00000000000..7d60a6fc6fb
--- /dev/null
+++ b/pulsar-sql/java-version-trim-agent/src/main/java/org/apache/pulsar/sql/agent/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Implementation of the connector to the Presto engine.
+ */
+package org.apache.pulsar.sql.agent;
diff --git a/pulsar-sql/pom.xml b/pulsar-sql/pom.xml
index 0ab3a1369cb..9e8f9b3f295 100644
--- a/pulsar-sql/pom.xml
+++ b/pulsar-sql/pom.xml
@@ -34,6 +34,7 @@
<modules>
<module>presto-pulsar</module>
<module>presto-pulsar-plugin</module>
+ <module>java-version-trim-agent</module>
<module>presto-distribution</module>
</modules>
diff --git a/pulsar-sql/presto-distribution/pom.xml b/pulsar-sql/presto-distribution/pom.xml
index b2755e4aa67..23ce147b4db 100644
--- a/pulsar-sql/presto-distribution/pom.xml
+++ b/pulsar-sql/presto-distribution/pom.xml
@@ -200,6 +200,13 @@
<version>${jackson.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>java-version-trim-agent</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
<dependencyManagement>
diff --git a/pulsar-sql/presto-distribution/src/assembly/assembly.xml b/pulsar-sql/presto-distribution/src/assembly/assembly.xml
index 4f1bac20dce..bc1fe5ed460 100644
--- a/pulsar-sql/presto-distribution/src/assembly/assembly.xml
+++ b/pulsar-sql/presto-distribution/src/assembly/assembly.xml
@@ -40,6 +40,11 @@
<outputDirectory>bin/</outputDirectory>
<fileMode>644</fileMode>
</file>
+ <file>
+ <source>${basedir}/../java-version-trim-agent/target/java-version-trim-agent.jar</source>
+ <destName>java-version-trim-agent.jar</destName>
+ <outputDirectory>/</outputDirectory>
+ </file>
</files>
<fileSets>
<fileSet>
diff --git a/pulsar-sql/presto-pulsar/pom.xml b/pulsar-sql/presto-pulsar/pom.xml
index 32aae203cfb..43b395d24dc 100644
--- a/pulsar-sql/presto-pulsar/pom.xml
+++ b/pulsar-sql/presto-pulsar/pom.xml
@@ -107,6 +107,12 @@
<version>${presto.version}</version>
</dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <version>${javax.annotation-api.version}</version>
+ </dependency>
+
<dependency>
<groupId>io.prestosql</groupId>
<artifactId>presto-main</artifactId>
diff --git a/src/check-binary-license.sh b/src/check-binary-license.sh
index 5e8f365178a..afe380d5c8f 100755
--- a/src/check-binary-license.sh
+++ b/src/check-binary-license.sh
@@ -96,7 +96,7 @@ done
if [ "$NO_PRESTO" -ne 1 ]; then
# check pulsar sql jars
- JARS=$(tar -tf $TARBALL | grep '\.jar' | grep 'lib/presto/' | grep -v pulsar-client | grep -v bouncy-castle-bc | grep -v pulsar-metadata | grep -v 'managed-ledger' | grep -v 'pulsar-client-admin' | grep -v 'pulsar-client-api' | grep -v 'pulsar-functions-api' | grep -v 'pulsar-presto-connector-original' | grep -v 'pulsar-presto-distribution' | grep -v 'pulsar-common' | grep -v 'pulsar-functions-proto' | grep -v 'pulsar-functions-utils' | grep -v 'pulsar-io-core' | grep -v 'pulsar-tran [...]
+ JARS=$(tar -tf $TARBALL | grep '\.jar' | grep 'lib/presto/' | grep -v pulsar-client | grep -v bouncy-castle-bc | grep -v pulsar-metadata | grep -v 'managed-ledger' | grep -v 'pulsar-client-admin' | grep -v 'pulsar-client-api' | grep -v 'pulsar-functions-api' | grep -v 'pulsar-presto-connector-original' | grep -v 'pulsar-presto-distribution' | grep -v 'pulsar-common' | grep -v 'pulsar-functions-proto' | grep -v 'pulsar-functions-utils' | grep -v 'pulsar-io-core' | grep -v 'pulsar-tran [...]
LICENSEPATH=$(tar -tf $TARBALL | awk '/^[^\/]*\/lib\/presto\/LICENSE/')
LICENSE=$(tar -O -xf $TARBALL "$LICENSEPATH")
LICENSEJARS=$(echo "$LICENSE" | sed -nE 's!.* (.*\.jar).*!\1!gp')
diff --git a/tests/docker-images/latest-version-image/conf/presto/jvm.config b/tests/docker-images/latest-version-image/conf/presto/jvm.config
index 28db36a3937..e8a0cec43ba 100644
--- a/tests/docker-images/latest-version-image/conf/presto/jvm.config
+++ b/tests/docker-images/latest-version-image/conf/presto/jvm.config
@@ -28,3 +28,4 @@
-XX:+ExitOnOutOfMemoryError
-Dpresto-temporarily-allow-java8=true
-Djdk.attach.allowAttachSelf=true
+-javaagent:java-version-trim-agent.jar
\ No newline at end of file
diff --git a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/presto/TestPrestoQueryTieredStorage.java b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/presto/TestPrestoQueryTieredStorage.java
index 2d3e96a8c3e..5ca4ae41c57 100644
--- a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/presto/TestPrestoQueryTieredStorage.java
+++ b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/presto/TestPrestoQueryTieredStorage.java
@@ -41,7 +41,6 @@ import org.testcontainers.shaded.org.apache.commons.lang.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
-
/**
* Test presto query from tiered storage, the Pulsar SQL is cluster mode.
*/