[ 
https://issues.apache.org/jira/browse/BEAM-5036?focusedWorklogId=160526&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-160526
 ]

ASF GitHub Bot logged work on BEAM-5036:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 30/Oct/18 10:40
            Start Date: 30/Oct/18 10:40
    Worklog Time Spent: 10m 
      Work Description: iemejia commented on a change in pull request #6843: 
[BEAM-5036] Optimize the FileBasedSink WriteOperation.moveToOutput()
URL: https://github.com/apache/beam/pull/6843#discussion_r229241481
 
 

 ##########
 File path: 
sdks/java/io/hadoop-file-system/src/main/java/org/apache/beam/sdk/io/hdfs/HadoopFileSystem.java
 ##########
 @@ -179,46 +181,61 @@ protected void rename(
       throws IOException {
     for (int i = 0; i < srcResourceIds.size(); ++i) {
 
+      Path src = srcResourceIds.get(i).toPath();
+      Path dest = destResourceIds.get(i).toPath();
+
       // rename in HDFS requires the target directory to exist or silently 
fails (BEAM-4861)
-      Path targetDirectory = destResourceIds.get(i).toPath().getParent();
-      if (!fileSystem.exists(targetDirectory)) {
+      mkdirs(dest);
+
+      boolean success = fileSystem.rename(src, dest);
+
+      // If the failure was due to the file already existing, delete and retry 
(BEAM-5036).
+      // This should be the exceptional case, so handle here rather than incur 
the overhead of testing first
+      if (!success && fileSystem.exists(src) && fileSystem.exists(dest)) {
         LOG.debug(
-            String.format(
-                LOG_CREATE_DIRECTORY, 
Path.getPathWithoutSchemeAndAuthority(targetDirectory)));
-        boolean success = fileSystem.mkdirs(targetDirectory);
-        if (!success) {
-          throw new IOException(
-              String.format(
-                  "Unable to create target directory %s. No further 
information provided by underlying filesystem.",
-                  targetDirectory));
-        }
+            String.format(LOG_DELETING_EXISTING_FILE, 
Path.getPathWithoutSchemeAndAuthority(dest)));
 
 Review comment:
   I am puzzled about spotless not complaining about this whitespace. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 160526)
    Time Spent: 14h  (was: 13h 50m)

> Optimize FileBasedSink's WriteOperation.moveToOutput()
> ------------------------------------------------------
>
>                 Key: BEAM-5036
>                 URL: https://issues.apache.org/jira/browse/BEAM-5036
>             Project: Beam
>          Issue Type: Improvement
>          Components: io-java-files
>    Affects Versions: 2.5.0
>            Reporter: Jozef Vilcek
>            Assignee: Tim Robertson
>            Priority: Major
>          Time Spent: 14h
>  Remaining Estimate: 0h
>
> moveToOutput() methods in FileBasedSink.WriteOperation implements move by 
> copy+delete. It would be better to use a rename() which can be much more 
> effective for some filesystems.
> Filesystem must support cross-directory rename. BEAM-4861 is related to this 
> for the case of HDFS filesystem.
> Feature was discussed here:
> http://mail-archives.apache.org/mod_mbox/beam-dev/201807.mbox/%3CCAF9t7_4Mp54pQ+vRrJrBh9Vx0=uaknupzd_qdh_qdm9vxll...@mail.gmail.com%3E



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to