Skip to content

Hive: ensure unlock is called when new metadata cannot be deleted#1998

Merged
rdblue merged 1 commit into
apache:masterfrom
jackye1995:hive-unlock
Dec 28, 2020
Merged

Hive: ensure unlock is called when new metadata cannot be deleted#1998
rdblue merged 1 commit into
apache:masterfrom
jackye1995:hive-unlock

Conversation

@jackye1995
Copy link
Copy Markdown
Contributor

wrap io().deleteFile(metadataLocation) in try catch block so that unlock(lockId) must be called in the finally block.

@github-actions github-actions Bot added the hive label Dec 28, 2020
}
} catch (RuntimeException e) {
LOG.error("Fail to cleanup metadata file at {}", metadataLocation, e);
throw e;
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants