vvysotskyi commented on a change in pull request #1822: DRILL-7317: Close 
ClassLoaders used for udf jars uploading when closing 
FunctionImplementationRegistry
URL: https://github.com/apache/drill/pull/1822#discussion_r300867399
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/registry/FunctionRegistryHolder.java
 ##########
 @@ -376,28 +377,78 @@ private void removeAllByJar(String jarName) {
       return;
     }
 
+    boolean isClosed  = false;
     for (Map.Entry<String, Queue<String>> functionEntry : jar.entrySet()) {
       final String function = functionEntry.getKey();
       Map<String, DrillFuncHolder> functionHolders = functions.get(function);
       Queue<String> functionSignatures = functionEntry.getValue();
-      for (Map.Entry<String, DrillFuncHolder> entry : 
functionHolders.entrySet()) {
-        if (functionSignatures.contains(entry.getKey())) {
-          ClassLoader classLoader = entry.getValue().getClassLoader();
-          if (classLoader instanceof AutoCloseable) {
-            try {
-              ((AutoCloseable) classLoader).close();
-            } catch (Exception e) {
-              logger.warn("Problem during closing class loader", e);
-            }
-          }
-          break;
-        }
-      }
+      // closes class loader only one time
+      isClosed = !isClosed && closeClassLoader(function, functionSignatures);
       functionHolders.keySet().removeAll(functionSignatures);
 
       if (functionHolders.isEmpty()) {
         functions.remove(function);
       }
     }
   }
+
+  @Override
+  public void close() {
+    try (@SuppressWarnings("unused") Closeable lock = writeLock.open()) {
+      jars.forEach((jarName, jar) -> {
+        if (!LocalFunctionRegistry.BUILT_IN.equals(jarName)) {
+          for (Map.Entry<String, Queue<String>> functionEntry : 
jar.entrySet()) {
+            if (closeClassLoader(functionEntry.getKey(), 
functionEntry.getValue())) {
+              // class loader is closed, iterates to another jar
+              break;
+            }
+          }
+        }
+      });
+
+      jars.clear();
 
 Review comment:
   Agree, reverted this change.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to