Uploaded image for project: 'Apache ServiceComb'
  1. Apache ServiceComb
  2. SCB-785

Cannot get the GlobalTxId and LocalTxId in the compensation method

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: saga-0.2.0
    • Fix Version/s: pack-0.3.0, saga-0.2.1
    • Component/s: Saga
    • Labels:
      None

      Description

      补偿方法里无法获取分布式事务的全局事务ID及本地事务ID

      因为在子事务业务处理方法中会将一部分中间数据存入外部缓存中,对应的补偿方法将可以通过这些中间数据进行合理的补偿操作,当时存入中间数据时会附带上globalTxId, localTxId,后面将根据这个查找到之前存入的中间数据。但发现在业务方法中可以获取分布式事务的全局事务ID及本地事务ID,但对应的补偿方法里却不行。

      Customer may want to access the globalTxId and LocalTxId in application to store these information into DB for the recovery.

      示例代码如下:

       

      @Autowired
      OmegaContext omegaContext;
      
      @Compensable(timeout=5, compensationMethod="cancel")
      public boolean transferOut(String from, int amount) {
        // 这里可以获得
        System.out.println(omegaContext.globalTxId());
        System.out.println(omegaContext.localTxId());
        repo.reduceBalanceByUsername(from, amount);
      }
      
      public boolean cancel(String from, int amount) {
        // 这里不可以获得
        System.out.println(omegaContext.globalTxId());
        System.out.println(omegaContext.localTxId());
        repo.addBalanceByUsername(from, amount);
      }
      

       

        Attachments

          Activity

            People

            • Assignee:
              njiang Willem Jiang
              Reporter:
              jeremyxu Jeremy Xu
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: