Skip to content

Commit

Permalink
Bump the minimum GraalVM CE version required to compile ShardingSpher…
Browse files Browse the repository at this point in the history
…e's GraalVM Native Image artifacts to JDK22 (#31630)
  • Loading branch information
linghengqian authored Jun 7, 2024
1 parent 2ae56cc commit e1b9bc9
Show file tree
Hide file tree
Showing 30 changed files with 238 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/graalvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
fail-fast: false
matrix:
os: [ 'ubuntu-latest' ]
java-version: [ '21.0.2' ]
java-version: [ '22.0.1' ]
steps:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
with:
java-version: '21.0.2'
java-version: '22.0.1'
distribution: 'graalvm-community'
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/cache@v4
Expand Down
3 changes: 0 additions & 3 deletions distribution/proxy-native/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@
<profiles>
<profile>
<id>release.native</id>
<properties>
<java.version>21</java.version>
</properties>
<build>
<finalName>apache-shardingsphere-${project.version}</finalName>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ Image,你需要借助于 GraalVM Native Build Tools。GraalVM Native Build Too
CE 的 `native-image` 命令行工具的长篇大论的 shell 命令。

ShardingSphere JDBC 要求在如下或更高版本的 `GraalVM CE` 完成构建 GraalVM Native Image。使用者可通过 SDKMAN! 快速切换 JDK。这同理
适用于 `Oracle GraalVM``Liberica Native Image Kit``Mandrel``GraalVM CE` 的下游发行版。
适用于 `Oracle GraalVM``Liberica NIK``Mandrel``GraalVM CE` 的下游发行版。

- GraalVM CE 23.1.2 For JDK 21.0.2,对应于 SDKMAN! 的 `21.0.2-graalce`
- GraalVM CE 24.0.0 For JDK 22,对应于 SDKMAN! 的 `22-graalce`
- GraalVM CE For JDK 22.0.1,对应于 SDKMAN! 的 `22.0.1-graalce`
- Oracle GraalVM For JDK 22.0.1,对应于 SDKMAN! 的 `22.0.1-graal`
- Liberica NIK For JDK 22.0.1,对应于 SDKMAN! 的 `24.0.1.r22-nik`
- Mandrel For JDK 22.0.1,对应于 SDKMAN! 的 `24.0.1.r22-mandrel`

用户依然可以使用 SDKMAN! 上的 `21.0.2-graalce` 等旧版本的 GraalVM CE 来构建 ShardingSphere 的 GraalVM Native Image 产物。
但这将导致集成部分第三方依赖时,构建 GraalVM Native Image 失败。
典型的例子来自 HiveServer2 JDBC Driver 相关的 `org.apache.hive:hive-jdbc:4.0.0`,HiveServer2 JDBC Driver 使用了 AWT 相关的类,
而 GraalVM CE 对 `java.beans.**` package 的支持仅位于 GraalVM CE For JDK22 及更高版本。

### Maven 生态

Expand Down Expand Up @@ -309,8 +316,8 @@ ShardingSphere 定义了 `nativeTestInShardingSphere` 的 Maven Profile 用于
sudo apt install unzip zip curl sed -y
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install java 21.0.2-graalce
sdk use java 21.0.2-graalce
sdk install java 22.0.1-graalce
sdk use java 22.0.1-graalce
sudo apt-get install build-essential libz-dev zlib1g-dev -y
git clone [email protected]:apache/shardingsphere.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ Image, you need to resort to GraalVM Native Build Tools. GraalVM Native Build To
to simplify long list of shell commands for GraalVM CE's `native-image` command line tool.

ShardingSphere JDBC requires GraalVM Native Image to be built with GraalVM CE as follows or higher. Users can quickly switch
JDK through `SDKMAN!`. Same reason applicable to downstream distributions of `GraalVM CE` such as `Oracle GraalVM`, `Liberica Native Image Kit`
JDK through `SDKMAN!`. Same reason applicable to downstream distributions of `GraalVM CE` such as `Oracle GraalVM`, `Liberica NIK`
and `Mandrel`.

- GraalVM CE 23.1.2 For JDK 21.0.2, corresponding to `21.0.2-graalce` of SDKMAN!
- GraalVM CE 24.0.0 For JDK 22, corresponding to `22-graalce` of SDKMAN!
- GraalVM CE For JDK 22.0.1, corresponding to `21.0.2-graalce` of SDKMAN!
- Oracle GraalVM For JDK 22.0.1, corresponding to `22.0.1-graal` of SDKMAN!
- Liberica NIK For JDK 22.0.1, corresponding to `24.0.1.r22-nik` of SDKMAN!
- Mandrel For JDK 22.0.1, corresponding to `24.0.1.r22-mandrel` of SDKMAN!

Users can still use the old versions of GraalVM CE such as `21.0.2-graalce` on SDKMAN! to build the GraalVM Native Image product of ShardingSphere.
However, this will cause the failure of building the GraalVM Native Image when integrating some third-party dependencies.
A typical example is related to the `org.apache.hive:hive-jdbc:4.0.0` HiveServer2 JDBC Driver, which uses AWT-related classes.
GraalVM CE only supports AWT for GraalVM CE For JDK22 and higher versions.

### Maven Ecology

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ services:
## 前提条件
1. 根据 https://www.graalvm.org/downloads/ 要求安装和配置 JDK 21 对应的 `GraalVM Community Edition`
1. 根据 https://www.graalvm.org/downloads/ 要求安装和配置 JDK 22 对应的 `GraalVM Community Edition`
或 `GraalVM Community Edition` 的下游发行版。若使用 `SDKMAN!`,

```shell
sdk install java 21.0.2-graalce
sdk install java 22.0.1-graalce
```

2. 根据 https://www.graalvm.org/jdk21/reference-manual/native-image/#prerequisites 的要求安装本地工具链。
2. 根据 https://www.graalvm.org/jdk22/reference-manual/native-image/#prerequisites 的要求安装本地工具链。

3. 如果需要构建 Docker Image, 确保 `docker-ce` 已安装。

Expand All @@ -56,7 +56,7 @@ sdk install java 21.0.2-graalce
- 在 Git Source 同级目录下执行如下命令, 直接完成 Native Image 的构建。

```bash
./mvnw -am -pl distribution/proxy-native -B -T1C -Prelease.native -DskipTests clean package
./mvnw -am -pl distribution/proxy-native -T1C -Prelease.native -DskipTests clean package
```

- 情形二:需要使用存在 SPI 实现的 JAR 或 GPL V2 等 LICENSE 的第三方依赖的 JAR。
Expand Down Expand Up @@ -113,7 +113,7 @@ services:

- 如果你不对 Git Source 做任何更改, 上文提及的命令将使用 `oraclelinux:9-slim` 作为 Base Docker Image。
但如果你希望使用 `busybox:glic`,`gcr.io/distroless/base` 或 `scratch` 等更小体积的 Docker Image 作为 Base Docker
Image,你需要根据 https://www.graalvm.org/jdk21/reference-manual/native-image/guides/build-static-executables/ 的要求,
Image,你需要根据 https://www.graalvm.org/jdk22/reference-manual/native-image/guides/build-static-executables/ 的要求,
做为 `pom.xml`的 `native profile` 添加 `-H:+StaticExecutableWithDynamicLibC` 的 `jvmArgs` 等操作。
另请注意,某些第三方依赖将需要在 `Dockerfile` 安装更多系统库,例如 `libdl`。
因此请确保根据你的使用情况调整 `distribution/proxy-native` 下的 `pom.xml` 和 `Dockerfile` 的内容。
Expand All @@ -123,7 +123,7 @@ services:
针对 GraalVM Native Image 形态的 ShardingSphere Proxy,其提供的可观察性的能力与
https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-proxy/observability/ 并不一致。

你可以使用 https://www.graalvm.org/jdk21/tools/ 提供的一系列命令行工具或可视化工具观察 GraalVM Native Image 的内部行为,
你可以使用 https://www.graalvm.org/jdk22/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
及其后继。如果你使用的不是 Linux,则无法对 GraalVM Native Image 进行 Debug,请关注尚未关闭的
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ services:
## Premise

1. Install and configure `GraalVM Community Edition` or a downstream distribution of `GraalVM Community Edition` for
JDK 21 according to https://www.graalvm.org/downloads/. If `SDKMAN!` is used,
JDK 22 according to https://www.graalvm.org/downloads/. If `SDKMAN!` is used,

```shell
sdk install java 21.0.2-graalce
sdk install java 22.0.1-graalce
```

2. Install the local toolchain as required by https://www.graalvm.org/jdk21/reference-manual/native-image/#prerequisites.
2. Install the local toolchain as required by https://www.graalvm.org/jdk22/reference-manual/native-image/#prerequisites.

3. If you need to build a Docker Image, make sure `docker-ce` is installed.

Expand Down Expand Up @@ -99,7 +99,7 @@ sdk install java 21.0.2-graalce
exist for SPI implementation or third-party dependencies.
```shell
./mvnw -am -pl distribution/proxy-native -B -T1C -Prelease.native,docker.native -DskipTests clean package
./mvnw -am -pl distribution/proxy-native -T1C -Prelease.native,docker.native -DskipTests clean package
```

- Assuming that there is a `conf` folder containing `global.yaml` as `./custom/conf`, you can start the Docker Image
Expand All @@ -120,7 +120,7 @@ services:
- If you don't make any changes to the Git Source, the commands mentioned above will use `oraclelinux:9-slim` as the
Base Docker Image. But if you want to use a smaller Docker Image like `busybox:glic`, `gcr.io/distroless/base` or
`scratch` as the Base Docker Image, you need according
to https://www.graalvm.org/jdk21/reference-manual/native-image/guides/build-static-executables/,
to https://www.graalvm.org/jdk22/reference-manual/native-image/guides/build-static-executables/,
add operations such as `-H:+StaticExecutableWithDynamicLibC` to `jvmArgs` as the `native profile` of `pom.xml`.
Also note that some 3rd-party dependencies will require more system libraries such as `libdl` to be installed in
the `Dockerfile`. So make sure to tune `distribution/proxy-native` according to your usage `pom.xml` and `Dockerfile`
Expand All @@ -133,7 +133,7 @@ with https://shardingsphere.apache.org/document/current/cn/user-manual/shardings
not consistent.

You can observe GraalVM Native Image using a series of command line tools or visualization tools available
at https://www.graalvm.org/jdk21/tools/, and use VSCode to debug it according to its requirements.
at https://www.graalvm.org/jdk22/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 follow
https://blog.jetbrains.com/idea/2022/06/intellij-idea-2022-2-eap-5/#Experimental_GraalVM_Native_Debugger_for_Java
and its successors. If you are not using Linux, you cannot debug GraalVM Native Image, please pay attention
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ public final class ReflectContext implements AutoCloseable {

/**
* This method is a simulation of the following operation.
* // CHECKSTYLE:OFF
* <pre class="code">
* private final Context context = Context.newBuilder("java")
* .allowAllAccess(true)
* .allowValueSharing(false)
* .option("java.Classpath", JAVA_CLASSPATH)
* .build();
* </pre>
* // CHECKSTYLE:ON
* TODO <a href="https://github.com/oracle/graal/issues/4555">oracle/graal#4555</a> not yet closed.
* Maybe sometimes shardingsphere need `.option("java.Properties.org.graalvm.home", System.getenv("JAVA_HOME")).
*
Expand Down
Loading

0 comments on commit e1b9bc9

Please sign in to comment.