diff --git a/distribution/proxy-native/Dockerfile b/distribution/proxy-native/Dockerfile index 4452ec0d486c4d..837601e1ad0f40 100644 --- a/distribution/proxy-native/Dockerfile +++ b/distribution/proxy-native/Dockerfile @@ -15,21 +15,17 @@ # limitations under the License. # -FROM busybox AS prepare - -RUN mkdir -p /conf/ - FROM oraclelinux:9-slim MAINTAINER ShardingSphere "dev@shardingsphere.apache.org" -ENV LOCAL_PATH /opt/shardingsphere-proxy-native - -bash <(curl -sL https://get.graalvm.org/jdk) -c espresso graalvm-ce-java17-22.3.1 +ARG APP_NAME -COPY --from=prepare /conf/ ${LOCAL_PATH}/conf +ENV LOCAL_PATH /opt/shardingsphere-proxy-native -ARG APP_NAME +RUN mkdir -p ${LOCAL_PATH}/conf && \ + microdnf install gzip -y && \ + bash <(curl -sL https://get.graalvm.org/jdk) -c espresso graalvm-ce-java17-22.3.1 ADD target/${APP_NAME} ${LOCAL_PATH}/ diff --git a/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.cn.md index 90005df99b5933..dfa6c440550b1f 100644 --- a/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.cn.md +++ b/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.cn.md @@ -112,7 +112,7 @@ services: ./apache-shardingsphere-proxy-native 3307 ./custom/conf ``` -4. 如果需要构建 Docker Image, 在添加后存在 SPI 实现的依赖或第三方依赖后, 在命令行执行如下命令。 +4. 如果需要构建 Docker Image, 在添加存在 SPI 实现的依赖或第三方依赖后, 在命令行执行如下命令。 ```shell ./mvnw -am -pl distribution/proxy-native -B -Pnative,docker.native -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat.skip=true clean package @@ -149,13 +149,13 @@ services: - 你可以使用 https://www.graalvm.org/22.3/tools/ 提供的一系列命令行工具或可视化工具观察 GraalVM Native Image 的内部行为,并根据其要求使用 VSCode 完成调试工作。 - 如果你正在使用 IntelliJ IDEA 并且希望调试生成的 GraalVM Native Image, - 你可以关注 https://blog.jetbrains.com/idea/2022/06/intellij-idea-2022-2-eap-5/#Experimental_GraalVM_Native_Debugger_for_Java - 及其后继。 + 如果你正在使用 IntelliJ IDEA 并且希望调试生成的 GraalVM Native + Image,你可以关注 https://blog.jetbrains.com/idea/2022/06/intellij-idea-2022-2-eap-5/#Experimental_GraalVM_Native_Debugger_for_Java + 及其后继。如果你使用的不是 Linux,则无法对 GraalVM Native Image 进行 + Debug,请关注尚未关闭的 https://github.com/oracle/graal/issues/5648 。 -- 对于使用 `ShardingSphere Agent` 等 APM Java Agent 的情形, - GraalVM 的 `native-image` 组件尚未完全支持在构建 Native Image 时使用 - javaagent,你需要关注尚未关闭的 https://github.com/oracle/graal/issues/1065。 +- 对于使用 `ShardingSphere Agent` 等 APM Java Agent 的情形, GraalVM 的 `native-image` 组件尚未完全支持在构建 Native + Image 时使用 javaagent,你需要关注尚未关闭的 https://github.com/oracle/graal/issues/1065。 - 以下部分采用 `Apache SkyWalking Java Agent` 作为示例,可用于跟踪 GraalVM 社区的对应 issue。 diff --git a/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.en.md b/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.en.md index 0f03b9d88342aa..8573d29722f13f 100644 --- a/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.en.md +++ b/docs/document/content/user-manual/shardingsphere-proxy/startup/graalvm-native-image.en.md @@ -123,8 +123,8 @@ services: ./apache-shardingsphere-proxy-native 3307 ./custom/conf ```` -4. If you need to build a Docker Image, after adding the dependencies of the SPI implementation or third-party - dependencies, execute the following commands on the command line. +4. If you need to build a Docker Image, execute the following command on the command line after adding dependencies that + exist for SPI implementation or third-party dependencies. ```shell ./mvnw -am -pl distribution/proxy-native -B -Pnative,docker.native -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotless.apply.skip=true -Drat .skip=true clean package @@ -164,10 +164,10 @@ services: - You can observe GraalVM Native Image using a series of command line tools or visualization tools available at https://www.graalvm.org/22.3/tools/, and use VSCode to debug it according to its requirements. - If you are using IntelliJ IDEA and want to debug the generated GraalVM Native Image, - You can + If you are using IntelliJ IDEA and want to debug the generated GraalVM Native Image, You can follow https://blog.jetbrains.com/idea/2022/06/intellij-idea-2022-2-eap-5/#Experimental_GraalVM_Native_Debugger_for_Java - and its successors. + and its successors. If you are not using Linux, you cannot debug GraalVM Native Image, please pay attention + to https://github.com/oracle/graal/issues/5648 which has not been closed yet. - In the case of using APM Java Agent such as `ShardingSphere Agent`, GraalVM's `native-image` component is not yet fully supported when building Native Images diff --git a/infra/util-groovy/pom.xml b/infra/util-groovy/pom.xml index 6ddcfb9df74ee9..69111485a93c62 100644 --- a/infra/util-groovy/pom.xml +++ b/infra/util-groovy/pom.xml @@ -32,9 +32,5 @@ org.apache.groovy groovy - - com.google.guava - guava - diff --git a/infra/util-groovy/src/main/java/org/apache/shardingsphere/infra/util/groovy/expr/HotspotInlineExpressionParser.java b/infra/util-groovy/src/main/java/org/apache/shardingsphere/infra/util/groovy/expr/HotspotInlineExpressionParser.java index caacaf5c6917e8..12dedfae2149fc 100644 --- a/infra/util-groovy/src/main/java/org/apache/shardingsphere/infra/util/groovy/expr/HotspotInlineExpressionParser.java +++ b/infra/util-groovy/src/main/java/org/apache/shardingsphere/infra/util/groovy/expr/HotspotInlineExpressionParser.java @@ -36,7 +36,7 @@ import java.util.stream.Collectors; /** - * Inline expression parser. + * Hotspot Inline expression parser. */ @RequiredArgsConstructor public final class HotspotInlineExpressionParser { diff --git a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/expr/EspressoInlineExpressionParser.java b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/expr/EspressoInlineExpressionParser.java index bd1114329698d7..35d6ff9344cc04 100644 --- a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/expr/EspressoInlineExpressionParser.java +++ b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/expr/EspressoInlineExpressionParser.java @@ -19,6 +19,7 @@ import groovy.lang.Closure; import org.graalvm.polyglot.Context; +import org.graalvm.polyglot.TypeLiteral; import org.graalvm.polyglot.Value; import java.net.URL; @@ -43,12 +44,12 @@ public class EspressoInlineExpressionParser { if (javaHome == null) { throw new RuntimeException("Failed to determine the system's environment variable GRAALVM_HOME or JAVA_HOME!"); } - System.setProperty("org.graalvm.home", javaHome); URL resource = Thread.currentThread().getContextClassLoader().getResource("espresso-need-libs"); assert null != resource; String dir = resource.getPath(); String javaClasspath = String.join(":", dir + "/groovy.jar", dir + "/guava.jar", dir + "/shardingsphere-infra-util.jar"); POLYGLOT = Context.newBuilder().allowAllAccess(true) + .option("java.Properties.org.graalvm.home", javaHome) .option("java.MultiThreaded", "true") .option("java.Classpath", javaClasspath) .build(); @@ -70,7 +71,7 @@ public static String handlePlaceHolder(final String inlineExpression) { return POLYGLOT.getBindings("java") .getMember("org.apache.shardingsphere.infra.util.expr.InlineExpressionParser") .invokeMember("handlePlaceHolder", inlineExpression) - .as(String.class); + .asString(); } /** @@ -78,10 +79,10 @@ public static String handlePlaceHolder(final String inlineExpression) { * * @return result list */ - @SuppressWarnings("unchecked") public List splitAndEvaluate() { - List splitAndEvaluate = espressoInlineExpressionParser.invokeMember("splitAndEvaluate").as(List.class); - // GraalVM Truffle Espresso CE 22.3.1 has a different behavior for generic List than Hotspot. + List splitAndEvaluate = espressoInlineExpressionParser.invokeMember("splitAndEvaluate").as(new TypeLiteral>() { + }); + // GraalVM Truffle Espresso 22.3.1 has a different behavior for generic List than Hotspot. return splitAndEvaluate.size() == 0 ? Collections.emptyList() : splitAndEvaluate; } @@ -91,6 +92,7 @@ public List splitAndEvaluate() { * @return closure */ public Closure evaluateClosure() { - return espressoInlineExpressionParser.invokeMember("evaluateClosure").as(Closure.class); + return espressoInlineExpressionParser.invokeMember("evaluateClosure").as(new TypeLiteral>() { + }); } }