-
Notifications
You must be signed in to change notification settings - Fork 40
Support begin in read-only mode for Consensus Commit transactions #2739
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
Support begin in read-only mode for Consensus Commit transactions #2739
Conversation
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.
Pull Request Overview
Adds support for starting Consensus Commit transactions in read-only mode by introducing a readOnly flag throughout the transaction stack, updating handlers, snapshots, managers, and tests accordingly.
- Propagate a
readOnlyboolean toCrudHandlerand suppress write-set and overlap verification when true - Introduce
beginReadOnly/startReadOnlymethods inConsensusCommitManagerand wrap read-only transactions inReadOnlyDistributedTransaction - Update tests to cover read-only behavior and adjust constructors to accept the new flag
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitIntegrationTestBase.java | Removed placeholder disabled tests for read-only mode |
| core/src/test/java/com/scalar/db/transaction/consensuscommit/CrudHandlerTest.java | Added unit tests for read-only get and scan paths |
| core/src/test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitManagerTest.java | Added tests for beginReadOnly and startReadOnly, updated spies to expect read-only flag |
| core/src/main/java/com/scalar/db/transaction/consensuscommit/TwoPhaseConsensusCommitManager.java | Pass false for readOnly when creating two-phase transactions |
| core/src/main/java/com/scalar/db/transaction/consensuscommit/Snapshot.java | Reordered and documented the read/get/scan/write/delete sets |
| core/src/main/java/com/scalar/db/transaction/consensuscommit/CrudHandler.java | Added readOnly field, suppressed read-set writes and overlap checks when in read-only mode |
| core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitManager.java | Added beginReadOnly / startReadOnly, extended executeTransaction to handle read-only paths |
Comments suppressed due to low confidence (4)
integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitIntegrationTestBase.java:929
- The removed placeholder tests for read-only mode indicate missing integration coverage. Consider adding end-to-end tests that verify
getandscanbehavior under a read-only Consensus Commit transaction against actual storage to ensure the feature is fully validated.
@Disabled("Implement later")
core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitManager.java:151
- [nitpick] Public API methods
beginReadOnlyandstartReadOnlylack Javadoc. Adding Javadoc comments explaining that these methods start a snapshot-isolation read-only transaction would improve discoverability and maintain consistency with existing methods.
public DistributedTransaction beginReadOnly() {
core/src/main/java/com/scalar/db/transaction/consensuscommit/CrudHandler.java:59
- [nitpick] The
boolean readOnlyflag in this constructor can be ambiguous at call sites (it's not obvious whattrueorfalsemeans). Consider replacing it with an enum or builder pattern (e.g.,.readOnly()vs.readWrite()) to make instantiation intent clearer.
public CrudHandler(
storage,
snapshot,
tableMetadataManager,
isIncludeMetadataEnabled,
parallelExecutor,
boolean readOnly) {
core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitManager.java:431
- [nitpick] The
executeTransactionmethod uses aboolean readOnlyflag to choose betweenbeginandbeginReadOnly. You might simplify the API by splitting into two overloads (one for read/write, one for read-only) or passing an enum instead of a raw boolean to reduce the risk of passing the wrong mode.
private <R> R executeTransaction(
ThrowableFunction<DistributedTransaction, R, TransactionException> throwableFunction,
| getTable().ifPresent(consensus::withTable); | ||
| return consensus; | ||
| if (readOnly) { | ||
| transaction = new ReadOnlyDistributedTransaction(transaction); |
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.
Wrap the transaction object with ReadOnlyDistributedTransaction for read-only transactions.
| } | ||
| } | ||
|
|
||
| private void putIntoReadSetInSnapshot(Snapshot.Key key, Optional<TransactionResult> result) { |
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.
As an optimization, in read-only mode, we don't need to add the result to the read set, since the read set is only used for write operations.
| } | ||
| } | ||
|
|
||
| private void verifyNoOverlap(Scan scan, Map<Snapshot.Key, TransactionResult> results) { |
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.
Also, we don't need to verify the overlap in read-only mode, since there are no write operations.
komamitsu
left a comment
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! 👍
| private final TransactionTableMetadataManager tableMetadataManager; | ||
| private final ParallelExecutor parallelExecutor; | ||
|
|
||
| // The read set stores information about the records that are read in this transaction. This is |
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.
👍
feeblefakie
left a comment
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!
Torch3333
left a comment
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
This PR adds support for beginning a transaction in read-only mode for Consensus Commit transactions.
Note that this feature is being developed in the
support-begin-in-read-only-modefeature branch.Related issues and/or PRs
Changes made
Added some inline comments. Please take a look for the details.
Checklist
Additional notes (optional)
N/A
Release notes
N/A