Skip to content

Commit

Permalink
DRILL-7317: Close ClassLoaders used for udf jars uploading when closi…
Browse files Browse the repository at this point in the history
…ng FunctionImplementationRegistry
  • Loading branch information
vvysotskyi committed Jul 5, 2019
1 parent 74b277d commit 1f10fa1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Expand Up @@ -455,7 +455,7 @@ private ScanResult scan(ClassLoader classLoader, Path path, URL[] urls) throws I
return RunTimeScan.dynamicPackageScan(drillConfig, Sets.newHashSet(urls));
} finally {
if (markerFileConnection instanceof JarURLConnection) {
((JarURLConnection) markerFile.openConnection()).getJarFile().close();
((JarURLConnection) markerFileConnection).getJarFile().close();
}
}
}
Expand Down Expand Up @@ -592,6 +592,7 @@ private void deleteQuietlyLocalJar(Path jar) {
*/
@Override
public void close() {
localFunctionRegistry.close();
if (deleteTmpDir) {
FileUtils.deleteQuietly(tmpDir);
} else {
Expand Down
Expand Up @@ -151,6 +151,20 @@ public void removeJar(String jarName) {
}
}

/**
* Removes all jars from {@link #jars} map and all associated with jars functions
* from {@link #functions}.
* This is write operation, so one user at a time can call perform such action,
* others will wait till first user completes his action.
*/
public void removeAllJars() {
try (@SuppressWarnings("unused") Closeable lock = writeLock.open()) {
jars.keySet().stream()
.filter(jarName -> !jarName.equals(LocalFunctionRegistry.BUILT_IN))
.forEach(this::removeAllByJar);
}
}

/**
* Retrieves list of all jars name present in {@link #jars}
* This is read operation, so several users can get this data.
Expand Down
Expand Up @@ -53,7 +53,7 @@
/**
* Registry of Drill functions.
*/
public class LocalFunctionRegistry {
public class LocalFunctionRegistry implements AutoCloseable {

public static final String BUILT_IN = "built-in";

Expand Down Expand Up @@ -356,4 +356,10 @@ private void registerOperatorsWithoutInference(DrillOperatorTable operatorTable,
}
}
}

@Override
public void close() {
// unregisters all jars to close ClassLoader used for jar uploading
registryHolder.removeAllJars();
}
}

0 comments on commit 1f10fa1

Please sign in to comment.