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

Operation not allowed after ResultSet closed when using SQLFederationEngine #33363

Open
wjjboy opened this issue Oct 23, 2024 · 5 comments
Open

Comments

@wjjboy
Copy link

wjjboy commented Oct 23, 2024

Bug Report

Which version of ShardingSphere did you use?

5.5.0 & 5.5.1

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-JDBC

Expected behavior

Federation SQL executes correctly during concurrent queries

Actual behavior

Federation SQL executes one by one is correctly, but three query one time Exception occurs.
Exception Trace Message:
More details: java.sql.SQLException: Operation not allowed after ResultSet closed at org.apache.shardingsphere.infra.exception.core.external.sql.ShardingSphereSQLException.toSQLException(ShardingSphereSQLException.java:81) ~[shardingsphere-infra-exception-core-5.5.1.jar!/:5.5.1] at org.apache.shardingsphere.infra.exception.dialect.SQLExceptionTransformEngine.toSQLException(SQLExceptionTransformEngine.java:54) ~[shardingsphere-infra-exception-dialect-core-5.5.1.jar!/:5.5.1] at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.executeQuery(ShardingSpherePreparedStatement.java:192) ~[shardingsphere-jdbc-5.5.1.jar!/:5.5.1] at xxx.ShardingRepository.executeQuery(NodeShardingRepository.java:228) ... 109 common frames omitted Caused by: java.sql.SQLException: Operation not allowed after ResultSet closed at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965) ~[mysql-connector-java-5.1.49.jar!/:5.1.49] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898) ~[mysql-connector-java-5.1.49.jar!/:5.1.49] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887) ~[mysql-connector-java-5.1.49.jar!/:5.1.49] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861) ~[mysql-connector-java-5.1.49.jar!/:5.1.49] at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:733) ~[mysql-connector-java-5.1.49.jar!/:5.1.49] at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:6279) ~[mysql-connector-java-5.1.49.jar!/:5.1.49] at com.zaxxer.hikari.pool.HikariProxyResultSet.next(HikariProxyResultSet.java) ~[HikariCP-4.0.3.jar!/:na] at org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.stream.JDBCStreamQueryResult.next(JDBCStreamQueryResult.java:54) ~[shardingsphere-infra-executor-5.5.1.jar!/:5.5.1] at org.apache.shardingsphere.sharding.merge.common.IteratorStreamMergedResult.next(IteratorStreamMergedResult.java:41) ~[shardingsphere-sharding-core-5.5.1.jar!/:5.5.1] at org.apache.shardingsphere.sqlfederation.executor.enumerator.JDBCRowEnumerator.moveNext0(JDBCRowEnumerator.java:60) ~[shardingsphere-sql-federation-executor-5.5.1.jar!/:5.5.1] at org.apache.shardingsphere.sqlfederation.executor.enumerator.JDBCRowEnumerator.moveNext(JDBCRowEnumerator.java:56) ~[shardingsphere-sql-federation-executor-5.5.1.jar!/:5.5.1] at org.apache.calcite.linq4j.EnumerableDefaults.groupBy_(EnumerableDefaults.java:979) ~[calcite-linq4j-1.35.0.jar!/:1.35.0] at org.apache.calcite.linq4j.EnumerableDefaults.groupBy(EnumerableDefaults.java:781) ~[calcite-linq4j-1.35.0.jar!/:1.35.0] at org.apache.calcite.linq4j.DefaultEnumerable.groupBy(DefaultEnumerable.java:311) ~[calcite-linq4j-1.35.0.jar!/:1.35.0] at Baz.bind(Unknown Source) ~[na:na] at org.apache.shardingsphere.sqlfederation.engine.SQLFederationEngine.executePlan(SQLFederationEngine.java:236) ~[shardingsphere-sql-federation-core-5.5.1.jar!/:5.5.1] at org.apache.shardingsphere.sqlfederation.engine.SQLFederationEngine.executeQuery(SQLFederationEngine.java:209) ~[shardingsphere-sql-federation-core-5.5.1.jar!/:5.5.1] at org.apache.shardingsphere.driver.executor.engine.DriverExecuteQueryExecutor.executeQuery(DriverExecuteQueryExecutor.java:85) ~[shardingsphere-jdbc-5.5.1.jar!/:5.5.1] at org.apache.shardingsphere.driver.executor.engine.facade.standard.StandardDriverExecutorFacade.executeQuery(StandardDriverExecutorFacade.java:94) ~[shardingsphere-jdbc-5.5.1.jar!/:5.5.1] at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.executeQuery(ShardingSpherePreparedStatement.java:183) ~[shardingsphere-jdbc-5.5.1.jar!/:5.5.1] ... 110 common frames omitted

Reason analyze (If you can)

the HikariProxyResultSet is closed by other thread?

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

Use SpringBoot + ShardingSphere-JDBC + Hikari + Mysql

the DataSource is like below:
`
// federation
CacheOption executionPlanCache = new CacheOption(1024, 65535L);

    SQLFederationRuleConfiguration federationRuleConfiguration = new SQLFederationRuleConfiguration(true, false, executionPlanCache);

    // config
    Collection<RuleConfiguration> ruleConfigs = Lists.newArrayList();

    ruleConfigs.add(shardingRuleConfig);

    ruleConfigs.add(federationRuleConfiguration);

    // 构建属性配置

    Properties properties = new Properties();

    properties.setProperty("sql-show", "true");

    properties.setProperty("max-connections-size-per-query", "1");

    return ShardingSphereDataSourceFactory.createDataSource(DATABASE_NAME, null, dataSourceMap, ruleConfigs, properties);

`

There has 3DB:
Table A stored in DB1.A
Table B stored in DB2.B DB3.B

We need sql like this:
select t1.id, t2.name, t1.num from ( select id, count(*) as num from B group B.id ) t1 left join ( select id, name from A ) t2 on t1.id = t2.id

Example codes for reproduce this issue (such as a github link).

@strongduanmu
Copy link
Member

Hi @wjjboy, thank you for your feedback. Can you provide a demo to help reproduce this exception?

@wjjboy
Copy link
Author

wjjboy commented Oct 23, 2024

Hi @wjjboy, thank you for your feedback. Can you provide a demo to help reproduce this exception?

I will attached later

@wjjboy
Copy link
Author

wjjboy commented Oct 24, 2024

Hi @wjjboy, thank you for your feedback. Can you provide a demo to help reproduce this exception?

Demo is in https://github.com/wjjboy/ShardingSphereTest.git

you should modify ShardingRepository.java for mysql username and password, and the db init sql is in resources dir.

The one by one test is in FederationSuccessTest,
The concurrent test is in FederationExceptionTest.

@strongduanmu
Copy link
Member

@wjjboy Thank you, I will test it recently.

@strongduanmu strongduanmu self-assigned this Oct 25, 2024
@wjjboy
Copy link
Author

wjjboy commented Oct 28, 2024

@strongduanmu Hi, any updates on this issue?

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

No branches or pull requests

2 participants