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

Support SagaEnd Callback invocation

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • pack-0.7.0
    • Saga

    Description

      Here is the use case for using the lock to provide the isolation in Saga.
      We just want to release this lock after the saga invocation is finished. Here is the code snippet for it. method2 wraps the Saga event to release the lock.

      @SagaStart
      void doSagaTx() {
         doLocalTx1();
         doLocalTx1();
      }
      
      @Compensable(timeout=5, compensationMethod="cancelLocalTx1")
      void doLocalTx1(){
         ...
      }
      
      void cancelLocalTx1(){
         ....
      }
      
      @Compensable(timeout=5, compensationMethod="cancelLocalTx2")
      void doLocalTx2(){
         ...
      }
      
      void cancelLocalTx2(){
         ....
      }
      
      void method2() {
         Lock resourceLock = getResourceLock();
         if (resourceLock.tryLock()) {
          try {
      
              doSagaTx();
          } finally {
              resourceLock.release();
          }
         } else {
           // Resource was locked
         }
      }
      

      But, this method is not good enough, as if there are something wrong inside of the Saga transaction, we need to wait for a while to let the transaction coordinator to finish the compensation invocation before release the resource lock.
      If ServiceComb saga can provide a callback when the saga transaction is finished, it could save lots of my time. The code just like this.

      @SagaStart(endMethod="sagaTxEnd")
      void doSagaTx(resourceLock) {
         doLocalTx1();
         doLocalTx1();
      }
      
      void sagaTxEnd(resourceLock){
         resourceLock.release();
      }
      
      @Compensable(timeout=5, compensationMethod="cancelLocalTx1")
      void doLocalTx1(){
         ...
      }
      
      void cancelLocalTx1(){
         ....
      }
      
      @Compensable(timeout=5, compensationMethod="cancelLocalTx2")
      void doLocalTx2(){
         ...
      }
      
      void cancelLocalTx2(){
         ....
      }
      
      void method2() {
         Lock resourceLock = getResourceLock();
         if (resourceLock.tryLock()) {
          doSagaTx(resourceLock);
         } else {
           // Resource was locked
         }
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            njiang Willem Jiang
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: