TeslaCN opened a new issue #14229:
URL: https://github.com/apache/shardingsphere/issues/14229
## Bug Report
### Which version of ShardingSphere did you use?
master - 1a9c35ef2d8b8a2d92c563cf1eabe0bd152cb41a
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-Proxy
### Expected behavior
Batch insert succeed.
### Actual behavior
Client logs:
```
Exception in thread "main" java.sql.BatchUpdateException: Batch entry 0
insert into t_order (user_id, order_time, order_value) values ('0', '2021-12-22
17:53:21.278+08',
'6HGUHCpWSIBMIljrWJqSVTjljTosLdWsBQiAev5NwnbriIuN7YerVKERXMDLxIRZR6zy5uv3zlOYoZNktk4NHYeSglRDEWsMZpeu')
was aborted: [127.0.0.1:48734/127.0.0.1:55433] ERROR: HikariPool-1 -
Connection is not available, request timed out after 3000ms. Call
getNextException to see other errors in the batch.
at
org.opengauss.jdbc.BatchResultHandler.handleCompletion(BatchResultHandler.java:166)
at
org.opengauss.core.v3.QueryExecutorImpl.executeBatch(QueryExecutorImpl.java:578)
at org.opengauss.jdbc.PgStatement.executeBatch(PgStatement.java:865)
at
org.opengauss.jdbc.PgPreparedStatement.executeBatch(PgPreparedStatement.java:1566)
at icu.wwj.hello.jdbc.opengauss.BatchBind.main(BatchBind.java:28)
Caused by: org.opengauss.util.PSQLException:
[127.0.0.1:48734/127.0.0.1:55433] ERROR: HikariPool-1 - Connection is not
available, request timed out after 3000ms.
at
org.opengauss.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2820)
at
org.opengauss.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2550)
at
org.opengauss.core.v3.QueryExecutorImpl.executeBatch(QueryExecutorImpl.java:564)
... 3 more
```
Proxy logs:
```
[ERROR] 2021-12-22 17:53:24.968 [Connection-1-ThreadExecutor]
o.a.s.p.f.c.CommandExecutorTask - Exception occur:
java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not
available, request timed out after 3000ms.
at
com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:689)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:196)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:161)
at
com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:100)
at
org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCBackendDataSource.createConnection(JDBCBackendDataSource.java:103)
at
org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCBackendDataSource.getConnections(JDBCBackendDataSource.java:73)
at
org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCBackendDataSource.getConnections(JDBCBackendDataSource.java:53)
at
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection.getConnectionsWithoutTransaction(JDBCBackendConnection.java:134)
at
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.JDBCBackendConnection.getConnections(JDBCBackendConnection.java:95)
at
org.apache.shardingsphere.infra.executor.sql.prepare.driver.DriverExecutionPrepareEngine.group(DriverExecutionPrepareEngine.java:86)
at
org.apache.shardingsphere.infra.executor.sql.prepare.AbstractExecutionPrepareEngine.prepare(AbstractExecutionPrepareEngine.java:68)
at
org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.useDriverToExecute(ProxySQLExecutor.java:147)
at
org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.execute(ProxySQLExecutor.java:124)
at
org.apache.shardingsphere.proxy.backend.communication.ProxySQLExecutor.execute(ProxySQLExecutor.java:116)
at
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine.doExecute(DatabaseCommunicationEngine.java:196)
at
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine.execute(DatabaseCommunicationEngine.java:161)
at
org.apache.shardingsphere.proxy.frontend.opengauss.command.query.extended.bind.OpenGaussComBatchBindExecutor.execute(OpenGaussComBatchBindExecutor.java:75)
at
org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:96)
at
org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:69)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
```
### Reason analyze (If you can)
When without transaction, connections will be get from DataSource everytime.
https://github.com/apache/shardingsphere/blob/1a9c35ef2d8b8a2d92c563cf1eabe0bd152cb41a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/JDBCBackendConnection.java#L132-L139
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule
configuration, when exception occur etc.
config-sharding.yaml
```yaml
schemaName: sharding_db
dataSources:
ds_0:
url: jdbc:opengauss://127.0.0.1:5433/demo_ds_0
username: gaussdb
password: P@ssw0rd
connectionTimeoutMilliseconds: 3000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 16
minPoolSize: 1
ds_1:
url: jdbc:opengauss://127.0.0.1:5433/demo_ds_1
username: gaussdb
password: P@ssw0rd
connectionTimeoutMilliseconds: 3000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 16
minPoolSize: 1
rules:
- !SHARDING
tables:
t_order:
actualDataNodes: ds_${0..1}.t_order_${0..1}
tableStrategy:
standard:
shardingColumn: order_id
shardingAlgorithmName: t_order_inline
keyGenerateStrategy:
column: order_id
keyGeneratorName: snowflake
defaultDatabaseStrategy:
standard:
shardingColumn: user_id
shardingAlgorithmName: database_inline
defaultTableStrategy:
none:
shardingAlgorithms:
database_inline:
type: INLINE
props:
algorithm-expression: ds_${user_id % 2}
t_order_inline:
type: INLINE
props:
algorithm-expression: t_order_${order_id % 2}
keyGenerators:
snowflake:
type: SNOWFLAKE
props:
worker-id: 123
```
### Example codes for reproduce this issue (such as a github link).
```java
Connection connection =
DriverManager.getConnection("jdbc:opengauss://127.0.0.1:3307/sharding_db",
"User", "Password");
Statement statement = connection.createStatement();
statement.executeUpdate("drop table if exists t_order");
statement.executeUpdate(
"create table t_order (order_id bigint primary key, user_id
bigint not null, order_time timestamp not null, order_value varchar not null)");
PreparedStatement preparedStatement =
connection.prepareStatement("insert into t_order (user_id, order_time,
order_value) values (?, ?, ?)");
int rows = 1000;
for (int i = 0; i < rows; i++) {
preparedStatement.setLong(1, i);
preparedStatement.setTimestamp(2, new
Timestamp(System.currentTimeMillis()));
preparedStatement.setString(3,
RandomStringUtils.randomAlphanumeric(100));
preparedStatement.addBatch();
}
preparedStatement.executeBatch();
try (ResultSet resultSet = statement.executeQuery("select count(*)
from t_order")) {
if (!resultSet.next() || rows != resultSet.getInt(1)) {
throw new RuntimeException("Batch insertion failed.");
}
}
statement.executeUpdate("drop table t_order");
preparedStatement.close();
statement.close();
connection.close();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]