seata 使用多线程测试时得到脏数据 -问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

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

一人吃饱,全家不饿 2021-02-02 10:50:53 382

当我使用多线程调用业务服务时,我在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
分享到
取消 提交回答
全部回答(1)
+ 订阅

我们开放源码,更相信社区的力量。

推荐文章
相似问题
链接