diff --git a/.github/workflows/nightly-build-artifact.yml b/.github/workflows/nightly-build-artifact.yml
index d09166afca5f2f..0b9a23d5ae8f4a 100644
--- a/.github/workflows/nightly-build-artifact.yml
+++ b/.github/workflows/nightly-build-artifact.yml
@@ -116,7 +116,7 @@ jobs:
with:
version: '22.3.1'
java-version: '17'
- components: 'native-image'
+ components: 'espresso,native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
cache: 'maven'
- uses: docker/login-action@v2
diff --git a/distribution/proxy-native/Dockerfile b/distribution/proxy-native/Dockerfile
index 4d10a573be0f55..4452ec0d486c4d 100644
--- a/distribution/proxy-native/Dockerfile
+++ b/distribution/proxy-native/Dockerfile
@@ -23,10 +23,14 @@ FROM oraclelinux:9-slim
MAINTAINER ShardingSphere "dev@shardingsphere.apache.org"
-COPY --from=prepare /conf/ /conf
+ENV LOCAL_PATH /opt/shardingsphere-proxy-native
+
+bash <(curl -sL https://get.graalvm.org/jdk) -c espresso graalvm-ce-java17-22.3.1
+
+COPY --from=prepare /conf/ ${LOCAL_PATH}/conf
ARG APP_NAME
-ADD target/${APP_NAME} ./
+ADD target/${APP_NAME} ${LOCAL_PATH}/
-ENTRYPOINT ./${APP_NAME} 3307 /conf
+ENTRYPOINT ${LOCAL_PATH}/${APP_NAME} 3307 ${LOCAL_PATH}/conf
diff --git a/distribution/proxy-native/pom.xml b/distribution/proxy-native/pom.xml
index 1e42518e118ae4..9708789c470c05 100644
--- a/distribution/proxy-native/pom.xml
+++ b/distribution/proxy-native/pom.xml
@@ -124,6 +124,7 @@
false
true
+ --language:java
--report-unsupported-elements-at-runtime
@@ -131,6 +132,7 @@
true
+ 0.2.6
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 8e523158383416..6bb7caaa3151b7 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
@@ -21,7 +21,7 @@ services:
apache-shardingsphere-proxy-native:
image: ghcr.io/apache/shardingsphere-proxy-native:latest
volumes:
- - ./custom/conf:/conf
+ - ./custom/conf:/opt/shardingsphere-proxy-native/conf
ports:
- "3307:3307"
```
@@ -34,15 +34,27 @@ services:
需要等待 Junit 5 Platform 的集成,你总是需要在构建 GraalVM Native Image 的过程中,
加上特定于 `GraalVM Native Build Tools` 的 `-DskipNativeTests` 或 `-DskipTests` 参数跳过 Native Image 中的单元测试。
+- 如下 3 个算法类由于涉及到 GraalVM Truffle Espresso 不方便在 host JVM 和 guest JVM 之间交互的 `groovy.lang.Closure`
+ 类,暂未可在 GraalVM Native Image 下使用。
+ - `org.apache.shardingsphere.sharding.algorithm.sharding.complex.ComplexInlineShardingAlgorithm`
+ - `org.apache.shardingsphere.sharding.algorithm.sharding.hint.HintInlineShardingAlgorithm`
+ - `org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm`
+
+- 当前阶段,GraalVM Native Image 形态的 ShardingSphere Proxy 处于混合 AOT ( GraalVM Native Image ) 和 JIT ( GraalVM
+ Truffle Espresso ) 运行的阶段。由于 https://github.com/oracle/graal/issues/4555 尚未关闭,GraalVM Truffle Espresso
+ 运行需要的 `.so` 文件并不会进入 GraalVM Native Image 内。因此如果你需要在 Docker Image 外运行 ShardingSphere Proxy
+ Native 的二进制文件,你需要确保系统环境变量 `GRAALVM_HOME` 或 `JAVA_HOME` 指向 GraalVM 的 `bin` 目录,并且此 GraalVM
+ 实例已经通过 `GraalVM Updater` 安装了 `espresso` 组件。目前,`GRAAL_HOME` 优先级比 `JAVA_HOME` 高。
+
- 本节假定处于 Linux(amd64,aarch64), MacOS(amd64)或 Windows(amd64)环境。
- 如果你位于 MacOS(aarch64/M1) 环境,你需要关注尚未关闭的 https://github.com/oracle/graal/issues/2666。
+ 如果你位于 MacOS(aarch64/M1) 环境,你需要关注尚未关闭的 https://github.com/oracle/graal/issues/2666 。
## 前提条件
1. 根据 https://www.graalvm.org/downloads/ 要求安装和配置 JDK 17 对应的 `GraalVM CE` 或 `GraalVM EE`。
同时可以通过 `SDKMAN!` 安装 JDK 17 对应的 `GraalVM CE`。
-2. 通过 `GraalVM Updater` 工具安装 `native-image` 组件。
+2. 通过 `GraalVM Updater` 工具安装 `native-image` 和 `espresso` 组件。
3. 根据 https://www.graalvm.org/22.2/reference-manual/native-image/#prerequisites 的要求安装本地工具链。
@@ -73,16 +85,16 @@ services:
```xml
-
- com.mysql
- mysql-connector-j
- 8.0.31
-
-
- org.apache.shardingsphere
- shardingsphere-sql-translator-jooq-provider
- 5.2.0
-
+
+ com.mysql
+ mysql-connector-j
+ 8.0.31
+
+
+ org.apache.shardingsphere
+ shardingsphere-sql-translator-jooq-provider
+ 5.3.1
+
```
@@ -116,7 +128,7 @@ services:
apache-shardingsphere-proxy-native:
image: apache/shardingsphere-proxy-native:latest
volumes:
- - ./custom/conf:/conf
+ - ./custom/conf:/opt/shardingsphere-proxy-native/conf
ports:
- "3307:3307"
```
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 bf482eeb6f4395..d33427f0d8d55f 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
@@ -23,7 +23,7 @@ services:
apache-shardingsphere-proxy-native:
image: ghcr.io/apache/shardingsphere-proxy-native:latest
volumes:
- - ./custom/conf:/conf
+ - ./custom/conf:/opt/shardingsphere-proxy-native/conf
ports:
- "3307:3307"
````
@@ -38,8 +38,23 @@ services:
Plus `-DskipNativeTests` or `-DskipTests` parameter specific to `GraalVM Native Build Tools` to skip unit tests in
Native Image.
+- The following three algorithm classes are not available under GraalVM Native Image because they involve
+ the `groovy.lang.Closure` class that is inconvenient for GraalVM Truffle Espresso to interact between the host JVM and
+ the guest JVM.
+ - `org.apache.shardingsphere.sharding.algorithm.sharding.complex.ComplexInlineShardingAlgorithm`
+ - `org.apache.shardingsphere.sharding.algorithm.sharding.hint.HintInlineShardingAlgorithm`
+ - `org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm`
+
+- At the current stage, ShardingSphere Proxy in GraalVM Native Image is in the stage of mixed AOT ( GraalVM
+ Native Image ) and JIT ( GraalVM Truffle Espresso ) operation. Since https://github.com/oracle/graal/issues/4555 has
+ not been closed, the `.so` file required for GraalVM Truffle Espresso to run does not enter the GraalVM Native Image.
+ So if you need to run the binary files of ShardingSphere Proxy Native outside the Docker Image, you need to ensure
+ that the system environment variable `GRAALVM_HOME` or `JAVA_HOME` points to the `bin` directory of GraalVM, and this
+ GraalVM instance has been installed `espresso` component by `GraalVM Updater`. Currently, `GRAAL_HOME` has higher
+ priority than `JAVA_HOME`.
+
- This section assumes a Linux (amd64, aarch64), MacOS (amd64) or Windows (amd64) environment.
- If you are on MacOS(aarch64/M1) environment, you need to follow https://github.com/oracle/graal/issues/2666 which is
+ If you are on MacOS (aarch64/M1) environment, you need to follow https://github.com/oracle/graal/issues/2666 which is
not closed yet.
## Premise
@@ -47,7 +62,7 @@ services:
1. Install and configure `GraalVM CE` or `GraalVM EE` for JDK 17 according to https://www.graalvm.org/downloads/.
`GraalVM CE` for JDK 17 can also be installed via `SDKMAN!`.
-2. Install the `native-image` component via the `GraalVM Updater` tool.
+2. Install the `native-image` and `espresso` component via the `GraalVM Updater` tool.
3. Install the local toolchain as required by https://www.graalvm.org/22.2/reference-manual/native-image/#prerequisites.
@@ -88,7 +103,7 @@ services:
org.apache.shardingsphere
shardingsphere-sql-translator-jooq-provider
- 5.2.0
+ 5.3.1
```
@@ -125,7 +140,7 @@ services:
apache-shardingsphere-proxy-native:
image: apache/shardingsphere-proxy-native:latest
volumes:
- - ./custom/conf:/conf
+ - ./custom/conf:/opt/shardingsphere-proxy-native/conf
ports:
- "3307:3307"
```
diff --git a/infra/pom.xml b/infra/pom.xml
index 3ae2d171c02b1d..bc49370479aa93 100644
--- a/infra/pom.xml
+++ b/infra/pom.xml
@@ -38,5 +38,6 @@
executor
merge
context
+ util-groovy
diff --git a/infra/util-groovy/pom.xml b/infra/util-groovy/pom.xml
new file mode 100644
index 00000000000000..6ddcfb9df74ee9
--- /dev/null
+++ b/infra/util-groovy/pom.xml
@@ -0,0 +1,40 @@
+
+
+
+
+ 4.0.0
+
+ org.apache.shardingsphere
+ shardingsphere-infra
+ 5.3.2-SNAPSHOT
+
+
+ shardingsphere-infra-util-groovy
+
+
+
+ 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
new file mode 100644
index 00000000000000..caacaf5c6917e8
--- /dev/null
+++ b/infra/util-groovy/src/main/java/org/apache/shardingsphere/infra/util/groovy/expr/HotspotInlineExpressionParser.java
@@ -0,0 +1,194 @@
+/*
+ * 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.shardingsphere.infra.util.groovy.expr;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import groovy.lang.Closure;
+import groovy.lang.GString;
+import groovy.lang.GroovyShell;
+import groovy.lang.Script;
+import lombok.RequiredArgsConstructor;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+/**
+ * Inline expression parser.
+ */
+@RequiredArgsConstructor
+public final class HotspotInlineExpressionParser {
+
+ private static final char SPLITTER = ',';
+
+ private static final Map SCRIPTS = new ConcurrentHashMap<>();
+
+ private static final GroovyShell SHELL = new GroovyShell();
+
+ private final String inlineExpression;
+
+ /**
+ * Replace all inline expression placeholders.
+ *
+ * @param inlineExpression inline expression with {@code $->}
+ * @return result inline expression with {@code $}
+ */
+ public static String handlePlaceHolder(final String inlineExpression) {
+ return inlineExpression.contains("$->{") ? inlineExpression.replaceAll("\\$->\\{", "\\$\\{") : inlineExpression;
+ }
+
+ /**
+ * Split and evaluate inline expression.
+ *
+ * @return result list
+ */
+ public List splitAndEvaluate() {
+ return Strings.isNullOrEmpty(inlineExpression) ? Collections.emptyList() : flatten(evaluate(split()));
+ }
+
+ /**
+ * Evaluate closure.
+ *
+ * @return closure
+ */
+ public Closure> evaluateClosure() {
+ return (Closure>) evaluate("{it -> \"" + inlineExpression + "\"}");
+ }
+
+ private List
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ ${maven-dependency-plugin.version}
+