-
Notifications
You must be signed in to change notification settings - Fork 684
Fix race condition during tenant initialization by adding synchronization lock and aborted connection rollback #4407
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
| * @param path the path that caused the constraint violation | ||
| * @return the existing path ID if found, or -1 if not found | ||
| */ | ||
| private int getPathIDAfterRollback(AbstractConnection conn, String path) throws SQLException { |
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.
Log Improvement Suggestion No: 1
| private int getPathIDAfterRollback(AbstractConnection conn, String path) throws SQLException { | |
| private int getPathIDAfterRollback(AbstractConnection conn, String path) throws SQLException { | |
| if (log.isDebugEnabled()) { | |
| log.debug("Attempting to retrieve path ID after rollback for path: " + path); | |
| } |
...carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/jdbc/dao/JDBCPathCache.java
Show resolved
Hide resolved
...o2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/utils/RegistryUtils.java
Show resolved
Hide resolved
...o2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/utils/RegistryUtils.java
Show resolved
Hide resolved
...o2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/utils/RegistryUtils.java
Show resolved
Hide resolved
...o2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/utils/RegistryUtils.java
Show resolved
Hide resolved
...o2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/utils/RegistryUtils.java
Show resolved
Hide resolved
...o2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/utils/RegistryUtils.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.
AI Agent Log Improvement Checklist
- The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
- Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.
✅ Before merging this pull request:
- Review all AI-generated comments for accuracy and relevance.
- Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
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 race conditions during tenant initialization and improves database error handling for constraint violations. The changes focus on adding synchronization mechanisms and better transaction rollback handling to ensure robust concurrent operations.
- Added tenant-specific synchronization locking to prevent race conditions during tenant initialization
- Enhanced database error handling with proper transaction rollback for constraint violations
- Improved error recovery by introducing a dedicated method for handling aborted transactions
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| RegistryUtils.java | Added tenant-specific locking mechanism with getTenantInitializationLock method and synchronized initializeTenant method |
| JDBCPathCache.java | Enhanced constraint violation handling with getPathIDAfterRollback method and updated both addEntry methods to use it |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...o2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/utils/RegistryUtils.java
Show resolved
Hide resolved
...carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/jdbc/dao/JDBCPathCache.java
Show resolved
Hide resolved
|
integration tests run in the fork |
|
PR builder started |
|
PR builder completed |
jenkins-is-staging
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.
Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/18375345415
Purpose
This pull request introduces improvements to concurrency handling and error recovery in the registry codebase. The main changes focus on preventing race conditions during tenant initialization and ensuring robust handling of database constraint violations when adding paths.
Concurrency and synchronization improvements:
RegistryUtils.javato prevent race conditions during tenant initialization by synchronizing on a per-tenant lock object. (initializeTenant,getTenantInitializationLock)Database error handling enhancements:
JDBCPathCache.javaby introducinggetPathIDAfterRollback, which rolls back aborted transactions and retries path ID lookup after a failed insert due to a duplicate path. This change is applied in both overloadedaddEntrymethods.Related issue
<path>Referential integrity constraint violation:REG_RESOURCE_FK_BY_PATH_IDproduct-is#25649