[
https://issues.apache.org/jira/browse/BEAM-5036?focusedWorklogId=149797&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-149797
]
ASF GitHub Bot logged work on BEAM-5036:
----------------------------------------
Author: ASF GitHub Bot
Created on: 30/Sep/18 15:17
Start Date: 30/Sep/18 15:17
Worklog Time Spent: 10m
Work Description: timrobertson100 commented on a change in pull request
#6289: [BEAM-5036] Optimize the FileBasedSink WriteOperation.moveToOutput()
URL: https://github.com/apache/beam/pull/6289#discussion_r221462801
##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileSystems.java
##########
@@ -322,8 +330,71 @@ public static void rename(
if (srcToRename.isEmpty()) {
return;
}
- getFileSystemInternal(srcToRename.iterator().next().getScheme())
- .rename(srcToRename, destToRename);
+
+ boolean replaceExisting =
+ options.contains(MoveOptions.StandardMoveOptions.REPLACE_EXISTING) ?
true : false;
+ rename(
+ getFileSystemInternal(srcToRename.iterator().next().getScheme()),
+ srcToRename,
+ destToRename,
+ replaceExisting);
+ }
+
+ /**
+ * Executes a rename of the src which all must exist using the provided
filesystem.
+ *
+ * <p>If replaceExisting is enabled and filesystem throws {code
FileAlreadyExistsException} then
+ * an attempt to delete the destination is made and the rename is retried.
Some filesystem
+ * implementations may apply this automatically without throwing.
+ *
+ * @param fileSystem The filesystem in use
+ * @param srcResourceIds The source resources to move
+ * @param destResourceIds The destinations for the sources to move to (must
be same length as
+ * srcResourceIds)
+ * @param replaceExisting If existing files in destination should be
overwritten
+ * @throws IOException If the rename could not be completed
+ */
+ @VisibleForTesting
+ static void rename(
+ FileSystem fileSystem,
+ List<ResourceId> srcResourceIds,
+ List<ResourceId> destResourceIds,
+ boolean replaceExisting)
+ throws IOException {
+ try {
+ fileSystem.rename(srcResourceIds, destResourceIds);
+ } catch (FileAlreadyExistsException e) {
+ if (replaceExisting) {
+
+ // The filesystem has reported a target that existed prior to calling
rename. Some files may
+ // have been moved successfully but there are no guarantees on which
as some filesystems
+ // batch and run in parallel asynchronously. We determine the state
and delete all dest files
+ // still existing in src and issue a retry. This will ignore all non
existing src files.
+
+ List<MatchResult> matchResultsSrc = matchResources(srcResourceIds);
+ List<MatchResult> matchResultsDest = matchResources(destResourceIds);
+ List<ResourceId> destResourceIdsToDelete = new ArrayList<>();
+ List<ResourceId> srcResourceIdsToRetry = new ArrayList<>();
+ List<ResourceId> destResourceIdsToRetry = new ArrayList<>();
+
+ for (int i = 0; i < matchResultsSrc.size(); ++i) {
+ boolean srcExists =
!matchResultsSrc.get(i).status().equals(Status.NOT_FOUND);
+ boolean destExists =
!matchResultsDest.get(i).status().equals(Status.NOT_FOUND);
Review comment:
I will do so if they aren't.
----------------------------------------------------------------
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: 149797)
Time Spent: 6h 50m (was: 6h 40m)
> 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: 6h 50m
> 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)