You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2018/09/11 10:39:48 UTC

[incubator-servicecomb-saga] 01/04: SCB-819 Only register the success participated event

This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch SCB-819
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-saga.git

commit 885a5f86190b00ae02cc26467a7792ce5a9b28ee
Author: Willem Jiang <ji...@huawei.com>
AuthorDate: Tue Sep 11 18:28:09 2018 +0800

    SCB-819 Only register the success participated event
---
 .../tcc/registry/TransactionEventRegistry.java     | 24 +++++++++++++---------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/registry/TransactionEventRegistry.java b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/registry/TransactionEventRegistry.java
index d135a8b..db60195 100644
--- a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/registry/TransactionEventRegistry.java
+++ b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/registry/TransactionEventRegistry.java
@@ -23,6 +23,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import org.apache.servicecomb.saga.alpha.server.tcc.event.ParticipatedEvent;
+import org.apache.servicecomb.saga.common.TransactionStatus;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -38,18 +39,21 @@ public final class TransactionEventRegistry {
   /**
    * Register participate event.
    *
-   * @param participateEvent participate event
+   * @param participatedEvent participated event
    */
-  public static void register(ParticipatedEvent participateEvent) {
-    REGISTRY
-        .computeIfAbsent(participateEvent.getGlobalTxId(), key -> new LinkedHashSet<>())
-        .add(participateEvent);
+  public static void register(ParticipatedEvent participatedEvent) {
+    // Only register the Succeed participatedEvent
+    if (TransactionStatus.Succeed.equals(participatedEvent.getStatus())) {
+      REGISTRY
+          .computeIfAbsent(participatedEvent.getGlobalTxId(), key -> new LinkedHashSet<>())
+          .add(participatedEvent);
 
-    LOG.info("Registered participated event, global tx: {}, local tx: {}, parent id: {}, "
-            + "confirm: {}, cancel: {}, status: {}, service [{}] instanceId [{}]",
-        participateEvent.getGlobalTxId(), participateEvent.getLocalTxId(), participateEvent.getParentTxId(),
-        participateEvent.getConfirmMethod(), participateEvent.getCancelMethod(), participateEvent.getStatus(),
-        participateEvent.getServiceName(), participateEvent.getInstanceId());
+      LOG.info("Registered participated event, global tx: {}, local tx: {}, parent id: {}, "
+              + "confirm: {}, cancel: {}, status: {}, service [{}] instanceId [{}]",
+          participatedEvent.getGlobalTxId(), participatedEvent.getLocalTxId(), participatedEvent.getParentTxId(),
+          participatedEvent.getConfirmMethod(), participatedEvent.getCancelMethod(), participatedEvent.getStatus(),
+          participatedEvent.getServiceName(), participatedEvent.getInstanceId());
+    }
   }
 
   /**