curcur commented on a change in pull request #14943: URL: https://github.com/apache/flink/pull/14943#discussion_r584440186
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/state/StateBackendLoader.java ########## @@ -249,6 +266,66 @@ public static StateBackend fromApplicationOrConfigOrDefault( return backend; } + /** + * This is the state backend loader that loads a {@link DelegateStateBackend} wrapping the state + * backend loaded from {@link StateBackendLoader#fromApplicationOrConfigOrDefault} when + * delegation is enabled. If delegation is not enabled, the underlying wrapped state backend is + * returned instead. + * + * <p>{@link DelegateStateBackend} can only be enabled through configuration. + * + * @param fromApplication StateBackend defined from application + * @param config The configuration to load the state backend from + * @param classLoader The class loader that should be used to load the state backend + * @param logger Optionally, a logger to log actions to (may be null) + * @return The instantiated state backend. + * @throws DynamicCodeLoadingException Thrown if a state backend (factory) is configured and the + * (factory) class was not found or could not be instantiated + * @throws IllegalConfigurationException May be thrown by the StateBackendFactory when creating + * / configuring the state backend in the factory + * @throws IOException May be thrown by the StateBackendFactory when instantiating the state + * backend + */ + public static StateBackend loadStateBackend( + @Nullable StateBackend fromApplication, + Configuration config, + ClassLoader classLoader, + @Nullable Logger logger) + throws IllegalConfigurationException, DynamicCodeLoadingException, IOException { + + final StateBackend backend = + fromApplicationOrConfigOrDefault(fromApplication, config, classLoader, logger); + + if (config.get(CheckpointingOptions.ENABLE_STATE_CHANGE_LOG)) { + LOG.info( + "Delegate State Backend is used, and the root State Backend is {}", + backend.getClass().getSimpleName()); + + // ChangelogStateBackend resides in a separate module, load it using reflection + try { + Constructor<? extends DelegateStateBackend> constructor = + Class.forName(CHANGELOG_STATE_BACKEND, false, classLoader) + .asSubclass(DelegateStateBackend.class) + .getConstructor(StateBackend.class); + return constructor.newInstance(backend); Review comment: No `ChnagelogStateBackend` can only be loaded from `loadStateBackend`; `loadStateBackend` loads the wrapped statebackend from `fromApplicationOrConfigOrDefault` `fromApplicationOrConfigOrDefault` can only return non-delegated statebackend ---------------------------------------------------------------- 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: us...@infra.apache.org