当我使用多线程调用业务服务时,我在undo_log中得到了脏数据并且无法回滚。
测试代码如下:
ExecutorService executorService = Executors.newFixedThreadPool(8);
for (int i = 0; i < 1000; i++) {
executorService.submit(() -> {
business.purchase("U100001", "C00321", 1, isRollback());
});
}
boolean isRollback() {
int r = ThreadLocalRandom.current().nextInt(100);
return r < 10;
}
And the purchase function
@Override
@GlobalTransactional(timeoutMills = 300000, name = "dubbo-demo-tx")
public void purchase(String userId, String commodityCode, int orderCount, boolean isRollback) {
LOGGER.info("purchase begin ... xid: " + RootContext.getXID());
storageService.deduct(commodityCode, orderCount);
orderService.create(userId, commodityCode, orderCount);
if (isRollback) {
throw new RuntimeException("xxx");
}
}
回滚报错
[INFO ] 2019-09-26 16:45:35,445 method:io.seata.rm.datasource.undo.AbstractUndoExecutor.dataValidationAndGoOn(AbstractUndoExecutor.java:225)
Field not equals, name count, old value 9957, new value 9968
[DEBUG] 2019-09-26 16:45:35,445 method:io.seata.rm.datasource.undo.AbstractUndoExecutor.dataValidationAndGoOn(AbstractUndoExecutor.java:229)
check dirty datas failed, old and new data are not equal,tableName:[storage_tbl],oldRows:[[{"fields":[{"keyType":"PrimaryKey","name":"id","type":4,"value":20},{"keyType":"NULL","name":"count","type":4,"value":9957}]}]],newRows:[[{"fields":[{"keyType":"PrimaryKey","name":"id","type":4,"value":20},{"keyType":"NULL","name":"commodity_code","type":12,"value":"C00321"},{"keyType":"NULL","name":"count","type":4,"value":9968}]}]].
[INFO ] 2019-09-26 16:45:35,449 method:io.seata.rm.datasource.DataSourceManager.branchRollback(DataSourceManager.java:182)
branchRollback failed reason [Branch session rollback failed and try again later xid = 10.0.75.1:8091:2023216781 branchId = 2023217051 Has dirty records when undo.]
[INFO ] 2019-09-26 16:45:35,449 method:io.seata.rm.AbstractRMHandler.doBranchRollback(AbstractRMHandler.java:130)
Branch Rollbacked result: PhaseTwo_RollbackFailed_Retryable
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。