-
Notifications
You must be signed in to change notification settings - Fork 40
Add READ_COMMITTED isolation #2803
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
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
This PR adds READ_COMMITTED isolation support to the consensus commit transaction module while refactoring configuration usage. Key changes include:
- Adding READ_COMMITTED to the Isolation enum and modifying related logic in recovery and CRUD handling.
- Refactoring ConsensusCommitManager and test classes to use the new isolation configuration.
- Updating exception handling in commit and preparation flows to correctly propagate conflict errors.
Reviewed Changes
Copilot reviewed 13 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| integration-test/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitNullMetadataIntegrationTestBase.java | Removed the consensusCommitConfig parameter and now passing the isolation value directly. |
| core/src/test/java/com/scalar/db/transaction/consensuscommit/TwoPhaseConsensusCommitTest.java | Added tests for the new exception mapping (e.g. PreparationConflictException). |
| core/src/test/java/com/scalar/db/transaction/consensuscommit/RecoveryExecutorTest.java | Updated tests to validate the new recovery types for different isolation levels. |
| core/src/test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitManagerTest.java | Adjusted initialization to use local config and store the isolation value. |
| core/src/main/java/com/scalar/db/transaction/consensuscommit/Isolation.java | Introduced READ_COMMITTED as a new supported isolation level. |
| core/src/main/java/com/scalar/db/transaction/consensuscommit/CrudHandler.java | Updated recovery execution to select recovery type based on the snapshot isolation value. |
| core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitManager.java | Refactored config usage to pass isolation to dependent objects and updated begin methods accordingly. |
| core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommit.java | Updated commit() to catch CrudConflictException and throw CommitConflictException. |
Comments suppressed due to low confidence (1)
core/src/main/java/com/scalar/db/transaction/consensuscommit/CrudHandler.java:514
- [nitpick] The catch block for ExecutionException rethrows a CrudConflictException when the cause is a conflict. Consider adding a brief comment explaining why conflicts are handled separately to improve code clarity.
if (e.getCause() instanceof CrudConflictException) {
| parallelExecutor, | ||
| recoveryExecutor, | ||
| commit, | ||
| consensusCommitConfig.getIsolation(), |
Copilot
AI
Jun 20, 2025
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.
The test still calls consensusCommitConfig.getIsolation() even though consensusCommitConfig was removed as a constructor argument. Update the test initialization to retrieve the isolation value from the appropriate source to match the refactored constructor.
| consensusCommitConfig.getIsolation(), | |
| databaseConfig.getIsolation(), |
| public enum RecoveryType { | ||
| RETURN_LATEST_RESULT_AND_RECOVER, | ||
| RETURN_COMMITTED_RESULT_AND_RECOVER, | ||
| RETURN_COMMITTED_RESULT_AND_NOT_RECOVER | ||
| } |
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.
Introduce RecoveryType in RecoveryExecutor.
RETURN_LATEST_RESULT_AND_RECOVER: This is the previous behavior. Return the latest record with the coordinator check, then start lazy recovery.
RETURN_COMMITTED_RESULT_AND_RECOVER: Return a record created from the before image without the coordinator check, then start lazy recovery.
RETURN_COMMITTED_RESULT_AND_NOT_RECOVER: Return a record created from the before image without the coordinator check. This type does not start lazy recovery.
| if (snapshot.getIsolation() == Isolation.READ_COMMITTED) { | ||
| // In READ_COMMITTED isolation | ||
|
|
||
| if (readOnly) { | ||
| // In read-only mode, we don't recover the record, but return the committed result | ||
| recoveryType = RecoveryExecutor.RecoveryType.RETURN_COMMITTED_RESULT_AND_NOT_RECOVER; | ||
| } else { | ||
| // In read-write mode, we recover the record and return the committed result | ||
| recoveryType = RecoveryExecutor.RecoveryType.RETURN_COMMITTED_RESULT_AND_RECOVER; | ||
| } | ||
| } else { | ||
| // In SNAPSHOT or SERIALIZABLE isolation, we always recover the record and return the latest | ||
| // result | ||
| recoveryType = RecoveryExecutor.RecoveryType.RETURN_LATEST_RESULT_AND_RECOVER; | ||
| } |
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.
The RecoveryType is chosen based in the isolation level and whether the transaction is read-only or not.
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.
Added many additional integration tests. Please refer to them if you want to know the details about the behavioral differences between isolation levels and read-only mode, etc.
core/src/main/java/com/scalar/db/transaction/consensuscommit/RecoveryExecutor.java
Show resolved
Hide resolved
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! 👍
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 the
READ_COMMITTEDisolation level.The behavior specific to
READ_COMMITTEDis as follows:Related issues and/or PRs
N/A
Changes made
Checklist
Additional notes (optional)
N/A
Release notes
Added the
READ_COMMITTEDisolation level, which offers better performance, especially for low-contention workloads.