JingsongLi commented on a change in pull request #10620: 
[FLINK-15239][table-planner-blink] CompileUtils::COMPILED_CACHE leaks class 
loaders
URL: https://github.com/apache/flink/pull/10620#discussion_r361594049
 
 

 ##########
 File path: 
flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/generated/CompileUtils.java
 ##########
 @@ -59,14 +62,16 @@
         * @return  the compiled class
         */
        public static <T> Class<T> compile(ClassLoader cl, String name, String 
code) {
-               Tuple2<ClassLoader, String> cacheKey = Tuple2.of(cl, name);
-               Class<?> clazz = COMPILED_CACHE.getIfPresent(cacheKey);
-               if (clazz == null) {
-                       clazz = doCompile(cl, name, code);
-                       COMPILED_CACHE.put(cacheKey, clazz);
+               try {
+                       Cache<ClassLoader, Class> compiledClasses = 
COMPILED_CACHE.get(name,
+                                       () -> 
CacheBuilder.newBuilder().maximumSize(5).weakKeys().softValues().build());
+                       return compiledClasses.get(cl, () -> doCompile(cl, 
name, code));
+               } catch (ExecutionException | UncheckedExecutionException e) {
 
 Review comment:
   It is just nit suggestion.
   Because `ExecutionException` is an invalid exception, and it could/should be 
threw. This can simplify exception stack.
   You can take a look to: 
https://github.com/apache/flink/blob/4adf23d3b93c301b53f11f1c05a1aa6d37112d46/flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/taskmanager/AbstractTaskManagerFileHandler.java#L125
   It is an example. And there are some examples in Spark too.

----------------------------------------------------------------
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