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 04:00:57 UTC

[GitHub] takumiCX commented on a change in pull request #352: 修复CompositeOmegaCallback中的compensate方法可能会出现的并发异常

takumiCX commented on a change in pull request #352: 修复CompositeOmegaCallback中的compensate方法可能会出现的并发异常
URL: https://github.com/apache/servicecomb-pack/pull/352#discussion_r242020921
 
 

 ##########
 File path: alpha/alpha-core/src/main/java/org/apache/servicecomb/saga/alpha/core/CompositeOmegaCallback.java
 ##########
 @@ -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();
 
 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