Willem Jiang created SCB-1006: --------------------------------- Summary: Support SagaEnd Callback invocation Key: SCB-1006 URL: https://issues.apache.org/jira/browse/SCB-1006 Project: Apache ServiceComb Issue Type: Improvement Components: Saga Reporter: Willem Jiang
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. {code} @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 } } {code} 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. {code} @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 } } {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)