You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/08/18 13:24:17 UTC

[GitHub] [shardingsphere] jackie007zzc opened a new issue #6919: the 'autoCommit' of ShardingConnection do not support

jackie007zzc opened a new issue #6919:
URL: https://github.com/apache/shardingsphere/issues/6919


   i use shardingsphere+mybatis+spring
   
   i want to use autocommit property that configed in the config file,but DataSourceTransactionManager use the autocommit property from the ShardingConnection in the method of doBegin,therefore  we can not use the customized autocommit property from the dataSourceMap in the ShardingConnection
   
   DataSourceTransactionManager doBegin
   @Override
   	protected void doBegin(Object transaction, TransactionDefinition definition) {
   		DataSourceTransactionObject txObject = (DataSourceTransactionObject) transaction;
   		Connection con = null;
   
   		try {
   			if (txObject.getConnectionHolder() == null ||
   					txObject.getConnectionHolder().isSynchronizedWithTransaction()) {
   				Connection newCon = this.dataSource.getConnection();
   				if (logger.isDebugEnabled()) {
   					logger.debug("Acquired Connection [" + newCon + "] for JDBC transaction");
   				}
   				txObject.setConnectionHolder(new ConnectionHolder(newCon), true);
   			}
   
   			txObject.getConnectionHolder().setSynchronizedWithTransaction(true);
   			con = txObject.getConnectionHolder().getConnection();
   
   			Integer previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(con, definition);
   			txObject.setPreviousIsolationLevel(previousIsolationLevel);
   
   			// Switch to manual commit if necessary. This is very expensive in some JDBC drivers,
   			// so we don't want to do it unnecessarily (for example if we've explicitly
   			// configured the connection pool to set it already).
   			if (con.getAutoCommit()) {
   				txObject.setMustRestoreAutoCommit(true);
   				if (logger.isDebugEnabled()) {
   					logger.debug("Switching JDBC Connection [" + con + "] to manual commit");
   				}
   				con.setAutoCommit(false);
   			}
   
   			prepareTransactionalConnection(con, definition);
   			txObject.getConnectionHolder().setTransactionActive(true);
   
   			int timeout = determineTimeout(definition);
   			if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
   				txObject.getConnectionHolder().setTimeoutInSeconds(timeout);
   			}
   
   			// Bind the connection holder to the thread.
   			if (txObject.isNewConnectionHolder()) {
   				TransactionSynchronizationManager.bindResource(getDataSource(), txObject.getConnectionHolder());
   			}
   		}
   
   		catch (Throwable ex) {
   			if (txObject.isNewConnectionHolder()) {
   				DataSourceUtils.releaseConnection(con, this.dataSource);
   				txObject.setConnectionHolder(null, false);
   			}
   			throw new CannotCreateTransactionException("Could not open JDBC Connection for transaction", ex);
   		}
   	}
   
   
   ShardingConnection
   private final Map<String, DataSource> dataSourceMap;
   
   AbstractConnectionAdapter
   private boolean autoCommit = true;


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] haocao commented on issue #6919: the 'autoCommit' of ShardingConnection do not support

Posted by GitBox <gi...@apache.org>.
haocao commented on issue #6919:
URL: https://github.com/apache/shardingsphere/issues/6919#issuecomment-675888536


   The problem is org.springframework.jdbc.datasource.DataSourceTransactionManager using ShardingConnection's autoCommit to justify, but not the actual datasource's auto-commit.
   ![image](https://user-images.githubusercontent.com/687732/90602009-9e911200-e22b-11ea-9868-f0a9c5ec5534.png)
   
   
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] jackie007zzc commented on issue #6919: the 'autoCommit' of ShardingConnection do not support

Posted by GitBox <gi...@apache.org>.
jackie007zzc commented on issue #6919:
URL: https://github.com/apache/shardingsphere/issues/6919#issuecomment-675809767


   > @jackie007zzc
   > 
   > Thx to report the issue!
   > could you provide the config file and version of shardingsphere?
   
   spring.shardingsphere.datasource.accounts_0_master.type: com.zaxxer.hikari.HikariDataSource
   spring.shardingsphere.datasource.accounts_0_master.jdbc-url: ****
   spring.shardingsphere.datasource.accounts_0_master.username: ****
   spring.shardingsphere.datasource.accounts_0_master.password: ****
   spring.shardingsphere.datasource.accounts_0_master.minimum-idle: 10
   spring.shardingsphere.datasource.accounts_0_master.maximum-pool-size: 40
   spring.shardingsphere.datasource.accounts_0_master.auto-commit: false
   
   spring.shardingsphere.datasource.accounts_1_master.type: com.zaxxer.hikari.HikariDataSource
   spring.shardingsphere.datasource.accounts_1_master.jdbc-url: ****
   spring.shardingsphere.datasource.accounts_1_master.username: ****
   spring.shardingsphere.datasource.accounts_1_master.password: ****
   spring.shardingsphere.datasource.accounts_1_master.minimum-idle: 10
   spring.shardingsphere.datasource.accounts_1_master.maximum-pool-size: 40
   spring.shardingsphere.datasource.accounts_1_master.auto-commit: false
   
   
   and the version of shardingsphere is 4.0.3-RC-6


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] jackie007zzc edited a comment on issue #6919: the 'autoCommit' of ShardingConnection do not support

Posted by GitBox <gi...@apache.org>.
jackie007zzc edited a comment on issue #6919:
URL: https://github.com/apache/shardingsphere/issues/6919#issuecomment-675809767


   > @jackie007zzc
   > 
   > Thx to report the issue!
   > could you provide the config file and version of shardingsphere?
   
   spring.shardingsphere.datasource.accounts_0_master.type: com.zaxxer.hikari.HikariDataSource
   spring.shardingsphere.datasource.accounts_0_master.jdbc-url: ****
   spring.shardingsphere.datasource.accounts_0_master.username: ****
   spring.shardingsphere.datasource.accounts_0_master.password: ****
   spring.shardingsphere.datasource.accounts_0_master.minimum-idle: 10
   spring.shardingsphere.datasource.accounts_0_master.maximum-pool-size: 40
   spring.shardingsphere.datasource.accounts_0_master.auto-commit: false
   
   spring.shardingsphere.datasource.accounts_1_master.type: com.zaxxer.hikari.HikariDataSource
   spring.shardingsphere.datasource.accounts_1_master.jdbc-url: ****
   spring.shardingsphere.datasource.accounts_1_master.username: ****
   spring.shardingsphere.datasource.accounts_1_master.password: ****
   spring.shardingsphere.datasource.accounts_1_master.minimum-idle: 10
   spring.shardingsphere.datasource.accounts_1_master.maximum-pool-size: 40
   spring.shardingsphere.datasource.accounts_1_master.auto-commit: false
   
   
   and the version of shardingsphere is 4.0.2


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] jackie007zzc closed issue #6919: the 'autoCommit' of ShardingConnection do not support

Posted by GitBox <gi...@apache.org>.
jackie007zzc closed issue #6919:
URL: https://github.com/apache/shardingsphere/issues/6919


   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] haocao commented on issue #6919: the 'autoCommit' of ShardingConnection do not support

Posted by GitBox <gi...@apache.org>.
haocao commented on issue #6919:
URL: https://github.com/apache/shardingsphere/issues/6919#issuecomment-677302616


   I think this issue could be closed, one possible solution is to add autoCommit into HintManager, and use it to change ShardingConnection's autoCommit.


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] fantacy2001 commented on issue #6919: the 'autoCommit' of ShardingConnection do not support

Posted by GitBox <gi...@apache.org>.
fantacy2001 commented on issue #6919:
URL: https://github.com/apache/shardingsphere/issues/6919#issuecomment-675808052


   It's similar to my question,#6913。
   Many single update operations do not add transactions,I want to know how to solve this problem. 


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] wcsoft commented on issue #6919: the 'autoCommit' of ShardingConnection do not support

Posted by GitBox <gi...@apache.org>.
wcsoft commented on issue #6919:
URL: https://github.com/apache/shardingsphere/issues/6919#issuecomment-675507211


   @jackie007zzc 
   
   Thx to report the issue!
   could you provide the config file and version of shardingsphere?


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org