lirui-apache 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_r361436270
##########
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:
We're supposed to throw `InvalidProgramException` if the compilation fails
(`CompileUtilsTest::testWrongCode` verifies that). So we have to catch the
execution exceptions and check the cause.
----------------------------------------------------------------
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