You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@servicecomb.apache.org by "Willem Jiang (JIRA)" <ji...@apache.org> on 2019/01/11 12:35:00 UTC
[jira] [Commented] (SCB-1006) Support SagaEnd Callback invocation
[ https://issues.apache.org/jira/browse/SCB-1006?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16740346#comment-16740346 ]
Willem Jiang commented on SCB-1006:
-----------------------------------
FYI, there are some idea[1] in the LRA.
[1]https://github.com/eclipse/microprofile-lra/issues/65
> 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)