You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/08/12 16:55:48 UTC

[GitHub] [shardingsphere] terrymanu edited a comment on issue #11307: Investigate mvn install failure

terrymanu edited a comment on issue #11307:
URL: https://github.com/apache/shardingsphere/issues/11307#issuecomment-897803147


   The problem is for thread safe in class OrderedSPIRegistry.
   
   When I add some log in the method:
   
   ```java
       /**
        * Get registered services.
        *
        * @param types types
        * @param orderedSPIClass class of ordered SPI
        * @param <K> type of key
        * @param <V> type of ordered SPI class
        * @param comparator comparator
        * @return registered services
        */
       @SuppressWarnings("unchecked")
       public static <K, V extends OrderedSPI<?>> Map<K, V> getRegisteredServices(final Collection<K> types, final Class<V> orderedSPIClass, final Comparator<Integer> comparator) {
           Optional<CachedOrderedServices> cachedServices = OrderedServicesCache.findCachedServices(types, orderedSPIClass);
           if (cachedServices.isPresent()) {
               Map<K, V> result = (Map<K, V>) cachedServices.get().getServices();
               if (types.size() == 2 && !result.isEmpty() && result.keySet().iterator().next().getClass().equals(SingleTableRuleBuilder.class)) {
                   System.out.println("from cache: types:" + types + "result: " + result);
               }
               return result;
           }
           Collection<V> registeredServices = getRegisteredServices(orderedSPIClass, comparator);
           Map<K, V> result = new LinkedHashMap<>(registeredServices.size(), 1);
           for (V each : registeredServices) {
               types.stream().filter(type -> each.getTypeClass() == type.getClass()).forEach(type -> result.put(type, each));
           }
           OrderedServicesCache.cacheServices(types, orderedSPIClass, result);
           return result;
       }
   ```
   
   The result form cache are error sometimes.
   
   The error log:
   
   ```
   from cache: 
   
   types:
   [org.apache.shardingsphere.infra.persist.rule.builder.DistMetaDataPersistRuleBuilder@21cf7d6c, org.apache.shardingsphere.authority.rule.builder.AuthorityRuleBuilder@14e57238]
   
   result: 
   {org.apache.shardingsphere.infra.rule.builder.single.SingleTableRuleBuilder@6015bb85=org.apache.shardingsphere.infra.rule.builder.single.DefaultSingleTableRuleConfigurationBuilder@602e976a}
   
   ```
   
   When using `DistMetaDataPersistRuleBuilder` and `AuthorityRuleBuilder` to get the builder, but return `SingleTableRuleBuilder`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org