Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,7 @@ protected void doCommit(TableMetadata base, TableMetadata metadata) {
throw new RuntimeException("Interrupted during commit", e);

} finally {
if (threw) {
// if anything went wrong, clean up the uncommitted metadata file
io().deleteFile(newMetadataLocation);
}
unlock(lockId);
cleanupMetadataAndUnlock(threw, newMetadataLocation, lockId);
}
}

Expand Down Expand Up @@ -367,6 +363,20 @@ private long acquireLock() throws UnknownHostException, TException, InterruptedE
return lockId;
}

private void cleanupMetadataAndUnlock(boolean errorThrown, String metadataLocation, Optional<Long> lockId) {
try {
if (errorThrown) {
// if anything went wrong, clean up the uncommitted metadata file
io().deleteFile(metadataLocation);
}
} catch (RuntimeException e) {
LOG.error("Fail to cleanup metadata file at {}", metadataLocation, e);
throw e;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of Throw within a Catch.
Maybe you can wrap it in something else.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine because we don't want to wrap or modify the original exception, and it is helpful to log the metadata location that was not correctly deleted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may leverage runSafely that was added recently.

    ExceptionUtil.runSafely(
        () -> {
          if (errorThrown) {
            // if anything went wrong, clean up the uncommitted metadata file
            io().deleteFile(metadataLocation);
          }
          return Void.TYPE;
        },
        e -> LOG.error("Failed to cleanup metadata file at {}", metadataLocation, e),
        () -> unlock(lockId));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} finally {
unlock(lockId);
}
}

private void unlock(Optional<Long> lockId) {
if (lockId.isPresent()) {
try {
Expand Down