[ 
https://issues.apache.org/jira/browse/SCB-1006?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16672470#comment-16672470
 ] 

Zheng Feng commented on SCB-1006:
---------------------------------

[~njiang] It looks like the coordinator will call the endMethod after all the 
compensations are OK and still hold the lock during the compensating time ? 
This could provide the isolate on the application level. But there is a 
deadlock risk when the coordinator fails to call the method due to the network 
error. It would be better if the lock is able to be timeout.

> 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
>            Priority: Major
>              Labels: improvement, pack
>
> 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)

Reply via email to