Download flink_3/solution/solution.patch from lolbench26/LoLBench: direct link, hf CLI and curl.
- Browser
- Download file 63.2 kB
-
https://huggingface.co/datasets/lolbench26/LoLBench/resolve/main/flink_3/solution/solution.patch
- Command line
-
hf download hf://datasets/lolbench26/LoLBench/flink_3/solution/solution.patch
-
curl -L -o solution.patch https://huggingface.co/datasets/lolbench26/LoLBench/resolve/main/flink_3/solution/solution.patch
63.2 kB
| diff --git a/flink-clients/src/main/java/org/apache/flink/client/deployment/application/ApplicationClusterEntryPoint.java b/flink-clients/src/main/java/org/apache/flink/client/deployment/application/ApplicationClusterEntryPoint.java | |
| index db290384..9307666f 100644 | |
| --- a/flink-clients/src/main/java/org/apache/flink/client/deployment/application/ApplicationClusterEntryPoint.java | |
| +++ b/flink-clients/src/main/java/org/apache/flink/client/deployment/application/ApplicationClusterEntryPoint.java | |
| public class ApplicationClusterEntryPoint extends ClusterEntrypoint { | |
| } | |
| @Override | |
| - protected void cleanupDirectories() throws IOException { | |
| + protected void cleanupDirectories(ShutdownBehaviour shutdownBehaviour) throws IOException { | |
| // Close the packaged program explicitly to clean up temporary jars. | |
| program.close(); | |
| - super.cleanupDirectories(); | |
| + super.cleanupDirectories(shutdownBehaviour); | |
| } | |
| } | |
| diff --git a/flink-core/src/main/java/org/apache/flink/configuration/CheckpointingOptions.java b/flink-core/src/main/java/org/apache/flink/configuration/CheckpointingOptions.java | |
| index 99859821..fce2f506 100644 | |
| --- a/flink-core/src/main/java/org/apache/flink/configuration/CheckpointingOptions.java | |
| +++ b/flink-core/src/main/java/org/apache/flink/configuration/CheckpointingOptions.java | |
| public class CheckpointingOptions { | |
| ConfigOptions.key("taskmanager.state.local.root-dirs") | |
| .noDefaultValue() | |
| .withDescription( | |
| - "The config parameter defining the root directories for storing file-based state for local " | |
| - + "recovery. Local recovery currently only covers keyed state backends. Currently, MemoryStateBackend does " | |
| - + "not support local recovery and ignore this option"); | |
| + Description.builder() | |
| + .text( | |
| + "The config parameter defining the root directories for storing file-based " | |
| + + "state for local recovery. Local recovery currently only covers keyed " | |
| + + "state backends. Currently, MemoryStateBackend does not support local " | |
| + + "recovery and ignores this option. If not configured it will default " | |
| + + "to <WORKING_DIR>/localState. The <WORKING_DIR> can be configured via %s", | |
| + TextElement.code( | |
| + ClusterOptions | |
| + .TASK_MANAGER_PROCESS_WORKING_DIR_BASE | |
| + .key())) | |
| + .build()); | |
| // ------------------------------------------------------------------------ | |
| // Options specific to the file-system-based state backends | |
| diff --git a/flink-core/src/main/java/org/apache/flink/configuration/ClusterOptions.java b/flink-core/src/main/java/org/apache/flink/configuration/ClusterOptions.java | |
| index 74b5a1de..a59f3183 100644 | |
| --- a/flink-core/src/main/java/org/apache/flink/configuration/ClusterOptions.java | |
| +++ b/flink-core/src/main/java/org/apache/flink/configuration/ClusterOptions.java | |
| import org.apache.flink.annotation.PublicEvolving; | |
| import org.apache.flink.annotation.docs.Documentation; | |
| import org.apache.flink.configuration.description.Description; | |
| import org.apache.flink.configuration.description.InlineElement; | |
| +import org.apache.flink.configuration.description.TextElement; | |
| import static org.apache.flink.configuration.ClusterOptions.UserSystemExitMode.THROW; | |
| import static org.apache.flink.configuration.ConfigOptions.key; | |
| public class ClusterOptions { | |
| UncaughtExceptionHandleMode.LOG.name(), | |
| UncaughtExceptionHandleMode.FAIL.name())); | |
| + @Documentation.OverrideDefault("io.tmp.dirs") | |
| + @Documentation.Section(Documentation.Sections.EXPERT_CLUSTER) | |
| + public static final ConfigOption<String> PROCESS_WORKING_DIR_BASE = | |
| + ConfigOptions.key("process.working-dir") | |
| + .stringType() | |
| + .noDefaultValue() | |
| + .withDescription( | |
| + Description.builder() | |
| + .text( | |
| + "Working directory for Flink processes. " | |
| + + "The working directory can be used to store information that can be used upon process recovery. " | |
| + + "If not configured, then it will default to a randomly picked temporary directory defined via %s.", | |
| + TextElement.code(CoreOptions.TMP_DIRS.key())) | |
| + .build()); | |
| + | |
| + @Documentation.Section(Documentation.Sections.EXPERT_CLUSTER) | |
| + public static final ConfigOption<String> JOB_MANAGER_PROCESS_WORKING_DIR_BASE = | |
| + ConfigOptions.key("process.jobmanager.working-dir") | |
| + .stringType() | |
| + .noDefaultValue() | |
| + .withFallbackKeys(PROCESS_WORKING_DIR_BASE.key()) | |
| + .withDescription( | |
| + Description.builder() | |
| + .text( | |
| + "Working directory for Flink JobManager processes. The working directory can be used to store information that can be used upon process recovery. If not configured, then it will default to %s.", | |
| + TextElement.code(PROCESS_WORKING_DIR_BASE.key())) | |
| + .build()); | |
| + | |
| + @Documentation.Section(Documentation.Sections.EXPERT_CLUSTER) | |
| + public static final ConfigOption<String> TASK_MANAGER_PROCESS_WORKING_DIR_BASE = | |
| + ConfigOptions.key("process.taskmanager.working-dir") | |
| + .stringType() | |
| + .noDefaultValue() | |
| + .withFallbackKeys(PROCESS_WORKING_DIR_BASE.key()) | |
| + .withDescription( | |
| + Description.builder() | |
| + .text( | |
| + "Working directory for Flink TaskManager processes. The working directory can be used to store information that can be used upon process recovery. If not configured, then it will default to %s.", | |
| + TextElement.code(PROCESS_WORKING_DIR_BASE.key())) | |
| + .build()); | |
| + | |
| public static JobManagerOptions.SchedulerType getSchedulerType(Configuration configuration) { | |
| if (isAdaptiveSchedulerEnabled(configuration) || isReactiveModeEnabled(configuration)) { | |
| return JobManagerOptions.SchedulerType.Adaptive; | |
| diff --git a/flink-core/src/main/java/org/apache/flink/configuration/ConfigurationUtils.java b/flink-core/src/main/java/org/apache/flink/configuration/ConfigurationUtils.java | |
| index fe42f548..a2bce405 100755 | |
| --- a/flink-core/src/main/java/org/apache/flink/configuration/ConfigurationUtils.java | |
| +++ b/flink-core/src/main/java/org/apache/flink/configuration/ConfigurationUtils.java | |
| package org.apache.flink.configuration; | |
| import org.apache.flink.annotation.VisibleForTesting; | |
| import org.apache.flink.api.common.time.Time; | |
| +import org.apache.flink.util.Preconditions; | |
| import org.apache.flink.util.TimeUtils; | |
| import javax.annotation.Nonnull; | |
| import java.util.Map; | |
| import java.util.Optional; | |
| import java.util.Properties; | |
| import java.util.Set; | |
| +import java.util.concurrent.ThreadLocalRandom; | |
| import java.util.stream.Collectors; | |
| import static org.apache.flink.configuration.MetricOptions.SYSTEM_RESOURCE_METRICS; | |
| public class ConfigurationUtils { | |
| return splitPaths(configuration.getString(CoreOptions.TMP_DIRS)); | |
| } | |
| + /** | |
| + * Picks a temporary directory randomly from the given configuration. | |
| + * | |
| + * @param configuration to extract the temp directory from | |
| + * @return a randomly picked temporary directory | |
| + */ | |
| + @Nonnull | |
| + public static File getRandomTempDirectory(Configuration configuration) { | |
| + final String[] tmpDirectories = parseTempDirectories(configuration); | |
| + | |
| + Preconditions.checkState( | |
| + tmpDirectories.length > 0, | |
| + String.format( | |
| + "No temporary directory has been specified for %s", | |
| + CoreOptions.TMP_DIRS.key())); | |
| + | |
| + final int randomIndex = ThreadLocalRandom.current().nextInt(tmpDirectories.length); | |
| + | |
| + return new File(tmpDirectories[randomIndex]); | |
| + } | |
| + | |
| /** | |
| * Extracts the local state directories as defined by {@link | |
| * CheckpointingOptions#LOCAL_RECOVERY_TASK_MANAGER_STATE_ROOT_DIRS}. | |
| diff --git a/flink-core/src/main/java/org/apache/flink/configuration/JobManagerOptions.java b/flink-core/src/main/java/org/apache/flink/configuration/JobManagerOptions.java | |
| index caa01578..97a0f027 100644 | |
| --- a/flink-core/src/main/java/org/apache/flink/configuration/JobManagerOptions.java | |
| +++ b/flink-core/src/main/java/org/apache/flink/configuration/JobManagerOptions.java | |
| public class JobManagerOptions { | |
| code(SchedulerType.AdaptiveBatch.name())) | |
| .build()); | |
| + /** | |
| + * The JobManager's ResourceID. If not configured, the ResourceID will be generated randomly. | |
| + */ | |
| + @Documentation.Section(Documentation.Sections.ALL_JOB_MANAGER) | |
| + public static final ConfigOption<String> JOB_MANAGER_RESOURCE_ID = | |
| + key("jobmanager.resource-id") | |
| + .stringType() | |
| + .noDefaultValue() | |
| + .withDescription( | |
| + "The JobManager's ResourceID. If not configured, the ResourceID will be generated randomly."); | |
| + | |
| // --------------------------------------------------------------------------------------------- | |
| private JobManagerOptions() { | |
| diff --git a/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/runtime/SavepointEnvironment.java b/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/runtime/SavepointEnvironment.java | |
| index e4a331e7..682c4cf3 100644 | |
| --- a/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/runtime/SavepointEnvironment.java | |
| +++ b/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/runtime/SavepointEnvironment.java | |
| public class SavepointEnvironment implements Environment { | |
| @Override | |
| public TaskManagerRuntimeInfo getTaskManagerInfo() { | |
| - return new SavepointTaskManagerRuntimeInfo(getIOManager()); | |
| + return new SavepointTaskManagerRuntimeInfo(getIOManager().getSpillingDirectories()[0]); | |
| } | |
| @Override | |
| diff --git a/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/runtime/SavepointTaskManagerRuntimeInfo.java b/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/runtime/SavepointTaskManagerRuntimeInfo.java | |
| index 5f481924..873fc244 100644 | |
| --- a/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/runtime/SavepointTaskManagerRuntimeInfo.java | |
| +++ b/flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/runtime/SavepointTaskManagerRuntimeInfo.java | |
| package org.apache.flink.state.api.runtime; | |
| import org.apache.flink.configuration.Configuration; | |
| -import org.apache.flink.runtime.io.disk.iomanager.IOManager; | |
| import org.apache.flink.runtime.taskmanager.TaskManagerRuntimeInfo; | |
| import org.apache.flink.util.Preconditions; | |
| +import java.io.File; | |
| + | |
| /** | |
| * A minimally implemented {@link TaskManagerRuntimeInfo} that provides the functionality required | |
| * to run the {@code state-processor-api}. | |
| */ | |
| class SavepointTaskManagerRuntimeInfo implements TaskManagerRuntimeInfo { | |
| - private final IOManager ioManager; | |
| + private final File tmpWorkingDirectory; | |
| - SavepointTaskManagerRuntimeInfo(IOManager ioManager) { | |
| - this.ioManager = Preconditions.checkNotNull(ioManager); | |
| + SavepointTaskManagerRuntimeInfo(File tmpWorkingDirectory) { | |
| + this.tmpWorkingDirectory = Preconditions.checkNotNull(tmpWorkingDirectory); | |
| } | |
| @Override | |
| class SavepointTaskManagerRuntimeInfo implements TaskManagerRuntimeInfo { | |
| @Override | |
| public String[] getTmpDirectories() { | |
| - return ioManager.getSpillingDirectoriesPaths(); | |
| + throw new UnsupportedOperationException( | |
| + "Tmp directories are not available with the SavepointTaskManagerRuntimeInfo"); | |
| } | |
| @Override | |
| class SavepointTaskManagerRuntimeInfo implements TaskManagerRuntimeInfo { | |
| throw new UnsupportedOperationException( | |
| "Getting external address of task manager is not supported in SavepointTaskManagerRuntimeInfo"); | |
| } | |
| + | |
| + @Override | |
| + public File getTmpWorkingDirectory() { | |
| + return tmpWorkingDirectory; | |
| + } | |
| } | |
| diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java | |
| index b4d23b4e..4955b3b5 100755 | |
| --- a/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java | |
| +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypoint.java | |
| import org.apache.flink.core.security.FlinkSecurityManager; | |
| import org.apache.flink.management.jmx.JMXService; | |
| import org.apache.flink.runtime.blob.BlobServer; | |
| import org.apache.flink.runtime.clusterframework.ApplicationStatus; | |
| +import org.apache.flink.runtime.clusterframework.types.ResourceID; | |
| import org.apache.flink.runtime.dispatcher.ExecutionGraphInfoStore; | |
| import org.apache.flink.runtime.dispatcher.MiniDispatcher; | |
| import org.apache.flink.runtime.entrypoint.component.DispatcherResourceManagerComponent; | |
| public abstract class ClusterEntrypoint implements AutoCloseableAsync, FatalErro | |
| private final AtomicBoolean isShutDown = new AtomicBoolean(false); | |
| + @GuardedBy("lock") | |
| + private ResourceID resourceId; | |
| + | |
| @GuardedBy("lock") | |
| private DispatcherResourceManagerComponent clusterComponent; | |
| public abstract class ClusterEntrypoint implements AutoCloseableAsync, FatalErro | |
| @GuardedBy("lock") | |
| private ExecutorService ioExecutor; | |
| + @GuardedBy("lock") | |
| + private WorkingDirectory workingDirectory; | |
| + | |
| private ExecutionGraphInfoStore executionGraphInfoStore; | |
| private final Thread shutDownHook; | |
| public abstract class ClusterEntrypoint implements AutoCloseableAsync, FatalErro | |
| // clean up any partial state | |
| shutDownAsync( | |
| ApplicationStatus.FAILED, | |
| - ShutdownBehaviour.STOP_APPLICATION, | |
| + ShutdownBehaviour.GRACEFUL_SHUTDOWN, | |
| ExceptionUtils.stringifyException(strippedThrowable), | |
| false) | |
| .get( | |
| public abstract class ClusterEntrypoint implements AutoCloseableAsync, FatalErro | |
| clusterComponent = | |
| dispatcherResourceManagerComponentFactory.create( | |
| configuration, | |
| + resourceId, | |
| ioExecutor, | |
| commonRpcService, | |
| haServices, | |
| public abstract class ClusterEntrypoint implements AutoCloseableAsync, FatalErro | |
| if (throwable != null) { | |
| shutDownAsync( | |
| ApplicationStatus.UNKNOWN, | |
| - ShutdownBehaviour.STOP_APPLICATION, | |
| + ShutdownBehaviour.GRACEFUL_SHUTDOWN, | |
| ExceptionUtils.stringifyException(throwable), | |
| false); | |
| } else { | |
| public abstract class ClusterEntrypoint implements AutoCloseableAsync, FatalErro | |
| // already triggered, this will do nothing | |
| shutDownAsync( | |
| applicationStatus, | |
| - ShutdownBehaviour.STOP_APPLICATION, | |
| + ShutdownBehaviour.GRACEFUL_SHUTDOWN, | |
| null, | |
| true); | |
| } | |
| public abstract class ClusterEntrypoint implements AutoCloseableAsync, FatalErro | |
| executionGraphInfoStore = | |
| createSerializableExecutionGraphStore( | |
| configuration, commonRpcService.getScheduledExecutor()); | |
| + | |
| + resourceId = | |
| + configuration | |
| + .getOptional(JobManagerOptions.JOB_MANAGER_RESOURCE_ID) | |
| + .map(ResourceID::new) | |
| + .orElseGet(ResourceID::generate); | |
| + | |
| + LOG.debug( | |
| + "Initialize cluster entrypoint {} with resource id {}.", | |
| + getClass().getSimpleName(), | |
| + resourceId); | |
| + | |
| + workingDirectory = | |
| + ClusterEntrypointUtils.createJobManagerWorkingDirectory( | |
| + configuration, resourceId); | |
| } | |
| } | |
| public abstract class ClusterEntrypoint implements AutoCloseableAsync, FatalErro | |
| return shutDownAsync( | |
| ApplicationStatus.UNKNOWN, | |
| - ShutdownBehaviour.STOP_PROCESS, | |
| + ShutdownBehaviour.PROCESS_FAILURE, | |
| "Cluster entrypoint has been closed externally.", | |
| false) | |
| .thenAccept(ignored -> {}); | |
| public abstract class ClusterEntrypoint implements AutoCloseableAsync, FatalErro | |
| final CompletableFuture<Void> cleanupDirectoriesFuture = | |
| FutureUtils.runAfterwards( | |
| - rpcSystemClassLoaderCloseFuture, this::cleanupDirectories); | |
| + rpcSystemClassLoaderCloseFuture, | |
| + () -> cleanupDirectories(shutdownBehaviour)); | |
| cleanupDirectoriesFuture.whenComplete( | |
| (Void ignored2, Throwable serviceThrowable) -> { | |
| public abstract class ClusterEntrypoint implements AutoCloseableAsync, FatalErro | |
| synchronized (lock) { | |
| if (clusterComponent != null) { | |
| switch (shutdownBehaviour) { | |
| - case STOP_APPLICATION: | |
| + case GRACEFUL_SHUTDOWN: | |
| return clusterComponent.stopApplication(applicationStatus, diagnostics); | |
| - case STOP_PROCESS: | |
| + case PROCESS_FAILURE: | |
| default: | |
| return clusterComponent.stopProcess(); | |
| } | |
| public abstract class ClusterEntrypoint implements AutoCloseableAsync, FatalErro | |
| /** | |
| * Clean up of temporary directories created by the {@link ClusterEntrypoint}. | |
| * | |
| + * @param shutdownBehaviour specifying the shutdown behaviour | |
| * @throws IOException if the temporary directories could not be cleaned up | |
| */ | |
| - protected void cleanupDirectories() throws IOException { | |
| + protected void cleanupDirectories(ShutdownBehaviour shutdownBehaviour) throws IOException { | |
| + IOException ioException = null; | |
| + | |
| final String webTmpDir = configuration.getString(WebOptions.TMP_DIR); | |
| - FileUtils.deleteDirectory(new File(webTmpDir)); | |
| + try { | |
| + FileUtils.deleteDirectory(new File(webTmpDir)); | |
| + } catch (IOException ioe) { | |
| + ioException = ioe; | |
| + } | |
| + | |
| + // We only clean up the working directory if we gracefully shut down. If it is a process | |
| + // failure, then we want to keep the working directory for potential recoveries. | |
| + if (shutdownBehaviour == ShutdownBehaviour.GRACEFUL_SHUTDOWN) { | |
| + synchronized (lock) { | |
| + if (workingDirectory != null) { | |
| + try { | |
| + workingDirectory.delete(); | |
| + } catch (IOException ioe) { | |
| + ioException = ExceptionUtils.firstOrSuppressed(ioe, ioException); | |
| + } | |
| + } | |
| + } | |
| + } | |
| + | |
| + if (ioException != null) { | |
| + throw ioException; | |
| + } | |
| } | |
| // -------------------------------------------------- | |
| public abstract class ClusterEntrypoint implements AutoCloseableAsync, FatalErro | |
| DETACHED | |
| } | |
| - private enum ShutdownBehaviour { | |
| - STOP_APPLICATION, | |
| - STOP_PROCESS, | |
| + /** Shutdown behaviour of a {@link ClusterEntrypoint}. */ | |
| + protected enum ShutdownBehaviour { | |
| + // Graceful shutdown means that the process wants to terminate and will clean everything up | |
| + GRACEFUL_SHUTDOWN, | |
| + // Process failure means that we don't clean up things so that they could be recovered | |
| + PROCESS_FAILURE, | |
| } | |
| } | |
| diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypointUtils.java b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypointUtils.java | |
| index d02646bb..57f15f01 100644 | |
| --- a/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypointUtils.java | |
| +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/ClusterEntrypointUtils.java | |
| package org.apache.flink.runtime.entrypoint; | |
| +import org.apache.flink.annotation.VisibleForTesting; | |
| import org.apache.flink.configuration.ClusterOptions; | |
| import org.apache.flink.configuration.ConfigConstants; | |
| +import org.apache.flink.configuration.ConfigOption; | |
| import org.apache.flink.configuration.Configuration; | |
| +import org.apache.flink.configuration.ConfigurationUtils; | |
| +import org.apache.flink.configuration.CoreOptions; | |
| +import org.apache.flink.runtime.clusterframework.types.ResourceID; | |
| import org.apache.flink.runtime.entrypoint.parser.CommandLineParser; | |
| import org.apache.flink.runtime.entrypoint.parser.ParserResultFactory; | |
| import org.apache.flink.runtime.util.ClusterUncaughtExceptionHandler; | |
| import org.slf4j.LoggerFactory; | |
| import javax.annotation.Nullable; | |
| import java.io.File; | |
| +import java.io.IOException; | |
| import java.util.Optional; | |
| /** Utility class for {@link org.apache.flink.runtime.entrypoint.ClusterEntrypoint}. */ | |
| public final class ClusterEntrypointUtils { | |
| new ClusterUncaughtExceptionHandler( | |
| config.get(ClusterOptions.UNCAUGHT_EXCEPTION_HANDLING))); | |
| } | |
| + | |
| + /** | |
| + * Creates the working directory for the TaskManager process. This method ensures that the | |
| + * working directory exists. | |
| + * | |
| + * @param configuration to extract the required settings from | |
| + * @param resourceId identifying the TaskManager process | |
| + * @return working directory | |
| + * @throws IOException if the working directory could not be created | |
| + */ | |
| + public static WorkingDirectory createTaskManagerWorkingDirectory( | |
| + Configuration configuration, ResourceID resourceId) throws IOException { | |
| + return WorkingDirectory.create( | |
| + generateTaskManagerWorkingDirectoryFile(configuration, resourceId)); | |
| + } | |
| + | |
| + /** | |
| + * Generates the working directory {@link File} for the TaskManager process. This method does | |
| + * not ensure that the working directory exists. | |
| + * | |
| + * @param configuration to extract the required settings from | |
| + * @param resourceId identifying the TaskManager process | |
| + * @return working directory file | |
| + */ | |
| + @VisibleForTesting | |
| + public static File generateTaskManagerWorkingDirectoryFile( | |
| + Configuration configuration, ResourceID resourceId) { | |
| + return generateWorkingDirectoryFile( | |
| + configuration, | |
| + Optional.of(ClusterOptions.TASK_MANAGER_PROCESS_WORKING_DIR_BASE), | |
| + "tm_" + resourceId); | |
| + } | |
| + | |
| + /** | |
| + * Generates the working directory {@link File} for the JobManager process. This method does not | |
| + * ensure that the working directory exists. | |
| + * | |
| + * @param configuration to extract the required settings from | |
| + * @param resourceId identifying the JobManager process | |
| + * @return working directory file | |
| + */ | |
| + @VisibleForTesting | |
| + public static File generateJobManagerWorkingDirectoryFile( | |
| + Configuration configuration, ResourceID resourceId) { | |
| + return generateWorkingDirectoryFile( | |
| + configuration, | |
| + Optional.of(ClusterOptions.JOB_MANAGER_PROCESS_WORKING_DIR_BASE), | |
| + "jm_" + resourceId); | |
| + } | |
| + | |
| + /** | |
| + * Generate the working directory from the given configuration. If a working dir option is | |
| + * specified, then this config option will be read first. At last, {@link CoreOptions#TMP_DIRS} | |
| + * will be used to extract the working directory base from. | |
| + * | |
| + * @param configuration to extract the working directory from | |
| + * @param workingDirOption optional working dir option | |
| + * @param workingDirectoryName name of the working directory to create | |
| + * @return working directory | |
| + */ | |
| + public static File generateWorkingDirectoryFile( | |
| + Configuration configuration, | |
| + Optional<ConfigOption<String>> workingDirOption, | |
| + String workingDirectoryName) { | |
| + final Optional<String> optionalWorkingDirectory = | |
| + workingDirOption.flatMap(configuration::getOptional); | |
| + | |
| + final File workingDirectoryBase = | |
| + optionalWorkingDirectory | |
| + .map(File::new) | |
| + .orElseGet( | |
| + () -> { | |
| + final File tempDirectory = | |
| + ConfigurationUtils.getRandomTempDirectory( | |
| + configuration); | |
| + | |
| + LOG.debug( | |
| + "Picked {} randomly from the configured temporary directories to be used as working directory base.", | |
| + tempDirectory); | |
| + | |
| + return tempDirectory; | |
| + }); | |
| + | |
| + return new File(workingDirectoryBase, workingDirectoryName); | |
| + } | |
| + | |
| + /** | |
| + * Creates the working directory for the JobManager process. This method ensures that the | |
| + * working diretory exists. | |
| + * | |
| + * @param configuration to extract the required settings from | |
| + * @param resourceId identifying the TaskManager process | |
| + * @return working directory | |
| + * @throws IOException if the working directory could not be created | |
| + */ | |
| + public static WorkingDirectory createJobManagerWorkingDirectory( | |
| + Configuration configuration, ResourceID resourceId) throws IOException { | |
| + return WorkingDirectory.create( | |
| + generateJobManagerWorkingDirectoryFile(configuration, resourceId)); | |
| + } | |
| } | |
| diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/WorkingDirectory.java b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/WorkingDirectory.java | |
| new file mode 100644 | |
| index 00000000..df63ffe4 | |
| --- /dev/null | |
| +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/WorkingDirectory.java | |
| +/* | |
| + * 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.runtime.entrypoint; | |
| + | |
| +import org.apache.flink.util.FileUtils; | |
| + | |
| +import java.io.File; | |
| +import java.io.IOException; | |
| + | |
| +/** | |
| + * Class that manages a working directory for a process/instance. When being instantiated, this | |
| + * class makes sure that the specified working directory exists. | |
| + */ | |
| +public class WorkingDirectory { | |
| + private final File root; | |
| + private final File tmp; | |
| + private final File localState; | |
| + | |
| + private WorkingDirectory(File root) throws IOException { | |
| + this.root = root; | |
| + createDirectory(root); | |
| + | |
| + this.tmp = new File(root, "tmp"); | |
| + createDirectory(tmp); | |
| + FileUtils.cleanDirectory(tmp); | |
| + | |
| + localState = new File(root, "localState"); | |
| + createDirectory(localState); | |
| + } | |
| + | |
| + private static void createDirectory(File directory) throws IOException { | |
| + if (!directory.mkdirs() && !directory.exists()) { | |
| + throw new IOException( | |
| + String.format("Could not create the working directory %s.", directory)); | |
| + } | |
| + } | |
| + | |
| + public void delete() throws IOException { | |
| + FileUtils.deleteDirectory(root); | |
| + } | |
| + | |
| + public File getTmpDirectory() { | |
| + return tmp; | |
| + } | |
| + | |
| + public File getLocalStateDirectory() { | |
| + return localState; | |
| + } | |
| + | |
| + public WorkingDirectory createSubWorkingDirectory(String directoryName) throws IOException { | |
| + return createIn(root, directoryName); | |
| + } | |
| + | |
| + @Override | |
| + public String toString() { | |
| + return String.format("WorkingDirectory(%s)", root.toString()); | |
| + } | |
| + | |
| + public static WorkingDirectory create(File workingDirectory) throws IOException { | |
| + return new WorkingDirectory(workingDirectory); | |
| + } | |
| + | |
| + public static WorkingDirectory createIn(File parentDirectory, String directoryName) | |
| + throws IOException { | |
| + return create(new File(parentDirectory, directoryName)); | |
| + } | |
| +} | |
| diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/component/DefaultDispatcherResourceManagerComponentFactory.java b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/component/DefaultDispatcherResourceManagerComponentFactory.java | |
| index 83f630ee..0d514f51 100644 | |
| --- a/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/component/DefaultDispatcherResourceManagerComponentFactory.java | |
| +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/component/DefaultDispatcherResourceManagerComponentFactory.java | |
| import org.apache.flink.configuration.Configuration; | |
| import org.apache.flink.configuration.MetricOptions; | |
| import org.apache.flink.configuration.RestOptions; | |
| import org.apache.flink.runtime.blob.BlobServer; | |
| +import org.apache.flink.runtime.clusterframework.types.ResourceID; | |
| import org.apache.flink.runtime.dispatcher.DispatcherGateway; | |
| import org.apache.flink.runtime.dispatcher.DispatcherId; | |
| import org.apache.flink.runtime.dispatcher.DispatcherOperationCaches; | |
| public class DefaultDispatcherResourceManagerComponentFactory | |
| @Override | |
| public DispatcherResourceManagerComponent create( | |
| Configuration configuration, | |
| + ResourceID resourceId, | |
| Executor ioExecutor, | |
| RpcService rpcService, | |
| HighAvailabilityServices highAvailabilityServices, | |
| public class DefaultDispatcherResourceManagerComponentFactory | |
| ResourceManagerServiceImpl.create( | |
| resourceManagerFactory, | |
| configuration, | |
| + resourceId, | |
| rpcService, | |
| highAvailabilityServices, | |
| heartbeatServices, | |
| diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/component/DispatcherResourceManagerComponentFactory.java b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/component/DispatcherResourceManagerComponentFactory.java | |
| index 8cddd193..9d9c9852 100644 | |
| --- a/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/component/DispatcherResourceManagerComponentFactory.java | |
| +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/entrypoint/component/DispatcherResourceManagerComponentFactory.java | |
| package org.apache.flink.runtime.entrypoint.component; | |
| import org.apache.flink.configuration.Configuration; | |
| import org.apache.flink.runtime.blob.BlobServer; | |
| +import org.apache.flink.runtime.clusterframework.types.ResourceID; | |
| import org.apache.flink.runtime.dispatcher.ExecutionGraphInfoStore; | |
| import org.apache.flink.runtime.heartbeat.HeartbeatServices; | |
| import org.apache.flink.runtime.highavailability.HighAvailabilityServices; | |
| public interface DispatcherResourceManagerComponentFactory { | |
| DispatcherResourceManagerComponent create( | |
| Configuration configuration, | |
| + ResourceID resourceId, | |
| Executor ioExecutor, | |
| RpcService rpcService, | |
| HighAvailabilityServices highAvailabilityServices, | |
| diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java b/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java | |
| index 5b095743..b3f333a7 100644 | |
| --- a/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java | |
| +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/minicluster/MiniCluster.java | |
| import org.apache.flink.runtime.dispatcher.MemoryExecutionGraphInfoStore; | |
| import org.apache.flink.runtime.dispatcher.TriggerSavepointMode; | |
| import org.apache.flink.runtime.entrypoint.ClusterEntrypointUtils; | |
| import org.apache.flink.runtime.entrypoint.ClusterInformation; | |
| +import org.apache.flink.runtime.entrypoint.WorkingDirectory; | |
| import org.apache.flink.runtime.entrypoint.component.DefaultDispatcherResourceManagerComponentFactory; | |
| import org.apache.flink.runtime.entrypoint.component.DispatcherResourceManagerComponent; | |
| import org.apache.flink.runtime.entrypoint.component.DispatcherResourceManagerComponentFactory; | |
| public class MiniCluster implements AutoCloseableAsync { | |
| @GuardedBy("lock") | |
| private RpcServiceFactory taskManagerRpcServiceFactory; | |
| + @GuardedBy("lock") | |
| + private WorkingDirectory workingDirectory; | |
| + | |
| /** Flag marking the mini cluster as started/running. */ | |
| private volatile boolean running; | |
| public class MiniCluster implements AutoCloseableAsync { | |
| miniClusterConfiguration.getRpcServiceSharing() == RpcServiceSharing.SHARED; | |
| try { | |
| + workingDirectory = | |
| + WorkingDirectory.create( | |
| + ClusterEntrypointUtils.generateWorkingDirectoryFile( | |
| + configuration, | |
| + Optional.empty(), | |
| + "minicluster_" + ResourceID.generate())); | |
| + | |
| initializeIOFormatClasses(configuration); | |
| rpcSystem = RpcSystem.load(configuration); | |
| public class MiniCluster implements AutoCloseableAsync { | |
| return Collections.singleton( | |
| dispatcherResourceManagerComponentFactory.create( | |
| configuration, | |
| + ResourceID.generate(), | |
| ioExecutor, | |
| rpcServiceFactory.createRpcService(), | |
| haServices, | |
| public class MiniCluster implements AutoCloseableAsync { | |
| remainingServicesTerminationFuture, | |
| () -> terminateExecutors(shutdownTimeoutMillis)); | |
| - executorsTerminationFuture.whenComplete( | |
| + final CompletableFuture<Void> deleteDirectoriesFuture = | |
| + FutureUtils.runAfterwards( | |
| + executorsTerminationFuture, this::deleteDirectories); | |
| + | |
| + deleteDirectoriesFuture.whenComplete( | |
| (Void ignored, Throwable throwable) -> { | |
| if (throwable != null) { | |
| terminationFuture.completeExceptionally( | |
| public class MiniCluster implements AutoCloseableAsync { | |
| blobCacheService, | |
| useLocalCommunication(), | |
| ExternalResourceInfoProvider.NO_EXTERNAL_RESOURCES, | |
| + workingDirectory.createSubWorkingDirectory("tm_" + taskManagers.size()), | |
| taskManagerTerminatingFatalErrorHandlerFactory.create( | |
| taskManagers.size())); | |
| public class MiniCluster implements AutoCloseableAsync { | |
| } | |
| } | |
| + private void deleteDirectories() throws IOException { | |
| + synchronized (lock) { | |
| + if (workingDirectory != null) { | |
| + workingDirectory.delete(); | |
| + } | |
| + } | |
| + } | |
| + | |
| /** Internal factory for {@link RpcService}. */ | |
| protected interface RpcServiceFactory { | |
| RpcService createRpcService() throws Exception; | |
| diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerFactory.java b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerFactory.java | |
| index fd8a9f6d..6bb6b7b3 100644 | |
| --- a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerFactory.java | |
| +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerFactory.java | |
| public abstract class ResourceManagerFactory<T extends ResourceIDRetrievable> { | |
| public ResourceManagerProcessContext createResourceManagerProcessContext( | |
| Configuration configuration, | |
| + ResourceID resourceId, | |
| RpcService rpcService, | |
| HighAvailabilityServices highAvailabilityServices, | |
| HeartbeatServices heartbeatServices, | |
| public abstract class ResourceManagerFactory<T extends ResourceIDRetrievable> { | |
| return new ResourceManagerProcessContext( | |
| rmConfig, | |
| + resourceId, | |
| runtimeServiceConfig, | |
| rpcService, | |
| highAvailabilityServices, | |
| public abstract class ResourceManagerFactory<T extends ResourceIDRetrievable> { | |
| } | |
| public ResourceManager<T> createResourceManager( | |
| - ResourceManagerProcessContext context, UUID leaderSessionId, ResourceID resourceId) | |
| - throws Exception { | |
| + ResourceManagerProcessContext context, UUID leaderSessionId) throws Exception { | |
| final ResourceManagerRuntimeServices resourceManagerRuntimeServices = | |
| createResourceManagerRuntimeServices( | |
| public abstract class ResourceManagerFactory<T extends ResourceIDRetrievable> { | |
| return createResourceManager( | |
| context.getRmConfig(), | |
| - resourceId, | |
| + context.getResourceId(), | |
| context.getRpcService(), | |
| leaderSessionId, | |
| context.getHeartbeatServices(), | |
| diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerProcessContext.java b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerProcessContext.java | |
| index 79d8ed13..994947de 100644 | |
| --- a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerProcessContext.java | |
| +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerProcessContext.java | |
| package org.apache.flink.runtime.resourcemanager; | |
| import org.apache.flink.configuration.Configuration; | |
| +import org.apache.flink.runtime.clusterframework.types.ResourceID; | |
| import org.apache.flink.runtime.entrypoint.ClusterInformation; | |
| import org.apache.flink.runtime.heartbeat.HeartbeatServices; | |
| import org.apache.flink.runtime.highavailability.HighAvailabilityServices; | |
| import static org.apache.flink.util.Preconditions.checkNotNull; | |
| */ | |
| public class ResourceManagerProcessContext { | |
| private final Configuration rmConfig; | |
| + private final ResourceID resourceId; | |
| private final ResourceManagerRuntimeServicesConfiguration rmRuntimeServicesConfig; | |
| private final RpcService rpcService; | |
| private final HighAvailabilityServices highAvailabilityServices; | |
| public class ResourceManagerProcessContext { | |
| public ResourceManagerProcessContext( | |
| Configuration rmConfig, | |
| + ResourceID resourceId, | |
| ResourceManagerRuntimeServicesConfiguration rmRuntimeServicesConfig, | |
| RpcService rpcService, | |
| HighAvailabilityServices highAvailabilityServices, | |
| public class ResourceManagerProcessContext { | |
| SlotManagerMetricGroup slotManagerMetricGroup, | |
| Executor ioExecutor) { | |
| this.rmConfig = checkNotNull(rmConfig); | |
| + this.resourceId = checkNotNull(resourceId); | |
| this.rmRuntimeServicesConfig = checkNotNull(rmRuntimeServicesConfig); | |
| this.rpcService = checkNotNull(rpcService); | |
| this.highAvailabilityServices = checkNotNull(highAvailabilityServices); | |
| public class ResourceManagerProcessContext { | |
| return rmConfig; | |
| } | |
| + public ResourceID getResourceId() { | |
| + return resourceId; | |
| + } | |
| + | |
| public ResourceManagerRuntimeServicesConfiguration getRmRuntimeServicesConfig() { | |
| return rmRuntimeServicesConfig; | |
| } | |
| diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerServiceImpl.java b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerServiceImpl.java | |
| index 2486377f..c0c038fa 100644 | |
| --- a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerServiceImpl.java | |
| +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerServiceImpl.java | |
| public class ResourceManagerServiceImpl implements ResourceManagerService, Leade | |
| this.leaderSessionID = newLeaderSessionID; | |
| this.leaderResourceManager = | |
| - resourceManagerFactory.createResourceManager( | |
| - rmProcessContext, newLeaderSessionID, ResourceID.generate()); | |
| + resourceManagerFactory.createResourceManager(rmProcessContext, newLeaderSessionID); | |
| final ResourceManager<?> newLeaderResourceManager = this.leaderResourceManager; | |
| public class ResourceManagerServiceImpl implements ResourceManagerService, Leade | |
| public static ResourceManagerServiceImpl create( | |
| ResourceManagerFactory<?> resourceManagerFactory, | |
| Configuration configuration, | |
| + ResourceID resourceId, | |
| RpcService rpcService, | |
| HighAvailabilityServices highAvailabilityServices, | |
| HeartbeatServices heartbeatServices, | |
| public class ResourceManagerServiceImpl implements ResourceManagerService, Leade | |
| resourceManagerFactory, | |
| resourceManagerFactory.createResourceManagerProcessContext( | |
| configuration, | |
| + resourceId, | |
| rpcService, | |
| highAvailabilityServices, | |
| heartbeatServices, | |
| diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerConfiguration.java b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerConfiguration.java | |
| index bae9b60c..d0780969 100644 | |
| --- a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerConfiguration.java | |
| +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerConfiguration.java | |
| public class TaskManagerConfiguration implements TaskManagerRuntimeInfo { | |
| private final String taskManagerExternalAddress; | |
| + private final File tmpWorkingDirectory; | |
| + | |
| private final RetryingRegistrationConfiguration retryingRegistrationConfiguration; | |
| public TaskManagerConfiguration( | |
| public class TaskManagerConfiguration implements TaskManagerRuntimeInfo { | |
| @Nullable String taskManagerStdoutPath, | |
| @Nullable String taskManagerLogDir, | |
| String taskManagerExternalAddress, | |
| + File tmpWorkingDirectory, | |
| RetryingRegistrationConfiguration retryingRegistrationConfiguration) { | |
| this.numberSlots = numberSlots; | |
| public class TaskManagerConfiguration implements TaskManagerRuntimeInfo { | |
| this.taskManagerStdoutPath = taskManagerStdoutPath; | |
| this.taskManagerLogDir = taskManagerLogDir; | |
| this.taskManagerExternalAddress = taskManagerExternalAddress; | |
| + this.tmpWorkingDirectory = tmpWorkingDirectory; | |
| this.retryingRegistrationConfiguration = retryingRegistrationConfiguration; | |
| } | |
| public class TaskManagerConfiguration implements TaskManagerRuntimeInfo { | |
| return taskManagerExternalAddress; | |
| } | |
| + @Override | |
| + public File getTmpWorkingDirectory() { | |
| + return tmpWorkingDirectory; | |
| + } | |
| + | |
| public RetryingRegistrationConfiguration getRetryingRegistrationConfiguration() { | |
| return retryingRegistrationConfiguration; | |
| } | |
| public class TaskManagerConfiguration implements TaskManagerRuntimeInfo { | |
| public static TaskManagerConfiguration fromConfiguration( | |
| Configuration configuration, | |
| TaskExecutorResourceSpec taskExecutorResourceSpec, | |
| - String externalAddress) { | |
| + String externalAddress, | |
| + File tmpWorkingDirectory) { | |
| int numberSlots = configuration.getInteger(TaskManagerOptions.NUM_TASK_SLOTS, 1); | |
| if (numberSlots == -1) { | |
| public class TaskManagerConfiguration implements TaskManagerRuntimeInfo { | |
| taskManagerStdoutPath, | |
| taskManagerLogDir, | |
| externalAddress, | |
| + tmpWorkingDirectory, | |
| retryingRegistrationConfiguration); | |
| } | |
| } | |
| diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java | |
| index 9d1e0483..2ebccca4 100644 | |
| --- a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java | |
| +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java | |
| import org.apache.flink.runtime.blob.TaskExecutorBlobService; | |
| import org.apache.flink.runtime.clusterframework.types.ResourceID; | |
| import org.apache.flink.runtime.entrypoint.ClusterEntrypointUtils; | |
| import org.apache.flink.runtime.entrypoint.FlinkParseException; | |
| +import org.apache.flink.runtime.entrypoint.WorkingDirectory; | |
| import org.apache.flink.runtime.externalresource.ExternalResourceInfoProvider; | |
| import org.apache.flink.runtime.externalresource.ExternalResourceUtils; | |
| import org.apache.flink.runtime.heartbeat.HeartbeatServices; | |
| import org.apache.flink.util.concurrent.FutureUtils; | |
| import org.slf4j.Logger; | |
| import org.slf4j.LoggerFactory; | |
| +import java.io.IOException; | |
| import java.lang.reflect.UndeclaredThrowableException; | |
| import java.net.InetAddress; | |
| import java.time.Duration; | |
| public class TaskManagerRunner implements FatalErrorHandler { | |
| private final TaskExecutorService taskExecutorService; | |
| + private final WorkingDirectory workingDirectory; | |
| + | |
| private final CompletableFuture<Result> terminationFuture; | |
| private final RpcSystem rpcSystem; | |
| public class TaskManagerRunner implements FatalErrorHandler { | |
| getTaskManagerResourceID( | |
| configuration, rpcService.getAddress(), rpcService.getPort()); | |
| + this.workingDirectory = | |
| + ClusterEntrypointUtils.createTaskManagerWorkingDirectory(configuration, resourceId); | |
| + | |
| + LOG.info("Using working directory: {}", workingDirectory); | |
| + | |
| HeartbeatServices heartbeatServices = HeartbeatServices.fromConfiguration(configuration); | |
| metricRegistry = | |
| public class TaskManagerRunner implements FatalErrorHandler { | |
| blobCacheService, | |
| false, | |
| externalResourceInfoProvider, | |
| + workingDirectory, | |
| this); | |
| this.terminationFuture = new CompletableFuture<>(); | |
| public class TaskManagerRunner implements FatalErrorHandler { | |
| FutureUtils.composeAfterwards( | |
| taskManagerTerminationFuture, this::shutDownServices); | |
| + final CompletableFuture<Void> workingDirCleanupFuture; | |
| + | |
| + if (terminationResult == Result.SUCCESS) { | |
| + workingDirCleanupFuture = | |
| + FutureUtils.runAfterwards( | |
| + serviceTerminationFuture, this::deleteWorkingDir); | |
| + } else { | |
| + // keep the working directory in case of a failure | |
| + workingDirCleanupFuture = serviceTerminationFuture; | |
| + } | |
| + | |
| final CompletableFuture<Void> rpcSystemClassLoaderCloseFuture = | |
| - FutureUtils.runAfterwards(serviceTerminationFuture, rpcSystem::close); | |
| + FutureUtils.runAfterwards(workingDirCleanupFuture, rpcSystem::close); | |
| rpcSystemClassLoaderCloseFuture.whenComplete( | |
| (Void ignored, Throwable throwable) -> { | |
| public class TaskManagerRunner implements FatalErrorHandler { | |
| return terminationFuture; | |
| } | |
| + private void deleteWorkingDir() throws IOException { | |
| + if (workingDirectory != null) { | |
| + workingDirectory.delete(); | |
| + } | |
| + } | |
| + | |
| private CompletableFuture<Void> shutDownServices() { | |
| synchronized (lock) { | |
| Collection<CompletableFuture<Void>> terminationFutures = new ArrayList<>(3); | |
| public class TaskManagerRunner implements FatalErrorHandler { | |
| BlobCacheService blobCacheService, | |
| boolean localCommunicationOnly, | |
| ExternalResourceInfoProvider externalResourceInfoProvider, | |
| + WorkingDirectory workingDirectory, | |
| FatalErrorHandler fatalErrorHandler) | |
| throws Exception { | |
| public class TaskManagerRunner implements FatalErrorHandler { | |
| blobCacheService, | |
| localCommunicationOnly, | |
| externalResourceInfoProvider, | |
| + workingDirectory, | |
| fatalErrorHandler); | |
| return TaskExecutorToServiceAdapter.createFor(taskExecutor); | |
| public class TaskManagerRunner implements FatalErrorHandler { | |
| TaskExecutorBlobService taskExecutorBlobService, | |
| boolean localCommunicationOnly, | |
| ExternalResourceInfoProvider externalResourceInfoProvider, | |
| + WorkingDirectory workingDirectory, | |
| FatalErrorHandler fatalErrorHandler) | |
| throws Exception { | |
| public class TaskManagerRunner implements FatalErrorHandler { | |
| resourceID, | |
| externalAddress, | |
| localCommunicationOnly, | |
| - taskExecutorResourceSpec); | |
| + taskExecutorResourceSpec, | |
| + workingDirectory); | |
| Tuple2<TaskManagerMetricGroup, MetricGroup> taskManagerMetricGroup = | |
| MetricUtils.instantiateTaskManagerMetricGroup( | |
| public class TaskManagerRunner implements FatalErrorHandler { | |
| TaskManagerConfiguration taskManagerConfiguration = | |
| TaskManagerConfiguration.fromConfiguration( | |
| - configuration, taskExecutorResourceSpec, externalAddress); | |
| + configuration, | |
| + taskExecutorResourceSpec, | |
| + externalAddress, | |
| + workingDirectory.getTmpDirectory()); | |
| String metricQueryServiceAddress = metricRegistry.getMetricQueryServiceGatewayRpcAddress(); | |
| public class TaskManagerRunner implements FatalErrorHandler { | |
| BlobCacheService blobCacheService, | |
| boolean localCommunicationOnly, | |
| ExternalResourceInfoProvider externalResourceInfoProvider, | |
| + WorkingDirectory workingDirectory, | |
| FatalErrorHandler fatalErrorHandler) | |
| throws Exception; | |
| } | |
| diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerServicesConfiguration.java b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerServicesConfiguration.java | |
| index 65963586..1f163828 100644 | |
| --- a/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerServicesConfiguration.java | |
| +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerServicesConfiguration.java | |
| import org.apache.flink.configuration.NettyShuffleEnvironmentOptions; | |
| import org.apache.flink.configuration.TaskManagerOptions; | |
| import org.apache.flink.runtime.clusterframework.types.ResourceID; | |
| import org.apache.flink.runtime.entrypoint.ClusterEntrypointUtils; | |
| +import org.apache.flink.runtime.entrypoint.WorkingDirectory; | |
| import org.apache.flink.runtime.execution.librarycache.FlinkUserCodeClassLoaders; | |
| import org.apache.flink.runtime.registration.RetryingRegistrationConfiguration; | |
| import org.apache.flink.runtime.util.ConfigurationParserUtils; | |
| import org.apache.flink.util.NetUtils; | |
| import javax.annotation.Nullable; | |
| +import java.io.File; | |
| import java.net.InetAddress; | |
| import java.util.Optional; | |
| public class TaskManagerServicesConfiguration { | |
| * accessible | |
| * @param localCommunicationOnly True if only local communication is possible. Use only in cases | |
| * where only one task manager runs. | |
| + * @param taskExecutorResourceSpec resource specification of the TaskManager to start | |
| + * @param workingDirectory working directory of the TaskManager | |
| * @return configuration of task manager services used to create them | |
| */ | |
| public static TaskManagerServicesConfiguration fromConfiguration( | |
| public class TaskManagerServicesConfiguration { | |
| ResourceID resourceID, | |
| String externalAddress, | |
| boolean localCommunicationOnly, | |
| - TaskExecutorResourceSpec taskExecutorResourceSpec) | |
| + TaskExecutorResourceSpec taskExecutorResourceSpec, | |
| + WorkingDirectory workingDirectory) | |
| throws Exception { | |
| - final String[] tmpDirs = ConfigurationUtils.parseTempDirectories(configuration); | |
| String[] localStateRootDir = ConfigurationUtils.parseLocalStateDirectories(configuration); | |
| + | |
| if (localStateRootDir.length == 0) { | |
| - // default to temp dirs. | |
| - localStateRootDir = tmpDirs; | |
| + final File localStateDir = workingDirectory.getLocalStateDirectory(); | |
| + | |
| + localStateRootDir = new String[] {localStateDir.getAbsolutePath()}; | |
| } | |
| boolean localRecoveryMode = configuration.getBoolean(CheckpointingOptions.LOCAL_RECOVERY); | |
| public class TaskManagerServicesConfiguration { | |
| final int numIoThreads = ClusterEntrypointUtils.getPoolSize(configuration); | |
| + final String[] tmpDirs = ConfigurationUtils.parseTempDirectories(configuration); | |
| + | |
| return new TaskManagerServicesConfiguration( | |
| configuration, | |
| resourceID, | |
| diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/TaskManagerRuntimeInfo.java b/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/TaskManagerRuntimeInfo.java | |
| index 200cc533..6e3c886b 100644 | |
| --- a/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/TaskManagerRuntimeInfo.java | |
| +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/taskmanager/TaskManagerRuntimeInfo.java | |
| import org.apache.flink.configuration.Configuration; | |
| import org.apache.flink.configuration.TaskManagerOptions; | |
| import org.apache.flink.runtime.taskexecutor.TaskExecutor; | |
| +import java.io.File; | |
| + | |
| /** Interface to access {@link TaskExecutor} information. */ | |
| public interface TaskManagerRuntimeInfo { | |
| public interface TaskManagerRuntimeInfo { | |
| default String getTaskManagerBindAddress() { | |
| return getConfiguration().getString(TaskManagerOptions.BIND_HOST); | |
| } | |
| + | |
| + /** | |
| + * Gets the temporary working directory of the TaskManager instance. | |
| + * | |
| + * @return The temporary working directory of the TaskManager. | |
| + */ | |
| + File getTmpWorkingDirectory(); | |
| } | |
| diff --git a/flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/EmbeddedRocksDBStateBackend.java b/flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/EmbeddedRocksDBStateBackend.java | |
| index 7fa2e507..cb7e8d94 100644 | |
| --- a/flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/EmbeddedRocksDBStateBackend.java | |
| +++ b/flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/EmbeddedRocksDBStateBackend.java | |
| public class EmbeddedRocksDBStateBackend extends AbstractManagedMemoryStateBacke | |
| // initialize the paths where the local RocksDB files should be stored | |
| if (localRocksDbDirectories == null) { | |
| - // initialize from the temp directories | |
| - initializedDbBasePaths = env.getIOManager().getSpillingDirectories(); | |
| + initializedDbBasePaths = new File[] {env.getTaskManagerInfo().getTmpWorkingDirectory()}; | |
| } else { | |
| List<File> dirs = new ArrayList<>(localRocksDbDirectories.length); | |
| StringBuilder errorMessage = new StringBuilder(); | |
| public class EmbeddedRocksDBStateBackend extends AbstractManagedMemoryStateBacke | |
| // first, make sure that the RocksDB JNI library is loaded | |
| // we do this explicitly here to have better error handling | |
| - String tempDir = env.getTaskManagerInfo().getTmpDirectories()[0]; | |
| + String tempDir = env.getTaskManagerInfo().getTmpWorkingDirectory().getAbsolutePath(); | |
| ensureRocksDBIsLoaded(tempDir); | |
| // replace all characters that are not legal for filenames with underscore | |
| diff --git a/flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/RocksDBOptions.java b/flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/RocksDBOptions.java | |
| index 0cf36028..f9d602d8 100644 | |
| --- a/flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/RocksDBOptions.java | |
| +++ b/flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/RocksDBOptions.java | |
| package org.apache.flink.contrib.streaming.state; | |
| import org.apache.flink.annotation.docs.Documentation; | |
| +import org.apache.flink.configuration.ClusterOptions; | |
| import org.apache.flink.configuration.ConfigOption; | |
| import org.apache.flink.configuration.ConfigOptions; | |
| import org.apache.flink.configuration.MemorySize; | |
| +import org.apache.flink.configuration.description.Description; | |
| +import org.apache.flink.configuration.description.TextElement; | |
| import static org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend.PriorityQueueStateType.ROCKSDB; | |
| import static org.apache.flink.contrib.streaming.state.PredefinedOptions.DEFAULT; | |
| public class RocksDBOptions { | |
| .noDefaultValue() | |
| .withDeprecatedKeys("state.backend.rocksdb.checkpointdir") | |
| .withDescription( | |
| - "The local directory (on the TaskManager) where RocksDB puts its files."); | |
| + Description.builder() | |
| + .text( | |
| + "The local directory (on the TaskManager) where RocksDB puts its files. Per default, it will be <WORKING_DIR>/tmp. See %s for more details.", | |
| + TextElement.code( | |
| + ClusterOptions | |
| + .TASK_MANAGER_PROCESS_WORKING_DIR_BASE | |
| + .key())) | |
| + .build()); | |
| /** Choice of timer service implementation. */ | |
| @Documentation.Section(Documentation.Sections.STATE_BACKEND_ROCKSDB) | |