lhotari commented on code in PR #21402:
URL: https://github.com/apache/pulsar/pull/21402#discussion_r1366514804
##########
pulsar-common/src/main/java/org/apache/pulsar/common/nar/NarClassLoader.java:
##########
@@ -135,24 +141,41 @@ public class NarClassLoader extends URLClassLoader {
* The NAR for which this <tt>ClassLoader</tt> is responsible.
*/
private final File narWorkingDirectory;
+ private final String narPath;
+ private final ClassLoader parentClassLoader;
+ private final AtomicInteger refCnt = new AtomicInteger(0);
private static final String TMP_DIR_PREFIX = "pulsar-nar";
public static final String DEFAULT_NAR_EXTRACTION_DIR =
System.getProperty("nar.extraction.tmpdir") != null
? System.getProperty("nar.extraction.tmpdir") :
System.getProperty("java.io.tmpdir");
- static NarClassLoader getFromArchive(File narPath, Set<String>
additionalJars, ClassLoader parent,
- String narExtractionDirectory)
- throws IOException {
- File unpacked = NarUnpacker.unpackNar(narPath,
getNarExtractionDirectory(narExtractionDirectory));
- return AccessController.doPrivileged(new
PrivilegedAction<NarClassLoader>() {
- @SneakyThrows
- @Override
- public NarClassLoader run() {
- return new NarClassLoader(unpacked, additionalJars, parent);
+ static NarClassLoader getFromArchive(File narFile, Set<String>
additionalJars, ClassLoader parent,
+ String narExtractionDirectory) {
+
+ final String cachedKey = classLoaderKey(narFile.getAbsolutePath(),
parent);
+ return CACHED_CLASS_LOADER.compute(cachedKey, (key, narClassLoader) ->
{
+ if (narClassLoader != null) {
+ return narClassLoader.retain();
+ }
+ try {
+ File unpacked = NarUnpacker.unpackNar(narFile,
getNarExtractionDirectory(narExtractionDirectory));
Review Comment:
I think that the cache key would need to contain the checksum/hash of the
nar file to work properly. Please check the unpacking logic to see how a hash
is currently calculated.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]