You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2022/06/14 02:34:58 UTC

[GitHub] [kafka] C0urante commented on a diff in pull request #12281: KAFKA-13971: Fix atomicity violations caused by improper usage of ConcurrentHashMap - part2

C0urante commented on code in PR #12281:
URL: https://github.com/apache/kafka/pull/12281#discussion_r896319034


##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/DelegatingClassLoader.java:
##########
@@ -222,14 +222,10 @@ protected PluginClassLoader newPluginClassLoader(
     private <T> void addPlugins(Collection<PluginDesc<T>> plugins, ClassLoader loader) {
         for (PluginDesc<T> plugin : plugins) {
             String pluginClassName = plugin.className();
-            SortedMap<PluginDesc<?>, ClassLoader> inner = pluginLoaders.get(pluginClassName);
-            if (inner == null) {
-                inner = new TreeMap<>();
-                pluginLoaders.put(pluginClassName, inner);
-                // TODO: once versioning is enabled this line should be moved outside this if branch
+            pluginLoaders.computeIfAbsent(pluginClassName, k -> {

Review Comment:
   Is this actually done concurrently? I was under the impression that this logic was all handled on a single thread.
   
   The map may be a `ConcurrentMap` in order to ensure that we can have one writer and an arbitrary number of readers at a single time, which might come in handy if a class has static initialization logic that spawns other threads which in turn make implicit calls to `DelegatingClassLoader::loadClass`.



-- 
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: jira-unsubscribe@kafka.apache.org

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