Github user zsxwing commented on a diff in the pull request: https://github.com/apache/spark/pull/18565#discussion_r126259778 --- Diff: common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/OneForOneBlockFetcher.java --- @@ -151,15 +152,27 @@ private void failRemainingBlocks(String[] failedBlockIds, Throwable e) { } } + private static synchronized boolean renameFile(File src, File dest) { + if (dest.exists()) { + if (!dest.delete()) { --- End diff -- Here is what I suggest: ``` private boolean rename() { synchronized (targetFile) { // Lock to avoid renaming at the same time. `File.renameTo` doesn't promise to fail on // all file systems when the target file exists. if (!targetFile.exists()) { if (!tmpFile.renameTo(targetFile)) { if (!targetFile.exists()) { return false; } } } } return true; } @Override public void onComplete(String streamId) throws IOException { channel.close(); if (!rename()) { onFailure(streamId, new Exception("Failed renaming " + tmpFile.getAbsolutePath() + " to " + targetFile.getAbsolutePath())); return; } ManagedBuffer buffer = new FileSegmentManagedBuffer(transportConf, targetFile, 0, targetFile.length()); tmpFile.delete(); listener.onBlockFetchSuccess(blockIds[chunkIndex], buffer); } ```
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org