You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2019/01/08 01:20:34 UTC

[GitHub] WillemJiang commented on a change in pull request #77: add saga quick start

WillemJiang commented on a change in pull request #77:  add saga  quick start
URL: https://github.com/apache/servicecomb-docs/pull/77#discussion_r245851508
 
 

 ##########
 File path: saga-reference/zh_CN/quickstart.md
 ##########
 @@ -19,95 +20,45 @@ SagaEndedEvent 标志着saga事务请求的结束,不需要保存任何内容
 
 ## Demo中的Pack场景
 Pack中包含两个组件,即 alpha 和 omega。
-图中的三个服务,booking、car、hotel均为omega进程,且通过alpha协调。booking调用car与hotel,且omega像一个agent内嵌其中,负责:1)对网络请求进行拦截并向alpha上报事务事件 2)异常情况下根据alpha下发的指令执行相应的补偿操作。而alpha充当协调者的角色,主要负责1)对事务的事件进行持久化存储2)协调子事务的状态,使其得以最终与全局事务的状态保持一致。
+图中的三个服务,booking、car、hotel均为omega进程,且通过alpha协调。booking调用car与hotel,且omega像一个agent内嵌其中,负责:  
+1)对网络请求进行拦截并向alpha上报事务事件  
+2)异常情况下根据alpha下发的指令执行相应的补偿操作。而alpha充当协调者的角色,主要负责1)对事务的事件进行持久化存储  
+2)协调子事务的状态,使其得以最终与全局事务的状态保持一致  
+
+![成功场景](static_files/Working.png)
 
 成功场景下,全局事务事件SagaStartedEvent对应SagaEndedEvent ,每个子事务开始的事件TxStartedEvent都会有对应的结束事件TXEndedEvent。
+![异常场景](static_files/Exception.png)
 
-异常场景下,omega会向alpha上报中断事件TxAbortedEvent,然后alpha会向该全局事务的其它已完成的子事务发送补偿指令TxCompensatedEvent,确保最终所有的子事务要么都成功,要么都回滚。
+异常场景下,omega会向alpha上报中断事件TxAbortedEvent,然后alpha会向该全局事务的其它已成功的子事务(以完成TXEndedEvent)发送补偿指令TxCompensatedEvent,确保最终所有的子事务要么都成功,要么都回滚。
 
-## 全局事务执行过程
-   ```
-
-class SagaStartAnnotationProcessor {
-
-  private final OmegaContext omegaContext;
-  private final SagaMessageSender sender;
-
-  SagaStartAnnotationProcessor(OmegaContext omegaContext, SagaMessageSender sender) {
-    this.omegaContext = omegaContext;
-    this.sender = sender;
-  }
-
-  AlphaResponse preIntercept(int timeout) {
-    try {
-      return sender
-          .send(new SagaStartedEvent(omegaContext.globalTxId(), omegaContext.localTxId(), timeout));
-    } catch (OmegaException e) {
-      throw new TransactionalException(e.getMessage(), e.getCause());
-    }
-  }
-
-  void postIntercept(String parentTxId) {
-    AlphaResponse response = sender
-        .send(new SagaEndedEvent(omegaContext.globalTxId(), omegaContext.localTxId()));
-    if (response.aborted()) {
-      throw new OmegaException("transaction " + parentTxId + " is aborted");
-    }
-  }
-
-  void onError(String compensationMethod, Throwable throwable) {
-    String globalTxId = omegaContext.globalTxId();
-    sender.send(
-        new TxAbortedEvent(globalTxId, omegaContext.localTxId(), null, compensationMethod,
-            throwable));
-  }
-}
-   ```
+![超时场景](static_files/Timeout.png)
+
+超时场景下,已超时的事件会被alpha的定期扫描器检测出来,与此同时,该超时事务对应的全局事务也会被中断。
+
+如上所述,航班预订,租车和酒店预订可以并行处理。但是这样做会造成另一个问题:如果航班预订失败,而租车正在处理怎么办?我们不能一直等待租车服务回应, 因为不知道需要等多久。
 
 Review comment:
   如果租车没有完成,怎么会触发回滚呢?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services