Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ShardingSphere Proxy in GraalVM Native Image form available #21347

Closed
7 tasks done
linghengqian opened this issue Oct 5, 2022 · 36 comments · Fixed by #29000
Closed
7 tasks done

Make ShardingSphere Proxy in GraalVM Native Image form available #21347

linghengqian opened this issue Oct 5, 2022 · 36 comments · Fixed by #29000

Comments

@linghengqian
Copy link
Member

linghengqian commented Oct 5, 2022

Feature Request

For English only, other languages will not accept.

Please pay attention on issues you submitted, because we maybe need more details.
If no response anymore and we cannot make decision by current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Is your feature request related to a problem?

Describe the feature you would like.

@linghengqian
Copy link
Member Author

  • I am working on this issue. However, this issue is affected by many issues and is unlikely to be resolved in the short term.

@linghengqian
Copy link
Member Author

  • I'm assuming the GraalVM reachability metadata about Apache Curator will be migrated out of Spring Cloud since their community just migrated the corresponding metadata for Consul Client 1.4.5.

@linghengqian
Copy link
Member Author

linghengqian commented Oct 13, 2022

@linghengqian
Copy link
Member Author

linghengqian commented Oct 14, 2022

  • I found and resolved the conflict around astomikos ,Jetcd and vertx in the new PR, refer to Update library to serve building GraalVM Native Image #21571 . There were some breaking changes in hikaricp 4.0.3, so I've temporarily removed tweaks to it.
  • I don't feel the need to switch to Junit Jupiter right away, so I still use Junit Vintage for the relevant PRs.
  • image
  • The new properties of HikarciCP are blocking my PR and I feel like I need to handle it better in a separate PR. Because it also involves how to match to HikariCP 5.0.1's GraalVM reachability metadata.
  • image

@linghengqian
Copy link
Member Author

linghengqian commented Oct 15, 2022

@linghengqian
Copy link
Member Author

linghengqian commented Oct 16, 2022

@linghengqian
Copy link
Member Author

@linghengqian
Copy link
Member Author

linghengqian commented Oct 22, 2022

com.github.luben.zstd.ZstdCompressCtx
org.conscrypt.ConscryptEngine
ch.qos.logback.core.encoder.LayoutWrappingEncoder
com.aayushatharva.brotli4j.Brotli4jLoader
com.github.luben.zstd.Zstd
com.ning.compress.lzf.impl.UnsafeChunkDecoder
io.netty.handler.codec.compression.Lz4FrameDecoder
net.jpountz.lz4.LZ4Exception
io.netty.handler.codec.compression.Lz4FrameEncoder
io.netty.handler.codec.marshalling.CompatibleMarshallingDecoder
org.jboss.marshalling.ByteInput
io.netty.handler.codec.marshalling.CompatibleMarshallingEncoder
org.jboss.marshalling.ByteOutput
io.netty.handler.codec.marshalling.MarshallingDecoder
io.netty.handler.codec.marshalling.MarshallingEncoder
org.apache.commons.logging.impl.Log4JLogger
org.apache.log4j.Category
org.apache.log4j.Level
org.apache.log4j.Priority
org.apache.logging.log4j.Logger
org.apache.logging.log4j.core.LoggerContext
org.apache.logging.log4j.message.DefaultFlowMessageFactory
org.apache.logging.log4j.message.ReusableMessageFactory
org.conscrypt.Conscrypt
org.conscrypt.OpenSSLContextImpl
org.hamcrest.number.OrderingComparison
com.zaxxer.hikari.HikariConfig

@linghengqian
Copy link
Member Author

  • It looks like Add support for Log4j2 oracle/graalvm-reachability-metadata#50 explains the issues related to Log4j2. Pending https://issues.apache.org/jira/browse/LOG4J2-2649 . This seems to require us to force-pull the Log4j2 version in the native profile to 3.0.0-SNAPSHOT. Should I say using SNAPSHOT is a weird behavior?

  • It just looks like log4j2's 3.0.0-SNAPSHOT completely removes stuff related to java.lang.invoke.LambdaMetafactory, the graalvm team almost doesn't want to support such usage at all, which involves SecurityManager. I assume that I should be able to find a simple operation in the native profile of the shardingsphere to specify the version of all the passed log4j2 dependencies to 3.0.0-SNAPSHOT, and also remove the log4j1 from the upstream dependencies, and finally Add support for Log4j2 oracle/graalvm-reachability-metadata#50 can be reopened and the metadata of log4j2 can be added. However, I am quite depressed how ShardingSphere CI Log can see a hamcrest related class when building GraalVM Native Image warning, the test library is not in the final product.

@linghengqian
Copy link
Member Author

Warning: Could not resolve class com.github.luben.zstd.ZstdCompressCtx for reflection configuration. Reason: java.lang.ClassNotFoundException: com.github.luben.zstd.ZstdCompressCtx.
Warning: Could not resolve class org.conscrypt.ConscryptEngine for reflection configuration. Reason: java.lang.ClassNotFoundException: org.conscrypt.ConscryptEngine.
Warning: Could not resolve class org.conscrypt.ConscryptEngine for reflection configuration. Reason: java.lang.ClassNotFoundException: org.conscrypt.ConscryptEngine.
Warning: Could not resolve class org.conscrypt.ConscryptEngine for reflection configuration. Reason: java.lang.ClassNotFoundException: org.conscrypt.ConscryptEngine.
Warning: Method ch.qos.logback.core.encoder.LayoutWrappingEncoder.setParent(Appender) not found.
Warning: Could not resolve class com.aayushatharva.brotli4j.Brotli4jLoader for reflection configuration. Reason: java.lang.ClassNotFoundException: com.aayushatharva.brotli4j.Brotli4jLoader.
Warning: Could not resolve class com.github.luben.zstd.Zstd for reflection configuration. Reason: java.lang.ClassNotFoundException: com.github.luben.zstd.Zstd.
Warning: Could not resolve class com.ning.compress.lzf.impl.UnsafeChunkDecoder for reflection configuration. Reason: java.lang.ClassNotFoundException: com.ning.compress.lzf.impl.UnsafeChunkDecoder.
Warning: Could not register io.netty.handler.codec.compression.Lz4FrameDecoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: net/jpountz/lz4/LZ4Exception.
Warning: Could not register io.netty.handler.codec.compression.Lz4FrameEncoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: net/jpountz/lz4/LZ4Exception.
Warning: Could not register io.netty.handler.codec.marshalling.CompatibleMarshallingDecoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteInput.
Warning: Could not register io.netty.handler.codec.marshalling.CompatibleMarshallingEncoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteOutput.
Warning: Could not register io.netty.handler.codec.marshalling.MarshallingDecoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteInput.
Warning: Could not register io.netty.handler.codec.marshalling.MarshallingEncoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteOutput.
Warning: Could not register method org.apache.commons.logging.impl.Log4JLogger.<init>(String) for reflection. Reason: java.lang.NoClassDefFoundError: org/apache/log4j/Category.
Warning: Could not resolve class org.apache.log4j.Level for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.Level.
Warning: Could not resolve class org.apache.log4j.Priority for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.log4j.Priority.
Warning: Could not resolve class org.apache.logging.log4j.Logger for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.logging.log4j.Logger.
Warning: Could not resolve class org.apache.logging.log4j.core.LoggerContext for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.logging.log4j.core.LoggerContext.
Warning: Could not resolve class org.apache.logging.log4j.message.DefaultFlowMessageFactory for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.logging.log4j.message.DefaultFlowMessageFactory.
Warning: Could not resolve class org.apache.logging.log4j.message.ReusableMessageFactory for reflection configuration. Reason: java.lang.ClassNotFoundException: org.apache.logging.log4j.message.ReusableMessageFactory.
Warning: Could not resolve class org.conscrypt.Conscrypt for reflection configuration. Reason: java.lang.ClassNotFoundException: org.conscrypt.Conscrypt.
Warning: Could not resolve class org.conscrypt.OpenSSLContextImpl$TLSv13 for reflection configuration. Reason: java.lang.ClassNotFoundException: org.conscrypt.OpenSSLContextImpl$TLSv13.
Warning: Could not resolve class org.hamcrest.number.OrderingComparison for reflection configuration. Reason: java.lang.ClassNotFoundException: org.hamcrest.number.OrderingComparison.
Warning: Method com.zaxxer.hikari.HikariConfig.getScheduledExecutorService() not found.
Warning: Method com.zaxxer.hikari.HikariConfig.isInitializationFailFast() not found.
Warning: Method com.zaxxer.hikari.HikariConfig.isJdbc4ConnectionTest() not found.
Warning: Method com.zaxxer.hikari.HikariConfig.setInitializationFailFast(boolean) not found.
Warning: Method com.zaxxer.hikari.HikariConfig.setJdbc4ConnectionTest(boolean) not found.
Warning: Method com.zaxxer.hikari.HikariConfig.setScheduledExecutorService(ScheduledThreadPoolExecutor) not found.
Warning: Could not register io.netty.handler.codec.compression.Lz4FrameDecoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: net/jpountz/lz4/LZ4Exception.
Warning: Could not register io.netty.handler.codec.compression.Lz4FrameEncoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: net/jpountz/lz4/LZ4Exception.
Warning: Could not register io.netty.handler.codec.marshalling.CompatibleMarshallingDecoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteInput.
Warning: Could not register io.netty.handler.codec.marshalling.CompatibleMarshallingEncoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteOutput.
Warning: Could not register io.netty.handler.codec.marshalling.MarshallingDecoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteInput.
Warning: Could not register io.netty.handler.codec.marshalling.MarshallingEncoder: queryAllPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteOutput.

@linghengqian
Copy link
Member Author

linghengqian commented Nov 16, 2022

@linghengqian
Copy link
Member Author

@linghengqian
Copy link
Member Author

@RaigorJiang
Copy link
Contributor

Great work 👍

@zhfeng
Copy link
Contributor

zhfeng commented Nov 16, 2023

Thanks @linghengqian and it is really very nice work! Do you have any plan to write a simple application to compare the performance between the GraalVM Native and JVM? I also write a quarkus extension to run with shardingsphere-jdbc in native mode which compile and evaluate the groovy rules at the build time.

@linghengqian
Copy link
Member Author

Thanks @linghengqian and it is really very nice work! Do you have any plan to write a simple application to compare the performance between the GraalVM Native and JVM? I also write a quarkus extension to run with shardingsphere-jdbc in native mode which compile and evaluate the groovy rules at the build time.

  • Sorry, it is not convenient for me to write a unit test for performance comparison because I lack the knowledge related to stress testing ShardingSphere.

  • For groovyshell, the unit tests related to nativeTest have skipped the use of groovyshell. Please refer to https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/graalvm-native-image/ . The relevant unit tests are located at org.apache.shardingsphere:shardingsphere-infra-nativetest.

  • This involves the buildArgs of --report-unsupported-elements-at-runtim which downstream consumers must use.

  • To facilitate review, I compressed the size of the initial subset of unit tests. What can be verified now is that in the standalone mode of ShardingSphere, the five functions and derivative functions of sharding, readwrite-splitting, mask, shadow and encrypt can be used under native image. For cluster mode and DistSQL, I have not added corresponding verification yet, and additional GraalVM Reachability Metadata json files should be required.

  • Since the modifications to these json files are not actually related to the current issue, I will discuss them in a new issue later.

  • The core problem solved by this issue is that with the help of the new Row Value Expression SPI, you can configure ShardingSphere without using Groovy syntax at all through the buildArgs of --report-unsupported-elements-at-runtim, which makes building a GraalVM Native Image that completes nativeTest becomes a reality.

  • If needed, I can help investigate the nativeTest failure issue on the quarkus-shardingsphere side, but this requires quarkus-shardingsphere to synchronize the master branch of shardingsphere. In addition, the naming of related submodules may still be variable in shardingsphere.

@zhfeng
Copy link
Contributor

zhfeng commented Nov 16, 2023

Well, quarkus-shardingsphere does not depend on GraalVM Reachability Metadata directly but I think it could be helpful to build native images since native-image tool can detect the .json configuartion in the jars and add them automatically. Also I think we need to avoid using --report-unsupported-elements-at-runtim because it can lead to any unexpected error at runtime.

@linghengqian
Copy link
Member Author

Well, quarkus-shardingsphere does not depend on GraalVM Reachability Metadata directly but I think it could be helpful to build native images since native-image tool can detect the .json configuartion in the jars and add them automatically. Also I think we need to avoid using --report-unsupported-elements-at-runtim because it can lead to any unexpected error at runtime.

  • This is natural. The current need to initialize GroovyShell related classes is because the default implementation of Row Value
    Expression SPI uses GroovyShell, which results in the need for downstream to actively add buildArgs for compatibility. Maybe I can modify shardingsphere-infra-expr-core to expose a possible configuration item on the ShardingSphere side. Or I can break this non-existent compatibility under GraalVM Native Image.

@zhfeng
Copy link
Contributor

zhfeng commented Nov 16, 2023

OK, thank for clarifying.

@linghengqian
Copy link
Member Author

Well, quarkus-shardingsphere does not depend on GraalVM Reachability Metadata directly but I think it could be helpful to build native images since native-image tool can detect the .json configuartion in the jars and add them automatically. Also I think we need to avoid using --report-unsupported-elements-at-runtim because it can lead to any unexpected error at runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment