Github user tillrohrmann commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3933#discussion_r117370134
  
    --- Diff: 
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/hooks/MasterHooks.java
 ---
    @@ -267,6 +269,112 @@ else if (!allowUnmatchedState) {
        }
     
        // 
------------------------------------------------------------------------
    +   //  hook management
    +   // 
------------------------------------------------------------------------
    +
    +   /**
    +    * Wraps a hook such that the user-code classloader is applied when the 
hook is invoked.
    +    * @param hook the hook to wrap
    +    * @param userClassLoader the classloader to use
    +    */
    +   public static <T> MasterTriggerRestoreHook<T> 
wrapHook(MasterTriggerRestoreHook<T> hook, ClassLoader userClassLoader) {
    +           return new WrappedMasterHook<T>(hook, userClassLoader);
    +   }
    +
    +   @VisibleForTesting
    +   static class WrappedMasterHook<T> implements 
MasterTriggerRestoreHook<T> {
    +
    +           private final MasterTriggerRestoreHook<T> hook;
    +           private final ClassLoader userClassLoader;
    +
    +           WrappedMasterHook(MasterTriggerRestoreHook<T> hook, ClassLoader 
userClassLoader) {
    +                   this.hook = hook;
    +                   this.userClassLoader = userClassLoader;
    +           }
    +
    +           @Override
    +           public String getIdentifier() {
    +                   Thread thread = Thread.currentThread();
    +                   ClassLoader originalClassLoader = 
thread.getContextClassLoader();
    +                   thread.setContextClassLoader(userClassLoader);
    --- End diff --
    
    Maybe we can move the `setContextClassLoader` into the `try` body. Just to 
be on the safe side that whenever something happens we will reset the original 
class loader.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to