shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

transactions not rolled back,

Open jie04baichi opened this issue 7 years ago • 4 comments

Bug Report

Which version of ShardingSphere did you use?

3.1.0.M1

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

Sharding-JDBC

Expected behavior

I am testing xa transactions, first i just use TransactionType.LOCAL ,the transaction should have been rolled back

Actual behavior

But The transaction cannot be rolled back,

Reason analyze (If you can)

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when

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

@Transactional(propagation=Propagation.REQUIRED, rollbackFor=Exception.class)
public int insertUser(UserInfo userInfo) throws Exception {
	
	TransactionTypeHolder.set(TransactionType.LOCAL);
	
    UserInfo userInfo1 = new UserInfo();
    int user_id = 45;
    for (int j = 0; j < 10; j++) {
        userInfo1.setAccount("Account" + j);
        userInfo1.setPassword("pass" + j);
        userInfo1.setUserName("name" + j);
        userInfo1.setCreateTime(new Date());
		userInfoMapper.insert(userInfo1);
        CommonInfo commonInfo = new CommonInfo();
        commonInfo.setId(j);
        commonInfo.setName("name " + j);
        
        commonInfoMapper.insert(commonInfo);
		if (j > 3) {
			throw new RuntimeException();
		}
	}
    return 0 ;
}

jie04baichi avatar Dec 26 '18 10:12 jie04baichi

If the following xa dependencies are not incloud, the transaction is normally rolled back.

	<dependency>
	    <groupId>io.shardingsphere</groupId>
	    <artifactId>sharding-transaction-2pc-xa</artifactId>
	    <version>${sharding-sphere.version}</version>
	</dependency>

jie04baichi avatar Dec 26 '18 10:12 jie04baichi

userInfoMapper is sharding, commonInfoMapper is not sharding. I found that only commonInfoMapper are not rolled back

jie04baichi avatar Dec 26 '18 10:12 jie04baichi

是要排除(exclude = JtaAutoConfiguration.class), 这个东西

jie04baichi avatar Dec 26 '18 11:12 jie04baichi

fixed at https://github.com/sharding-sphere/sharding-spring/pull/9

terrymanu avatar Dec 27 '18 10:12 terrymanu