rdblue commented on a change in pull request #144: Delete temporary metadata
file when rename fails.
URL: https://github.com/apache/incubator-iceberg/pull/144#discussion_r273128073
##########
File path:
core/src/main/java/org/apache/iceberg/hadoop/HadoopTableOperations.java
##########
@@ -211,6 +203,43 @@ private int readVersionHint() {
}
}
+ /**
+ * Renames the source file to destination, using the provided file system.
If rename failed,
+ * the source file will be attempted to deleted.
+ *
+ * @param fs the filesystem used for the rename
+ * @param src the source file
+ * @param dst the destination file
+ */
+ private void renameToFinal(final FileSystem fs, final Path src, final Path
dst) {
+ try {
+ if (!fs.rename(src, dst)) {
+ final CommitFailedException cfe = new CommitFailedException(
+ "Failed to commit changes using rename: %s", dst);
+ deleteFileNoThrow(src, cfe);
+ throw cfe;
+ }
+ } catch (IOException e) {
+ final CommitFailedException cfe = new CommitFailedException(e,
+ "Failed to commit changes using rename: %s", dst);
+ deleteFileNoThrow(src, cfe);
+ throw cfe;
+ }
+ }
+
+ /**
+ * Deletes the file from the file system. Any RuntimeException will be
suppressed.
+ *
+ * @param tempMetadataFile the file to be deleted.
+ */
+ private void deleteFileNoThrow(Path tempMetadataFile, CommitFailedException
cfe) {
Review comment:
This looks good to me now. I'll take a little duplicate code that is simple
over mixing concerns in a method.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]