-
Notifications
You must be signed in to change notification settings - Fork 40
Skip commit-state for read-only transactions in Consensus Commit #2765
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
Changes from 1 commit
19aac3d
e7cefba
6c6299d
a40322c
e783b13
2c13b1c
a303699
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,42 +106,52 @@ private void waitBeforePreparationSnapshotHookFuture( | |
| } | ||
| } | ||
|
|
||
| public void commit(Snapshot snapshot) throws CommitException, UnknownTransactionStatusException { | ||
| public void commit(Snapshot snapshot, boolean readOnly) | ||
| throws CommitException, UnknownTransactionStatusException { | ||
| boolean hasNoWritesAndDeletesInSnapshot = readOnly || snapshot.hasNoWritesAndDeletes(); | ||
|
|
||
| Optional<Future<Void>> snapshotHookFuture = invokeBeforePreparationSnapshotHook(snapshot); | ||
| try { | ||
| prepare(snapshot); | ||
| } catch (PreparationException e) { | ||
| safelyCallOnFailureBeforeCommit(snapshot); | ||
| abortState(snapshot.getId()); | ||
| rollbackRecords(snapshot); | ||
| if (e instanceof PreparationConflictException) { | ||
| throw new CommitConflictException(e.getMessage(), e, e.getTransactionId().orElse(null)); | ||
|
|
||
| if (!hasNoWritesAndDeletesInSnapshot) { | ||
| try { | ||
| prepare(snapshot); | ||
| } catch (PreparationException e) { | ||
| safelyCallOnFailureBeforeCommit(snapshot); | ||
| abortState(snapshot.getId()); | ||
| rollbackRecords(snapshot); | ||
| if (e instanceof PreparationConflictException) { | ||
| throw new CommitConflictException(e.getMessage(), e, e.getTransactionId().orElse(null)); | ||
| } | ||
| throw new CommitException(e.getMessage(), e, e.getTransactionId().orElse(null)); | ||
| } catch (Exception e) { | ||
| safelyCallOnFailureBeforeCommit(snapshot); | ||
| throw e; | ||
| } | ||
| throw new CommitException(e.getMessage(), e, e.getTransactionId().orElse(null)); | ||
| } catch (Exception e) { | ||
| safelyCallOnFailureBeforeCommit(snapshot); | ||
| throw e; | ||
| } | ||
|
||
|
|
||
| try { | ||
| validate(snapshot); | ||
| } catch (ValidationException e) { | ||
| safelyCallOnFailureBeforeCommit(snapshot); | ||
| abortState(snapshot.getId()); | ||
| rollbackRecords(snapshot); | ||
| if (e instanceof ValidationConflictException) { | ||
| throw new CommitConflictException(e.getMessage(), e, e.getTransactionId().orElse(null)); | ||
| if (!snapshot.hasNoReads()) { | ||
|
||
| try { | ||
| validate(snapshot); | ||
| } catch (ValidationException e) { | ||
| safelyCallOnFailureBeforeCommit(snapshot); | ||
| abortState(snapshot.getId()); | ||
| rollbackRecords(snapshot); | ||
| if (e instanceof ValidationConflictException) { | ||
| throw new CommitConflictException(e.getMessage(), e, e.getTransactionId().orElse(null)); | ||
| } | ||
| throw new CommitException(e.getMessage(), e, e.getTransactionId().orElse(null)); | ||
| } catch (Exception e) { | ||
| safelyCallOnFailureBeforeCommit(snapshot); | ||
| throw e; | ||
| } | ||
| throw new CommitException(e.getMessage(), e, e.getTransactionId().orElse(null)); | ||
| } catch (Exception e) { | ||
| safelyCallOnFailureBeforeCommit(snapshot); | ||
| throw e; | ||
| } | ||
|
||
|
|
||
| waitBeforePreparationSnapshotHookFuture(snapshot, snapshotHookFuture.orElse(null)); | ||
|
|
||
| commitState(snapshot); | ||
| commitRecords(snapshot); | ||
| if (!hasNoWritesAndDeletesInSnapshot) { | ||
| commitState(snapshot); | ||
| commitRecords(snapshot); | ||
| } | ||
|
||
| } | ||
|
|
||
| protected void handleCommitConflict(Snapshot snapshot, Exception cause) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,7 +221,7 @@ DistributedTransaction beginReadOnly(Isolation isolation) { | |
| DistributedTransaction begin(String txId, Isolation isolation, boolean readOnly) { | ||
| checkArgument(!Strings.isNullOrEmpty(txId)); | ||
| checkNotNull(isolation); | ||
| if (isGroupCommitEnabled()) { | ||
| if (!readOnly && isGroupCommitEnabled()) { | ||
| assert groupCommitter != null; | ||
| txId = groupCommitter.reserve(txId); | ||
| } | ||
|
Comment on lines
+235
to
238
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In read-only mode, skip reserving a slot in the group commit. |
||
|
|
||
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.
I think double negative is a bit hard to read.
Since all the usage of
hasNoWritesAndDeletesInSnapshotis with negation (!), how about making the method likehasSomeWritesAndDeletesInSnapshotso that we don't have to negate all the if clauses?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.
Fixed in 6c6299d. Thanks!