-
Notifications
You must be signed in to change notification settings - Fork 40
Fix secondary index behavior in Consensus Commit #3133
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
Summary of ChangesHello @brfrn169, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors and strengthens the validation mechanisms within the Consensus Commit transaction protocol. By introducing a unified operation checker, it enforces more rigorous constraints on how Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces important fixes and improvements related to secondary index behavior in Consensus Commit, especially for the SERIALIZABLE isolation level.
The main changes include:
- A new
ConsensusCommitOperationCheckerclass is introduced, which consolidates and extends the validation logic forGet,Scan, andMutationoperations. This is a good refactoring that improves code organization. - New restrictions are added for the
SERIALIZABLEisolation level:GetandScanoperations using a secondary index are now disallowed.- Conditions on indexed columns in cross-partition scans (
ScanAll) are also disallowed.
- The logic for preparing scan operations in
ConsensusCommitUtilshas been updated to handle conditions on indexed columns inScanAlloperations differently, which seems to be a performance optimization. MutationConditionsValidatorhas been refactored to reduce its dependency onTransactionContext, which is a nice improvement for decoupling.
The changes are well-implemented, and the test suite has been updated comprehensively to cover the new behavior, including new integration tests that validate the new restrictions.
Overall, this is a high-quality pull request that improves the correctness and robustness of the transaction implementation. I have no further comments.
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 enhances operation checking in consensus commit transactions by introducing restrictions for SERIALIZABLE isolation level and extending the operation checker to validate read operations. The changes prevent index-based operations and conditions on indexed columns in specific scenarios when using SERIALIZABLE isolation, as these operations cannot guarantee serializability.
Key changes:
- Renames and expands
ConsensusCommitMutationOperationCheckertoConsensusCommitOperationCheckerwith support for Get/Scan validation - Adds SERIALIZABLE isolation checks to reject index-based Get/Scan operations and conditions on indexed columns in cross-partition scans
- Refactors condition conversion logic to skip indexed column conditions for ScanAll operations
Reviewed Changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| ConsensusCommitOperationChecker.java | New class replacing ConsensusCommitMutationOperationChecker with added Get/Scan validation and SERIALIZABLE isolation checks |
| ConsensusCommitMutationOperationChecker.java | Removed - replaced by ConsensusCommitOperationChecker |
| ConsensusCommit.java, TwoPhaseConsensusCommit.java | Updated to call operation checker for Get/Scan operations and use renamed checker |
| ConsensusCommitManager.java, TwoPhaseConsensusCommitManager.java | Updated to instantiate ConsensusCommitOperationChecker with include_metadata flag |
| ConsensusCommitUtils.java | Modified conjunction conversion to conditionally skip indexed columns based on scan type |
| MutationConditionsValidator.java | Simplified to accept transactionId string instead of full TransactionContext |
| CrudHandler.java | Updated to pass transactionId to MutationConditionsValidator |
| CoreError.java | Added error codes for projection/ordering metadata restrictions and SERIALIZABLE index operation restrictions |
| ConsensusCommitSpecificIntegrationTestBase.java | Updated tests to reflect SERIALIZABLE restrictions and removed obsolete index operation tests |
| Various test files | Updated to use renamed ConsensusCommitOperationChecker and adjust mock behavior |
Comments suppressed due to low confidence (1)
core/src/main/java/com/scalar/db/common/CoreError.java:439
- The error message format for
CONSENSUS_COMMIT_CONDITION_NOT_ALLOWED_TO_TARGET_TRANSACTION_METADATA_COLUMNSwas changed from accepting one parameter (Column: %s) to accepting two parameters (Table: %s; Column: %s) in the new usage, but the error enum definition was not updated. This will cause a format string mismatch. The error definition should be updated to match the new usage pattern seen in line 72 and 232 of ConsensusCommitOperationChecker.java wherebuildMessage(get.forFullTableName().get(), column)andbuildMessage(mutation.forFullTableName().get(), column)are called.
CONSENSUS_COMMIT_CONDITION_NOT_ALLOWED_TO_TARGET_TRANSACTION_METADATA_COLUMNS(
Category.USER_ERROR,
"0100",
"The condition is not allowed to target transaction metadata columns. Column: %s",
"",
""),
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitUtils.java
Show resolved
Hide resolved
...src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitOperationChecker.java
Show resolved
Hide resolved
...src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitOperationChecker.java
Show resolved
Hide resolved
cc720db to
7471988
Compare
...src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitOperationChecker.java
Show resolved
Hide resolved
...src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitOperationChecker.java
Show resolved
Hide resolved
core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitUtils.java
Show resolved
Hide resolved
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've left a couple of minor suggestions. Other than that, LGTM. Thank you!🙇🏻♂️
Just out of curiosity, but using indexes for a normal column and the before column separately and merging them as follows don't work? |
@komamitsu Yes, that manual merge index approach should work. |
Co-authored-by: Josh Wong <joshua.wong@scalar-labs.com>
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.
Overall, looking good!
Left some questions for clarification. PTAL!
...src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitOperationChecker.java
Show resolved
Hide resolved
core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitUtils.java
Show resolved
Hide resolved
jnmt
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.
Thank you for the careful thought on this. I left a clarification question. PTAL!
core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitUtils.java
Show resolved
Hide resolved
|
@brfrn169 @feeblefakie This is off topic, but could we handle scan using index columns well even under serializable isolation if we had "after" image as transaction metadata instead of before image? Rollforward and rollback mechanisms must be completely changed, though. |
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!
...src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitOperationChecker.java
Show resolved
Hide resolved
jnmt
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!
core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitUtils.java
Show resolved
Hide resolved
...src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitOperationChecker.java
Outdated
Show resolved
Hide resolved
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!
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, thank you!
Description
Currently, when users specify an index key for Get or Scan operations with the Consensus Commit transaction manager, we do not add any additional conditions for the before columns. However, as described in the following Javadoc, we need to add the same conditions for the before columns to ensure correct results:
scalardb/core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitUtils.java
Lines 407 to 472 in cc720db
However, if we simply add the same conditions to the before columns, the secondary index will no longer be used, which can significantly degrade performance.
Therefore, after further discussion, we decided to redefine Get/Scan operations using secondary indexes as eventually consistent operations. This means they:
Since SERIALIZABLE isolation level requires the strongest consistency guarantees and cannot tolerate eventually consistent reads, we now prohibit secondary index operations when using SERIALIZABLE isolation.
ADDED:
I’ve summarized the behavior here:
#3133 (comment)
Related issues and/or PRs
N/A
Changes made
ConsensusCommitOperationChecker)ConsensusCommitMutationOperationCheckerto check all operations (Get, Scan, and Mutations)ConsensusCommitUtils.convertConjunctions():Checklist
Additional notes (optional)
N/A
Release notes
Prohibited Get and Scan operations using secondary indexes when the isolation level is SERIALIZABLE in the Consensus Commit transaction manager, as these operations are now defined as eventually consistent and cannot guarantee the strict consistency required by SERIALIZABLE isolation.