seanyinx commented on a change in pull request #117: SCB-224 support retry 
sub-transaction
URL: 
https://github.com/apache/incubator-servicecomb-saga/pull/117#discussion_r163728483
 
 

 ##########
 File path: 
alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/SpringCommandRepository.java
 ##########
 @@ -48,25 +46,32 @@
   }
 
   @Override
-  public void saveCompensationCommands(String globalTxId) {
-    List<TxEvent> events = eventRepository
-        .findStartedEventsWithMatchingEndedButNotCompensatedEvents(globalTxId);
-
-    Map<String, Command> commands = new LinkedHashMap<>();
-
-    for (TxEvent event : events) {
-      commands.computeIfAbsent(event.localTxId(), k -> new Command(event));
-    }
-
-    for (Command command : commands.values()) {
-      log.info("Saving compensation command {}", command);
-      try {
-        commandRepository.save(command);
-      } catch (Exception e) {
-        log.warn("Failed to save some command {}", command);
+  public void saveCompensationCommands(TxEvent abortEvent) {
+    Optional<TxEvent> compensationStartedEvent =
+        eventRepository.findStartedEventWithLocalTxId(abortEvent.globalTxId(), 
abortEvent.parentTxId());
+
+    compensationStartedEvent.ifPresent(txEvent -> {
+      String retriesMethod = txEvent.retriesMethod();
+      long retried = retriedTimes(txEvent.globalTxId(), retriesMethod, 
txEvent.localTxId());
+
+      List<TxEvent> compensationEvents = createRetriesTxEvent(abortEvent.id(), 
txEvent);
+
+      if (txEvent.retries() < (retried + 1)) {
+        compensationEvents =
+            
eventRepository.findStartedEventsWithMatchingEndedButNotCompensatedEvents(txEvent.globalTxId());
       }
-      log.info("Saved compensation command {}", command);
-    }
+
+      compensationEvents.stream().map(Command::new)
 
 Review comment:
   there may be duplicate start events and they have to be filtered to avoid 
redundant compensation

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to