Github user tillrohrmann commented on a diff in the pull request:
https://github.com/apache/flink/pull/1687#discussion_r53780485
--- Diff:
flink-streaming-java/src/main/java/org/apache/flink/streaming/util/HDFSCopyFromLocal.java
---
@@ -17,41 +17,50 @@
*/
package org.apache.flink.streaming.util;
-import org.apache.flink.util.ExternalProcessRunner;
+import org.apache.flink.runtime.fs.hdfs.HadoopFileSystem;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import java.io.DataInputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
/**
- * Utility for copying from local file system to a HDFS {@link FileSystem}
in an external process.
- * This is required since {@code FileSystem.copyFromLocalFile} does not
like being interrupted.
+ * Utility for copying from local file system to a HDFS {@link FileSystem}.
*/
public class HDFSCopyFromLocal {
- public static void main(String[] args) throws Exception {
- String hadoopConfPath = args[0];
- String localBackupPath = args[1];
- String backupUri = args[2];
-
- Configuration hadoopConf = new Configuration();
- try (DataInputStream in = new DataInputStream(new
FileInputStream(hadoopConfPath))) {
- hadoopConf.readFields(in);
- }
- FileSystem fs = FileSystem.get(new URI(backupUri), hadoopConf);
+ public static void copyFromLocal(final File localPath,
+ final URI remotePath) throws Exception {
+ // Do it in another Thread because HDFS can deadlock if being
interrupted while copying
+ String threadName = "HDFS Copy from " + localPath + " to " +
remotePath;
- fs.copyFromLocalFile(new Path(localBackupPath), new
Path(backupUri));
- }
+ final List<Exception> asyncException = new ArrayList<>();
--- End diff --
Agreed. `ArrayList` will allocate an array of 10 elements when you
initialize the ArrayList without an initial capacity. So either initialize the
ArrayList with a size of `1` or use Robert's approach.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---