-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring the callbacks for the group commit error handling in CommitHandler
#2390
Conversation
with `onFailureBeforeCommit()`
just in case
CommitHandler
CommitHandler
@@ -65,11 +69,9 @@ private Optional<Future<Void>> invokeBeforePreparationSnapshotHook(Snapshot snap | |||
return Optional.of( | |||
beforePreparationSnapshotHook.handle(tableMetadataManager, snapshot.getReadWriteSets())); | |||
} catch (Exception e) { | |||
onFailureBeforeCommit(snapshot); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling this callback first is safe since it doesn't throw any exception.
@@ -104,28 +104,30 @@ public void commit(Snapshot snapshot) throws CommitException, UnknownTransaction | |||
try { | |||
prepare(snapshot); | |||
} catch (PreparationException e) { | |||
onFailureBeforeCommit(snapshot); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the following abortState()
internally calls a method equivalent to onFailureBeforeCommit()
in case of CommitHandlerWithGroupCommit
. So, this change doesn't change the behavior at all. But, I think the callback should be called here for consistent error handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
@@ -65,11 +69,9 @@ private Optional<Future<Void>> invokeBeforePreparationSnapshotHook(Snapshot snap | |||
return Optional.of( | |||
beforePreparationSnapshotHook.handle(tableMetadataManager, snapshot.getReadWriteSets())); | |||
} catch (Exception e) { | |||
onFailureBeforeCommit(snapshot); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For safety, I think we can catch the exception as follow:
onFailureBeforeCommit(snapshot); | |
try { | |
onFailureBeforeCommit(snapshot); | |
} catch (Exception ex) { | |
... | |
} |
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you have a point. On the other hand, I think all the codes calling the callback need the same just-in-case error handling in terms of consistency. So, I wrote this comment https://github.com/scalar-labs/scalardb/pull/2390/files#diff-80b71c10ff00c8a739d8aec837a1730b5470df99295bebb354033c9aefc33bbaR55-R56 so that we don't need such a just-in-case error handling. But if you think the comment isn't enough, I'm okay to add the error handling to all the codes calling the callback. Either is fine with me 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brfrn169 On second thought, I'll follow your suggestion since trusting an overridden callback is a bit too optimistic and the comment doesn't guarantee a callback won't throw an exception. Let me update the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed it in 782cb03
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
logger.warn( | ||
"Unexpectedly failed to remove the snapshot ID from the group committer. ID: {}", id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit:
logger.warn( | |
"Unexpectedly failed to remove the snapshot ID from the group committer. ID: {}", id); | |
logger.warn( | |
"Unexpectedly failed to remove the snapshot ID from the group committer. ID: {}", id, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
Description
In the current implementation,
CommitHandler
hasonPrepareFailure()
andonValidateFailure()
, but there is no need to separate them. This PR merges them to make it simpler.Related issues and/or PRs
None.
Changes made
onPrepareFailure()
andonValidateFailure()
intoonFailureBeforeCommit()
Checklist
Additional notes (optional)
None
Release notes
N/A