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/04/26 23:50:41 UTC
[pulsar] branch branch-2.9 updated: [cherry-pick][pulsar-sql] Java version trim agent presto332 branch2.9 (#15326)
This is an automated email from the ASF dual-hosted git repository.
penghui pushed a commit to branch branch-2.9
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.9 by this push:
new 421e7c7ff36 [cherry-pick][pulsar-sql] Java version trim agent presto332 branch2.9 (#15326)
421e7c7ff36 is described below
commit 421e7c7ff36137eb9c7960ed56b83e1a7521a7a1
Author: ran <ga...@126.com>
AuthorDate: Wed Apr 27 07:50:28 2022 +0800
[cherry-pick][pulsar-sql] Java version trim agent presto332 branch2.9 (#15326)
Fix #14951
The presto 332 couldn't parse Java version like this `11.0.14.1`, so add a Java version trim agent to walk around the problem.
This is a temporary patch, after the presto upgrade to 332+, we could remove this.
Add a Java version trim agent to format the system property `java.version` for the Pulsar SQL plugin.
(cherry picked from commit a1aa18f1a856d074bb23d68f5c330d3558bdf6cb)
---
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 | 5 ++
.../latest-version-image/conf/presto/jvm.config | 1 +
.../presto/TestPrestoQueryTieredStorage.java | 1 -
.../integration/suites/PulsarSQLTestSuite.java | 1 +
11 files changed, 152 insertions(+), 1 deletion(-)
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..2f1171408b6
--- /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.9.2</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 31ec8436754..5aac5ffa456 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 0d9c145dff5..b0741725685 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 48376baa592..129f0854bc8 100644
--- a/pulsar-sql/presto-pulsar/pom.xml
+++ b/pulsar-sql/presto-pulsar/pom.xml
@@ -107,6 +107,11 @@
<version>${presto.version}</version>
</dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ </dependency>
+
<dependency>
<groupId>io.prestosql</groupId>
<artifactId>presto-main</artifactId>
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 4c129fadce0..7e4aae47bf0 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.
*/
diff --git a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/suites/PulsarSQLTestSuite.java b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/suites/PulsarSQLTestSuite.java
index 762fff751b0..902de4dd4ad 100644
--- a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/suites/PulsarSQLTestSuite.java
+++ b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/suites/PulsarSQLTestSuite.java
@@ -23,6 +23,7 @@ import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
+
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.PulsarClientException;