-
Notifications
You must be signed in to change notification settings - Fork 40
Fix Scanner thread-safety in active transaction managers #3094
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
Fix Scanner thread-safety in active transaction managers #3094
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 resolves a critical thread-safety vulnerability affecting scanner operations in active transaction managers. By carefully synchronizing access to scanner methods, the changes ensure data consistency and prevent potential race conditions that could arise in multi-threaded environments, particularly when transactions are rolled back concurrently. 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.
Pull Request Overview
This PR addresses a thread-safety issue in the scanner within active transaction managers for versions 3.16 and earlier. The fix ensures that Scanner operations are properly synchronized when the rollback() method may be called from an expiration handler in a different thread.
Key Changes:
- Wraps Scanner instances returned by
getScanner()with synchronized delegates - Adds documentation explaining the thread-safety requirements for ActiveTransaction classes
- Applies identical fixes to both TwoPhaseCommitTransactionManager and DistributedTransactionManager
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| ActiveTransactionManagedTwoPhaseCommitTransactionManager.java | Wraps Scanner with synchronized delegate to prevent concurrent access during rollback |
| ActiveTransactionManagedDistributedTransactionManager.java | Applies identical Scanner synchronization fix for distributed transactions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...main/java/com/scalar/db/common/ActiveTransactionManagedTwoPhaseCommitTransactionManager.java
Show resolved
Hide resolved
...rc/main/java/com/scalar/db/common/ActiveTransactionManagedDistributedTransactionManager.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.
Code Review
This pull request aims to fix a thread-safety issue in the scanner within active transaction managers by synchronizing access to the scanner's methods. The approach of wrapping the Scanner and synchronizing its methods on the ActiveTransaction instance is correct. However, the implementation for the iterator() method is incomplete, as it does not synchronize the methods of the returned Iterator, leaving a potential race condition. I've provided suggestions to fully fix the thread-safety issue.
Description
This PR applies to versions 3.16 and earlier.
It fixes a thread-safety issue in the scanner in active transaction managers. This change is a backport of part of the change introduced in #3082.
Related issues and/or PRs
Changes made
Checklist
Additional notes (optional)
N/A
Release notes
N/A