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

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

commit ce71ab73ae80bc90ba59fe9b038f134fef9426b1
Author: Eric Lee <eric.lee....@gmail.com>
AuthorDate: Tue Apr 24 16:17:39 2018 +0800

    SCB-224 resolved rebase conflicts
    
    Signed-off-by: Eric Lee <eric.lee....@gmail.com>
---
 .../saga/alpha/core/TxConsistentService.java            | 17 +++--------------
 .../saga/alpha/core/TxConsistentServiceTest.java        | 13 +++++++++++++
 .../saga/alpha/server/TxEventEnvelopeRepository.java    |  2 +-
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git 
a/alpha/alpha-core/src/main/java/org/apache/servicecomb/saga/alpha/core/TxConsistentService.java
 
b/alpha/alpha-core/src/main/java/org/apache/servicecomb/saga/alpha/core/TxConsistentService.java
index 4382fd3..9a7f82b 100644
--- 
a/alpha/alpha-core/src/main/java/org/apache/servicecomb/saga/alpha/core/TxConsistentService.java
+++ 
b/alpha/alpha-core/src/main/java/org/apache/servicecomb/saga/alpha/core/TxConsistentService.java
@@ -23,7 +23,6 @@ import static 
org.apache.servicecomb.saga.common.EventType.TxStartedEvent;
 
 import java.lang.invoke.MethodHandles;
 import java.util.Arrays;
-import java.util.Date;
 import java.util.List;
 
 import org.slf4j.Logger;
@@ -41,22 +40,12 @@ public class TxConsistentService {
   }
 
   public boolean handle(TxEvent event) {
-    if (TxStartedEvent.name().equals(event.type()) && 
isGlobalTxAborted(event)) {
-      LOG.info("Sub-transaction rejected, because its parent with globalTxId 
{} was already aborted",
-          event.globalTxId());
+    if (types.contains(event.type()) && isGlobalTxAborted(event)) {
+      LOG.info("Transaction event {} rejected, because its parent with 
globalTxId {} was already aborted",
+          event.type(), event.globalTxId());
       return false;
     }
 
-    if (SagaEndedEvent.name().equals(event.type()) && 
!event.expiryTime().equals(new Date(TxEvent.MAX_TIMESTAMP))) {
-      // if we get the SagaEndedEvent and the expiryTime is not MAX_TIME, we 
need to check if it is timeout
-      if (eventRepository.findTimeoutEvents().stream()
-          .filter(txEvent -> txEvent.globalTxId().equals(event.globalTxId()))
-          .count() == 1) {
-        LOG.warn("Transaction {} is timeout and will be handled by the event 
scanner", event.globalTxId());
-        return false;
-      }
-    }
-
     eventRepository.save(event);
 
     return true;
diff --git 
a/alpha/alpha-core/src/test/java/org/apache/servicecomb/saga/alpha/core/TxConsistentServiceTest.java
 
b/alpha/alpha-core/src/test/java/org/apache/servicecomb/saga/alpha/core/TxConsistentServiceTest.java
index e80d5a8..8faf0e8 100644
--- 
a/alpha/alpha-core/src/test/java/org/apache/servicecomb/saga/alpha/core/TxConsistentServiceTest.java
+++ 
b/alpha/alpha-core/src/test/java/org/apache/servicecomb/saga/alpha/core/TxConsistentServiceTest.java
@@ -132,6 +132,19 @@ public class TxConsistentServiceTest {
     assertThat(events.size(), is(2));
   }
 
+  @Test
+  public void skipSagaEndedEvent_IfGlobalTxAlreadyFailed() {
+    String localTxId1 = UUID.randomUUID().toString();
+    events.add(eventOf(SagaStartedEvent, localTxId1));
+    events.add(eventOf(TxAbortedEvent, localTxId1));
+
+    TxEvent event = eventOf(SagaEndedEvent, localTxId1);
+
+    consistentService.handle(event);
+
+    assertThat(events.size(), is(2));
+  }
+
   private TxEvent newEvent(EventType eventType) {
     return new TxEvent(serviceName, instanceId, globalTxId, localTxId, 
parentTxId, eventType.name(), compensationMethod,
         payloads);
diff --git 
a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/TxEventEnvelopeRepository.java
 
b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/TxEventEnvelopeRepository.java
index 68e6233..6a8a263 100644
--- 
a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/TxEventEnvelopeRepository.java
+++ 
b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/TxEventEnvelopeRepository.java
@@ -72,7 +72,7 @@ interface TxEventEnvelopeRepository extends 
CrudRepository<TxEvent, Long> {
       + "  AND ( SELECT MIN(t1.retries) FROM TxEvent t1 "
       + "  WHERE t1.globalTxId = t.globalTxId "
       + "    AND t1.localTxId = t.localTxId "
-      + "    AND t1.type = 'TxStartedEvent' ) = 0 ")
+      + "    AND t1.type IN ('TxStartedEvent', 'SagaStartedEvent') ) = 0 ")
   List<TxEvent> findByEventGlobalTxIdAndEventType(String globalTxId, String 
type);
 
   @Query("SELECT t FROM TxEvent t "

-- 
To stop receiving notification emails like this one, please contact
ningji...@apache.org.

Reply via email to