snehashisp commented on code in PR #16984:
URL: https://github.com/apache/kafka/pull/16984#discussion_r1873316820


##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/isolation/Plugins.java:
##########
@@ -240,6 +261,21 @@ public Runnable withClassLoader(ClassLoader classLoader, 
Runnable operation) {
         };
     }
 
+    public static LoaderSwap swapLoader(ClassLoader loader) {

Review Comment:
   Actually, there are classloader swaps required in transformations as well. I 
always wondered why separate plugins like connector and transformation, were 
running under the connectors class loader in workertasks. I guess up until now 
it would not cause issues as class loading would go via delegation to the 
correct class loader. But with versioned plugins the delegation would end up on 
the latest version of the plugin which can differ from the versioned plugin. 
That was my reasoning for introducing loader swaps under converters and 
transformations. The breath of places which required it led me to make it 
static for easy access. Also, I did not unnecessarily want to inject the entire 
plugin instance into those classes. 
   
   I think we would want to avoid the lookup cost of finding the classloader 
from the plugins instance every time and then swapping the loader, so we would 
need to maintain a set of extra class loader variables for each instance in the 
worker tasks and transformations. I was thinking of exposing a `safeLoaderSwap` 
java function like below and pass that on to the worker tasks and 
transformations.
   ```
   public Function<ClassLoader, LoaderSwap> safeLoaderSwapper() {
           return loader -> {
               if (!(loader instanceof PluginClassLoader)) {
                   loader = delegatingLoader;
               }
               return withClassLoader(loader);
           };
       }
   ```
   That way we don't have to keep track of each class loader. wdyt?



-- 
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-unsubscr...@kafka.apache.org

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

Reply via email to