开发者社区> 问答> 正文

seata 使用多线程测试时得到脏数据

当我使用多线程调用业务服务时,我在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

展开
收起
一人吃饱,全家不饿 2021-02-02 10:50:53 5675 0
来自:阿里开源
1 条回答
写回答
取消 提交回答
来源圈子
更多
收录在圈子:
+ 订阅
阿里巴巴相信开源的世界里人人贡献代码,人人获得收益,共同创造一个互帮互利的社区,促进技术进步和发展。
问答排行榜
最热
最新

相关电子书

更多
用AI 高效测试移动应用 立即下载
移动互联网测试到质量的转变 立即下载
给ITer的技术实战进阶课-阿里CIO学院独家教材(四) 立即下载