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 2018/12/17 08:22:17 UTC

[GitHub] WillemJiang closed pull request #352: SCB-1081 current issue when Calling the compensation from CompositeOmegaCallback (#353)

WillemJiang closed pull request #352: SCB-1081 current issue when Calling the compensation from CompositeOmegaCallback (#353)
URL: https://github.com/apache/servicecomb-pack/pull/352
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/alpha/alpha-core/src/main/java/org/apache/servicecomb/saga/alpha/core/CompositeOmegaCallback.java b/alpha/alpha-core/src/main/java/org/apache/servicecomb/saga/alpha/core/CompositeOmegaCallback.java
index 54e78f7b..41069b7f 100644
--- a/alpha/alpha-core/src/main/java/org/apache/servicecomb/saga/alpha/core/CompositeOmegaCallback.java
+++ b/alpha/alpha-core/src/main/java/org/apache/servicecomb/saga/alpha/core/CompositeOmegaCallback.java
@@ -20,6 +20,8 @@
 import static java.util.Collections.emptyMap;
 
 import java.lang.invoke.MethodHandles;
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.Map;
 
 import org.slf4j.Logger;
@@ -37,14 +39,15 @@ public CompositeOmegaCallback(Map<String, Map<String, OmegaCallback>> callbacks)
   public void compensate(TxEvent event) {
     Map<String, OmegaCallback> serviceCallbacks = callbacks.getOrDefault(event.serviceName(), emptyMap());
 
-    if (serviceCallbacks.isEmpty()) {
-      throw new AlphaException("No such omega callback found for service " + event.serviceName());
-    }
-
     OmegaCallback omegaCallback = serviceCallbacks.get(event.instanceId());
     if (omegaCallback == null) {
       LOG.info("Cannot find the service with the instanceId {}, call the other instance.", event.instanceId());
-      omegaCallback = serviceCallbacks.values().iterator().next();
+
+      Iterator<OmegaCallback> iterator = new ArrayList<>(serviceCallbacks.values()).iterator();
+      if(iterator.hasNext()) omegaCallback=iterator.next();
+    }
+    if(omegaCallback==null){
+      throw new AlphaException("No such omega callback found for service " + event.serviceName());
     }
 
     try {


 

----------------------------------------------------------------
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