From fe5348c64bb28f547d1257e0f973bc6076fc9cb7 Mon Sep 17 00:00:00 2001 From: linghengqian Date: Fri, 8 Mar 2024 16:00:41 +0800 Subject: [PATCH] Fixes for unjudged Seata AT transactions caused by #30462 --- .../graalvm-native-image/_index.cn.md | 8 +++-- .../graalvm-native-image/_index.en.md | 9 +++-- .../engine/driver/jdbc/JDBCExecutor.java | 2 +- .../reflect-config.json | 34 +++++++++++-------- .../resource-config.json | 8 ++--- .../TransactionConnectionContext.java | 8 ++--- pom.xml | 2 +- .../native-image-filter/extra-filter.json | 1 - .../native-image-filter/user-code-filter.json | 2 ++ 9 files changed, 42 insertions(+), 32 deletions(-) diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.cn.md b/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.cn.md index 283ccba524810..fb8c5bb0ca003 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.cn.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.cn.md @@ -21,6 +21,8 @@ ShardingSphere JDBC 要求在如下或更高版本的 `GraalVM CE` 完成构建 使用者需要主动使用 GraalVM Reachability Metadata 中央仓库。 如下配置可供参考,以配置项目额外的 Maven Profiles,以 GraalVM Native Build Tools 的文档为准。 +由于 Gradle 8.6 的限制,用户需要通过 Maven 依赖的形式引入 Metadata Repository 的 JSON 文件。 +参考 https://github.com/graalvm/native-build-tools/issues/572 。 ```xml @@ -37,7 +39,7 @@ ShardingSphere JDBC 要求在如下或更高版本的 `GraalVM CE` 完成构建 org.graalvm.buildtools native-maven-plugin - 0.10.0 + 0.10.1 true @@ -73,12 +75,12 @@ ShardingSphere JDBC 要求在如下或更高版本的 `GraalVM CE` 完成构建 ```groovy plugins { - id 'org.graalvm.buildtools.native' version '0.10.0' + id 'org.graalvm.buildtools.native' version '0.10.1' } dependencies { implementation 'org.apache.shardingsphere:shardingsphere-jdbc:${shardingsphere.version}' - implementation(group: 'org.graalvm.buildtools', name: 'graalvm-reachability-metadata', version: '0.10.0', classifier: 'repository', ext: 'zip') + implementation(group: 'org.graalvm.buildtools', name: 'graalvm-reachability-metadata', version: '0.10.1', classifier: 'repository', ext: 'zip') } graalvmNative { diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.en.md b/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.en.md index adfca28f289c3..660c236f46ab7 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.en.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/graalvm-native-image/_index.en.md @@ -39,7 +39,7 @@ and the documentation of GraalVM Native Build Tools shall prevail. org.graalvm.buildtools native-maven-plugin - 0.10.0 + 0.10.1 true @@ -73,15 +73,18 @@ and the documentation of GraalVM Native Build Tools shall prevail. Users need to actively use the GraalVM Reachability Metadata central repository. The following configuration is for reference to configure additional Gradle Tasks for the project, and the documentation of GraalVM Native Build Tools shall prevail. +Due to the limitations of Gradle 8.6, +users need to introduce the JSON file of Metadata Repository through Maven dependency. +Reference https://github.com/graalvm/native-build-tools/issues/572 . ```groovy plugins { - id 'org.graalvm.buildtools.native' version '0.10.0' + id 'org.graalvm.buildtools.native' version '0.10.1' } dependencies { implementation 'org.apache.shardingsphere:shardingsphere-jdbc:${shardingsphere.version}' - implementation(group: 'org.graalvm.buildtools', name: 'graalvm-reachability-metadata', version: '0.10.0', classifier: 'repository', ext: 'zip') + implementation(group: 'org.graalvm.buildtools', name: 'graalvm-reachability-metadata', version: '0.10.1', classifier: 'repository', ext: 'zip') } graalvmNative { diff --git a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutor.java b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutor.java index db3445419fc40..5199ad837da04 100644 --- a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutor.java +++ b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/engine/driver/jdbc/JDBCExecutor.java @@ -63,7 +63,7 @@ public List execute(final ExecutionGroupContext execut public List execute(final ExecutionGroupContext executionGroupContext, final JDBCExecutorCallback firstCallback, final JDBCExecutorCallback callback) throws SQLException { try { - return executorEngine.execute(executionGroupContext, firstCallback, callback, connectionContext.getTransactionContext().isInXATransaction()); + return executorEngine.execute(executionGroupContext, firstCallback, callback, connectionContext.getTransactionContext().isInDistributedTransaction()); } catch (final SQLException ex) { SQLExecutorExceptionHandler.handleException(ex); return Collections.emptyList(); diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json index 7490dab53800d..861acb9766512 100644 --- a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json @@ -14,7 +14,7 @@ "name":"org.apache.shardingsphere.authority.yaml.config.YamlAuthorityRuleConfiguration" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.broadcast.yaml.swapper.NewYamlBroadcastRuleConfigurationSwapper"}, + "condition":{"typeReachable":"org.apache.shardingsphere.broadcast.yaml.swapper.YamlBroadcastDataNodeRuleConfigurationSwapper"}, "name":"org.apache.shardingsphere.broadcast.yaml.config.YamlBroadcastRuleConfiguration", "allDeclaredFields":true, "methods":[{"name":"getTables","parameterTypes":[] }] @@ -125,7 +125,7 @@ "name":"org.apache.shardingsphere.encrypt.yaml.config.rule.YamlEncryptColumnRuleConfigurationCustomizer" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.encrypt.yaml.swapper.NewYamlEncryptRuleConfigurationSwapper"}, + "condition":{"typeReachable":"org.apache.shardingsphere.encrypt.yaml.swapper.YamlEncryptDataNodeRuleConfigurationSwapper"}, "name":"org.apache.shardingsphere.encrypt.yaml.config.rule.YamlEncryptTableRuleConfiguration", "allDeclaredFields":true, "methods":[{"name":"getColumns","parameterTypes":[] }, {"name":"getName","parameterTypes":[] }] @@ -150,7 +150,7 @@ "name":"org.apache.shardingsphere.globalclock.core.yaml.config.YamlGlobalClockRuleConfiguration" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.encrypt.yaml.swapper.NewYamlEncryptRuleConfigurationSwapper"}, + "condition":{"typeReachable":"org.apache.shardingsphere.encrypt.yaml.swapper.YamlEncryptDataNodeRuleConfigurationSwapper"}, "name":"org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration", "allDeclaredFields":true, "methods":[{"name":"getProps","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }] @@ -163,19 +163,19 @@ "methods":[{"name":"","parameterTypes":[] }, {"name":"setProps","parameterTypes":["java.util.Properties"] }, {"name":"setType","parameterTypes":["java.lang.String"] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mask.yaml.swapper.NewYamlMaskRuleConfigurationSwapper"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mask.yaml.swapper.YamlMaskDataNodeRuleConfigurationSwapper"}, "name":"org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration", "allDeclaredFields":true, "methods":[{"name":"getProps","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.shadow.yaml.swapper.NewYamlShadowRuleConfigurationSwapper"}, + "condition":{"typeReachable":"org.apache.shardingsphere.shadow.yaml.swapper.YamlShadowDataNodeRuleConfigurationSwapper"}, "name":"org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration", "allDeclaredFields":true, "methods":[{"name":"getProps","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.sharding.yaml.swapper.NewYamlShardingRuleConfigurationSwapper"}, + "condition":{"typeReachable":"org.apache.shardingsphere.sharding.yaml.swapper.YamlShardingDataNodeRuleConfigurationSwapper"}, "name":"org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration", "allDeclaredFields":true, "methods":[{"name":"getProps","parameterTypes":[] }, {"name":"getType","parameterTypes":[] }] @@ -466,7 +466,7 @@ "methods":[{"name":"","parameterTypes":[] }, {"name":"setColumns","parameterTypes":["java.util.Map"] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.mask.yaml.swapper.NewYamlMaskRuleConfigurationSwapper"}, + "condition":{"typeReachable":"org.apache.shardingsphere.mask.yaml.swapper.YamlMaskDataNodeRuleConfigurationSwapper"}, "name":"org.apache.shardingsphere.mask.yaml.config.rule.YamlMaskTableRuleConfiguration", "allDeclaredFields":true, "methods":[{"name":"getColumns","parameterTypes":[] }, {"name":"getName","parameterTypes":[] }] @@ -614,7 +614,7 @@ "name":"org.apache.shardingsphere.parser.yaml.config.YamlSQLParserRuleConfiguration" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.parser.yaml.swapper.NewYamlSQLParserRuleConfigurationSwapper"}, + "condition":{"typeReachable":"org.apache.shardingsphere.parser.yaml.swapper.YamlSQLParserDataNodeRuleConfigurationSwapper"}, "name":"org.apache.shardingsphere.parser.yaml.config.YamlSQLParserRuleConfiguration", "allDeclaredFields":true, "methods":[{"name":"getParseTreeCache","parameterTypes":[] }, {"name":"getSqlStatementCache","parameterTypes":[] }] @@ -654,7 +654,7 @@ "methods":[{"name":"","parameterTypes":[] }, {"name":"setReadDataSourceNames","parameterTypes":["java.util.List"] }, {"name":"setWriteDataSourceName","parameterTypes":["java.lang.String"] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.readwritesplitting.yaml.swapper.NewYamlReadwriteSplittingRuleConfigurationSwapper"}, + "condition":{"typeReachable":"org.apache.shardingsphere.readwritesplitting.yaml.swapper.YamlReadwriteSplittingDataNodeRuleConfigurationSwapper"}, "name":"org.apache.shardingsphere.readwritesplitting.yaml.config.rule.YamlReadwriteSplittingDataSourceRuleConfiguration", "allDeclaredFields":true, "methods":[{"name":"getLoadBalancerName","parameterTypes":[] }, {"name":"getReadDataSourceNames","parameterTypes":[] }, {"name":"getTransactionalReadQueryStrategy","parameterTypes":[] }, {"name":"getWriteDataSourceName","parameterTypes":[] }] @@ -709,7 +709,7 @@ "methods":[{"name":"","parameterTypes":[] }, {"name":"setProductionDataSourceName","parameterTypes":["java.lang.String"] }, {"name":"setShadowDataSourceName","parameterTypes":["java.lang.String"] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.shadow.yaml.swapper.NewYamlShadowRuleConfigurationSwapper"}, + "condition":{"typeReachable":"org.apache.shardingsphere.shadow.yaml.swapper.YamlShadowDataNodeRuleConfigurationSwapper"}, "name":"org.apache.shardingsphere.shadow.yaml.config.datasource.YamlShadowDataSourceConfiguration", "allDeclaredFields":true, "methods":[{"name":"getProductionDataSourceName","parameterTypes":[] }, {"name":"getShadowDataSourceName","parameterTypes":[] }] @@ -730,7 +730,7 @@ "methods":[{"name":"","parameterTypes":[] }, {"name":"setDataSourceNames","parameterTypes":["java.util.Collection"] }, {"name":"setShadowAlgorithmNames","parameterTypes":["java.util.Collection"] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.shadow.yaml.swapper.NewYamlShadowRuleConfigurationSwapper"}, + "condition":{"typeReachable":"org.apache.shardingsphere.shadow.yaml.swapper.YamlShadowDataNodeRuleConfigurationSwapper"}, "name":"org.apache.shardingsphere.shadow.yaml.config.table.YamlShadowTableConfiguration", "allDeclaredFields":true, "methods":[{"name":"getDataSourceNames","parameterTypes":[] }, {"name":"getShadowAlgorithmNames","parameterTypes":[] }] @@ -825,7 +825,7 @@ "methods":[{"name":"","parameterTypes":[] }, {"name":"setActualDataNodes","parameterTypes":["java.lang.String"] }, {"name":"setKeyGenerateStrategy","parameterTypes":["org.apache.shardingsphere.sharding.yaml.config.strategy.keygen.YamlKeyGenerateStrategyConfiguration"] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.sharding.yaml.swapper.NewYamlShardingRuleConfigurationSwapper"}, + "condition":{"typeReachable":"org.apache.shardingsphere.sharding.yaml.swapper.YamlShardingDataNodeRuleConfigurationSwapper"}, "name":"org.apache.shardingsphere.sharding.yaml.config.rule.YamlTableRuleConfiguration", "allDeclaredFields":true, "methods":[{"name":"getActualDataNodes","parameterTypes":[] }, {"name":"getAuditStrategy","parameterTypes":[] }, {"name":"getDatabaseStrategy","parameterTypes":[] }, {"name":"getKeyGenerateStrategy","parameterTypes":[] }, {"name":"getLogicTable","parameterTypes":[] }, {"name":"getTableStrategy","parameterTypes":[] }] @@ -866,7 +866,7 @@ "methods":[{"name":"","parameterTypes":[] }, {"name":"setStandard","parameterTypes":["org.apache.shardingsphere.sharding.yaml.config.strategy.sharding.YamlStandardShardingStrategyConfiguration"] }] }, { - "condition":{"typeReachable":"org.apache.shardingsphere.sharding.yaml.swapper.NewYamlShardingRuleConfigurationSwapper"}, + "condition":{"typeReachable":"org.apache.shardingsphere.sharding.yaml.swapper.YamlShardingDataNodeRuleConfigurationSwapper"}, "name":"org.apache.shardingsphere.sharding.yaml.config.strategy.sharding.YamlShardingStrategyConfiguration", "allDeclaredFields":true, "methods":[{"name":"getComplex","parameterTypes":[] }, {"name":"getHint","parameterTypes":[] }, {"name":"getNone","parameterTypes":[] }, {"name":"getStandard","parameterTypes":[] }] @@ -931,7 +931,7 @@ "queryAllPublicMethods":true }, { - "condition":{"typeReachable":"org.apache.shardingsphere.single.yaml.config.swapper.NewYamlSingleRuleConfigurationSwapper"}, + "condition":{"typeReachable":"org.apache.shardingsphere.single.yaml.config.swapper.YamlSingleDataNodeRuleConfigurationSwapper"}, "name":"org.apache.shardingsphere.single.yaml.config.pojo.YamlSingleRuleConfiguration", "allDeclaredFields":true, "methods":[{"name":"getDefaultDataSource","parameterTypes":[] }, {"name":"getTables","parameterTypes":[] }] @@ -1156,6 +1156,10 @@ "condition":{"typeReachable":"org.apache.shardingsphere.sqlfederation.optimizer.planner.util.SQLFederationPlannerUtils"}, "name":"org.apache.shardingsphere.sqlfederation.optimizer.planner.util.SQLFederationFunctionUtils" }, +{ + "condition":{"typeReachable":"org.apache.shardingsphere.sqlfederation.rule.SQLFederationMetaDataHeldRule"}, + "name":"org.apache.shardingsphere.sqlfederation.optimizer.planner.util.SQLFederationFunctionUtils" +}, { "condition":{"typeReachable":"org.apache.shardingsphere.sqlfederation.rule.SQLFederationRule"}, "name":"org.apache.shardingsphere.sqlfederation.optimizer.planner.util.SQLFederationFunctionUtils" @@ -1228,7 +1232,7 @@ "name":"org.apache.shardingsphere.transaction.yaml.config.YamlTransactionRuleConfiguration" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.transaction.yaml.swapper.NewYamlTransactionRuleConfigurationSwapper"}, + "condition":{"typeReachable":"org.apache.shardingsphere.transaction.yaml.swapper.YamlTransactionDataNodeRuleConfigurationSwapper"}, "name":"org.apache.shardingsphere.transaction.yaml.config.YamlTransactionRuleConfiguration", "allDeclaredFields":true, "methods":[{"name":"getDefaultType","parameterTypes":[] }, {"name":"getProps","parameterTypes":[] }, {"name":"getProviderType","parameterTypes":[] }] diff --git a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/resource-config.json b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/resource-config.json index fa5be0653ed29..5c1ba4cee229c 100644 --- a/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/resource-config.json +++ b/infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/resource-config.json @@ -4,16 +4,16 @@ "condition":{"typeReachable":"org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader"}, "pattern":".*META-INF/services/org\\.apache\\.shardingsphere\\..+" }, { - "condition":{"typeReachable":"org.apache.shardingsphere.infra.metadata.database.schema.builder.SystemSchemaBuilder"}, + "condition":{"typeReachable":"org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager"}, "pattern":".*schema/.+\\.yaml$" }, { "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader"}, "pattern":".*sql/.+\\.xml$" - }, { - "condition":{"typeReachable":"org.apache.shardingsphere.infra.state.datasource.DataSourceStateManager"}, - "pattern":"\\QMETA-INF/services/java.sql.Driver\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.infra.util.directory.ClasspathResourceDirectoryReader"}, + "pattern":"\\Qschema\\E" + }, { + "condition":{"typeReachable":"org.apache.shardingsphere.mode.repository.standalone.jdbc.sql.JDBCRepositorySQLLoader"}, "pattern":"\\Qsql\\E" }, { "condition":{"typeReachable":"org.apache.shardingsphere.transaction.xa.atomikos.manager.AtomikosTransactionManagerProvider"}, diff --git a/infra/session/src/main/java/org/apache/shardingsphere/infra/session/connection/transaction/TransactionConnectionContext.java b/infra/session/src/main/java/org/apache/shardingsphere/infra/session/connection/transaction/TransactionConnectionContext.java index c7f45b40bce81..411a0b15ae8f7 100644 --- a/infra/session/src/main/java/org/apache/shardingsphere/infra/session/connection/transaction/TransactionConnectionContext.java +++ b/infra/session/src/main/java/org/apache/shardingsphere/infra/session/connection/transaction/TransactionConnectionContext.java @@ -47,12 +47,12 @@ public void beginTransaction(final String transactionType) { } /** - * Judge is in XA transaction or not. + * Judge is in distributed transaction or not. * - * @return in XA transaction or not + * @return in distributed transaction or not */ - public boolean isInXATransaction() { - return inTransaction && "XA".equals(transactionType); + public boolean isInDistributedTransaction() { + return inTransaction && ("XA".equals(transactionType) || "BASE".equals(transactionType)); } @Override diff --git a/pom.xml b/pom.xml index 228aa37cfa2d3..4c8e62768a780 100644 --- a/pom.xml +++ b/pom.xml @@ -146,7 +146,7 @@ 1.4.13 4.0.0 1.6.2 - 0.10.0 + 0.10.1 1.0.0 diff --git a/test/native/native-image-filter/extra-filter.json b/test/native/native-image-filter/extra-filter.json index 197076d15ed76..8e02278f7db88 100644 --- a/test/native/native-image-filter/extra-filter.json +++ b/test/native/native-image-filter/extra-filter.json @@ -6,7 +6,6 @@ {"excludeClasses": "com.sun.org.apache.xerces.internal.jaxp.**"}, {"excludeClasses": "java.**"}, {"includeClasses": "java.lang.Boolean"}, - {"includeClasses": "java.lang.Thread"}, {"includeClasses": "java.util.Properties"}, {"excludeClasses": "javax.security.auth.x500.**"}, {"excludeClasses": "javax.smartcardio.**"}, diff --git a/test/native/native-image-filter/user-code-filter.json b/test/native/native-image-filter/user-code-filter.json index 61b0ffcec867b..ee8d1f69f9776 100644 --- a/test/native/native-image-filter/user-code-filter.json +++ b/test/native/native-image-filter/user-code-filter.json @@ -3,5 +3,7 @@ {"excludeClasses": "**"}, {"includeClasses": "org.apache.shardingsphere.**"}, {"excludeClasses": "org.apache.shardingsphere.test.natived.**"} + ], + "regexRules": [ ] }