tillrohrmann commented on a change in pull request #12446: URL: https://github.com/apache/flink/pull/12446#discussion_r435997739
########## File path: flink-core/src/main/java/org/apache/flink/util/FlinkUserCodeClassLoader.java ########## @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.util; + +import java.net.URL; +import java.net.URLClassLoader; +import java.util.function.Consumer; + +/** + * This class loader accepts a custom handler if an exception occurs in {@link #loadClass(String, boolean)}. + */ +public abstract class FlinkUserCodeClassLoader extends URLClassLoader { + public static final Consumer<Throwable> EMPTY_EXCEPTION_HANDLER = classLoadingException -> {}; Review comment: nit: ```suggestion public static final Consumer<Throwable> NOOP_EXCEPTION_HANDLER = classLoadingException -> {}; ``` ########## File path: flink-runtime/src/test/java/org/apache/flink/runtime/execution/librarycache/BlobLibraryCacheRecoveryITCase.java ########## @@ -79,7 +79,9 @@ public void testRecoveryRegisterAndDownload() throws Exception { final BlobLibraryCacheManager.ClassLoaderFactory classLoaderFactory = BlobLibraryCacheManager.defaultClassLoaderFactory( FlinkUserCodeClassLoaders.ResolveOrder.CHILD_FIRST, - new String[0]); + new String[0], + false, + exception -> {}); Review comment: Instead of passing a boolean and the fatal error handler to `defaultClassLoaderFactory()` one could also change it to pass in the `exception handler` instead. That way one would not pass in redundant information `false` and `exception -> {}` but it would suffice to simply pass `exception -> {}`. ########## File path: flink-core/src/main/java/org/apache/flink/configuration/CoreOptions.java ########## @@ -110,6 +110,14 @@ " resolved through the parent ClassLoader first. A pattern is a simple prefix that is checked against" + " the fully qualified class name. These patterns are appended to \"" + ALWAYS_PARENT_FIRST_LOADER_PATTERNS.key() + "\"."); + @Documentation.Section(Documentation.Sections.EXPERT_CLASS_LOADING) + public static final ConfigOption<Boolean> FAIL_USER_CLASS_LOADING_METASPACE_OOM = ConfigOptions + .key("classloader.fail.on.metaspace.oom.error") + .booleanType() + .defaultValue(true) + .withDescription("Sets whether to fail and exit TaskManager JVM process if 'OutOfMemoryError: Metaspace' is " + Review comment: ```suggestion .withDescription("Fail Flink JVM processes if 'OutOfMemoryError: Metaspace' is " + ``` ########## File path: flink-core/src/main/java/org/apache/flink/configuration/CoreOptions.java ########## @@ -110,6 +110,14 @@ " resolved through the parent ClassLoader first. A pattern is a simple prefix that is checked against" + " the fully qualified class name. These patterns are appended to \"" + ALWAYS_PARENT_FIRST_LOADER_PATTERNS.key() + "\"."); + @Documentation.Section(Documentation.Sections.EXPERT_CLASS_LOADING) + public static final ConfigOption<Boolean> FAIL_USER_CLASS_LOADING_METASPACE_OOM = ConfigOptions + .key("classloader.fail.on.metaspace.oom.error") Review comment: ```suggestion .key("classloader.fail-on-metaspace-oom-error") ``` ########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/execution/librarycache/BlobLibraryCacheManager.java ########## @@ -151,12 +163,31 @@ public URLClassLoader createClassLoader(URL[] libraryURLs) { classLoaderResolveOrder, libraryURLs, FlinkUserCodeClassLoaders.class.getClassLoader(), - alwaysParentFirstPatterns); + alwaysParentFirstPatterns, + classLoadingExceptionHandler); } } - public static ClassLoaderFactory defaultClassLoaderFactory(FlinkUserCodeClassLoaders.ResolveOrder classLoaderResolveOrder, String[] alwaysParentFirstPatterns) { - return new DefaultClassLoaderFactory(classLoaderResolveOrder, alwaysParentFirstPatterns); + public static ClassLoaderFactory defaultClassLoaderFactory( + FlinkUserCodeClassLoaders.ResolveOrder classLoaderResolveOrder, + String[] alwaysParentFirstPatterns, + boolean failOnJvmMetaspaceOomError, + FatalErrorHandler fatalErrorHandler) { + return new DefaultClassLoaderFactory( + classLoaderResolveOrder, + alwaysParentFirstPatterns, + createClassLoadingExceptionHandler(failOnJvmMetaspaceOomError, fatalErrorHandler)); + } + + private static Consumer<Throwable> createClassLoadingExceptionHandler( Review comment: If we make this method public, then we don't have to pass `failOnJvmMetaspaceOomError` and `fatalErrorHandler` to `defaultClassLoaderFactory` but could directly pass in a `Consumer<Throwable>`. ########## File path: flink-core/src/main/java/org/apache/flink/configuration/CoreOptions.java ########## @@ -110,6 +110,14 @@ " resolved through the parent ClassLoader first. A pattern is a simple prefix that is checked against" + " the fully qualified class name. These patterns are appended to \"" + ALWAYS_PARENT_FIRST_LOADER_PATTERNS.key() + "\"."); + @Documentation.Section(Documentation.Sections.EXPERT_CLASS_LOADING) + public static final ConfigOption<Boolean> FAIL_USER_CLASS_LOADING_METASPACE_OOM = ConfigOptions + .key("classloader.fail.on.metaspace.oom.error") + .booleanType() + .defaultValue(true) + .withDescription("Sets whether to fail and exit TaskManager JVM process if 'OutOfMemoryError: Metaspace' is " + + "thrown trying to load a user code class."); Review comment: ```suggestion "thrown while trying to load a user code class."); ``` ########## File path: flink-core/src/main/java/org/apache/flink/configuration/CoreOptions.java ########## @@ -110,6 +110,14 @@ " resolved through the parent ClassLoader first. A pattern is a simple prefix that is checked against" + " the fully qualified class name. These patterns are appended to \"" + ALWAYS_PARENT_FIRST_LOADER_PATTERNS.key() + "\"."); + @Documentation.Section(Documentation.Sections.EXPERT_CLASS_LOADING) + public static final ConfigOption<Boolean> FAIL_USER_CLASS_LOADING_METASPACE_OOM = ConfigOptions Review comment: ```suggestion public static final ConfigOption<Boolean> FAIL_ON_USER_CLASS_LOADING_METASPACE_OOM = ConfigOptions ``` ---------------------------------------------------------------- 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]
