-
Notifications
You must be signed in to change notification settings - Fork 40
Fix NPE that occurs with DELETE w/o clustering key #2981
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.
Summary of Changes
Hello @komamitsu, 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 addresses a NullPointerException (NPE) that occurred when attempting to delete records without a clustering key. Previously, committing such delete operations would silently fail because the clusteringKey() method was explicitly set to null, leading to an issue during the commit process. The fix ensures that the clustering key is only set if it is present, preventing the NPE and allowing these delete operations to complete successfully.
Highlights
- NPE Fix for DELETE operations: Resolved a NullPointerException that occurred when performing DELETE operations without a clustering key by modifying the
composeDeletemethod inCommitMutationComposerto conditionally set the clustering key. - Improved Clustering Key Handling: The
composeDeletemethod now usesOptional.ifPresentto apply the clustering key only when it exists, avoiding the explicit passing ofnull. - Enhanced Test Coverage: Added new test cases in
CommitMutationComposerTestto specifically validate the correct behavior ofPutandDeleteoperations when no clustering key is provided.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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 correctly fixes a NullPointerException that could occur during a DELETE operation on a record without a clustering key. The modification in CommitMutationComposer to use ifPresent for conditionally setting the clustering key is a clean and appropriate solution. The new tests added in CommitMutationComposerTest are well-written and provide good coverage for the fix, especially the case for deletes without a clustering key. I've included one suggestion to improve the maintainability of the test code by refactoring duplicated logic.
core/src/test/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposerTest.java
Show resolved
Hide resolved
core/src/test/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposerTest.java
Show resolved
Hide resolved
core/src/test/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposerTest.java
Show resolved
Hide resolved
core/src/main/java/com/scalar/db/transaction/consensuscommit/CommitMutationComposer.java
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!
…/scalardb into fix-delete-wo-clustering-key
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 fixes a NullPointerException that occurs when deleting records without clustering keys in the consensus commit transaction system. The issue was causing silent failures during commit operations where null clustering keys were being passed to builder methods that don't accept null values.
Key changes made:
- Modified
CommitMutationComposerandRollbackMutationComposerto conditionally set clustering keys only when present - Updated both composers to use builder patterns that avoid passing null values
- Added comprehensive test coverage for operations without clustering keys
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| CommitMutationComposer.java | Fixed NPE by conditionally setting clustering key in delete operations using Optional.ifPresent() |
| RollbackMutationComposer.java | Applied same fix to rollback operations and updated get operation to handle null clustering keys |
| CommitMutationComposerTest.java | Added test cases for put and delete operations without clustering keys |
| RollbackMutationComposerTest.java | Added test case for put operations without clustering keys in rollback scenarios |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
core/src/main/java/com/scalar/db/transaction/consensuscommit/RollbackMutationComposer.java
Show resolved
Hide resolved
brfrn169
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 for handling this!
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!
Description
I noticed committing records silently fail when deleting a record without clustering key. It doesn't cause integration test failures since committing state itself finishes successfully and the failure of commit-record is ignored. This PR fixed the issue.
Related issues and/or PRs
https://github.com/scalar-labs/scalardb/pull/2957/files#diff-a77001aa78b9f7b380bda3d90371dd74610f8a344d04a5aa42c2ae8b704d901eR121, I guess.
Changes made
Avoid setting
clusteringKey()to null inCommitMutationComposer#composeDelete().Checklist
Additional notes (optional)
None
Release notes
N/A