azexcy opened a new issue, #20876:
URL: https://github.com/apache/shardingsphere/issues/20876

   ## Bug Report
   
   I use jdbc mode to create Sharding ShardingSphereDataSource, finally the 
`H2JDBCRepositoryProvider` will be used.
   If multiple threads at about the same time execute `JDBCRepository.init`
   
   related code
   ```
       @Override
       public void init(final Properties props) {
           JDBCRepositoryProperties jdbcRepositoryProps = new 
JDBCRepositoryProperties(props);
           hikariDataSource = new HikariDataSource();
           
hikariDataSource.setJdbcUrl(jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.JDBC_URL));
           
hikariDataSource.setUsername(jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.USERNAME));
           
hikariDataSource.setPassword(jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.PASSWORD));
           try (
                   Connection connection = hikariDataSource.getConnection();
                   Statement statement = connection.createStatement()) {
               provider = 
JDBCRepositoryProviderFactory.getInstance(jdbcRepositoryProps.getValue(JDBCRepositoryPropertyKey.PROVIDER));
               statement.execute(provider.dropTableSQL());
               statement.execute(provider.createTableSQL());
           }
       }
   ```
   
   the `provider.dropTableSQL()` may cause deadlock exception, and failed to 
get data source
   
   ```
   Caused by: org.h2.jdbc.JdbcSQLTransactionRollbackException: Deadlock 
detected. The current transaction was rolled back. Details: "\000aSession #2 
(user: SA, RUNNING) on thread Thread-9 is waiting to lock PUBLIC.repository 
(exclusive) while locking PUBLIC.SYS (exclusive).\000aSession #3 (user: SA, 
RUNNING) on thread Thread-10 is waiting to lock PUBLIC.SYS (exclusive) while 
locking PUBLIC.repository (exclusive)."; SQL statement: DROP TABLE IF EXISTS 
`repository` [40001-214]
   ```
   
   relation ci link:
   > 
https://github.com/apache/shardingsphere/runs/8242175967?check_suite_focus=true
   
https://github.com/apache/shardingsphere/runs/8226074983?check_suite_focus=true
   
   ### Which version of ShardingSphere did you use?
   
   master
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   
   ShardingSphere-Proxy
   
   ### Expected behavior
   
   Succeed to get data source
   
   ### Actual behavior
   
   Exception thrown and failed to get data source
   
   ### Reason analyze (If you can)
   
   http://www.h2database.com/html/advanced.html
   
   drop table may get exclusive lock,  add jdbc param or add lock?
   > I'm not sure, maybe there is a better way
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   
   ### Example codes for reproduce this issue (such as a github link).
   


-- 
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]

Reply via email to