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_r272658713
##########
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:
I think it would be cleaner if this caught and returned the exception
instead of passing the commit exception into this method. This doesn't need to
be more complicated when it can just return the RuntimeException, if there was
one.
I would change it to this:
```java
private RuntimeException tryDelete(Path location) {
try {
io().deleteFile(location.toString);
return null;
} catch (RuntimeException re) {
return re;
}
}
```
Then the caller should check whether there is a suppressed exception and add
it to the failure that will be thrown. This method doesn't need to know about
that concern.
----------------------------------------------------------------
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]