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
[AMBARI-25325] : RetryUpgradeActionService not updating host_role_command in Transaction #3032
Conversation
Refer to this link for build results (access rights to CI server needed): |
Refer to this link for build results (access rights to CI server needed): |
Refer to this link for build results (access rights to CI server needed): |
@adoroszlai @zeroflag @jonathan-hurley Please review |
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.
Why break this out into its own file? It's not going to be reused. Can you just make this method public instead?
@jonathan-hurley Thanks for your review. |
If object A calls public transactional method of it's own, there would not be any proxy involved and hence, purpose of @transactional would not provide any meaning. Only if object A calls public transactional method of object B, given that object B is already injected to object A with proxy, @transactional creates actual transaction and commit/rollback the transaction based on the ongoing execution. |
Refer to this link for build results (access rights to CI server needed): |
According to the Where are you getting your information from? |
@jonathan-hurley here is one of the links: Also, I tried to verify this scenario using unit tests available in RetryUpgradeActionServiceTest.java Line 304 in c6db11c
(we can put may be: int i=1/0; after L304) Scenario 1: Without this patch, with and without public method retryHoldingCommandsInRequest, dao.merge is not getting rolled back, which means Transaction is not applied to retryHoldingCommandsInRequest. Scenario 2: With this patch, dao.merge is getting rolled back. The only reason why this update was working so far is because m_hostRoleCommandDAO.merge(hrc); itself is annotated with Transactional and the dependency of m_hostRoleCommandDAO is injected to RetryUpgradeActionService. However, there is no Transaction getting applied for retryHoldingCommandsInRequest as such. |
@jonathan-hurley There is one more way to further validate transaction applicable for retryHoldingCommandsInRequest() method: Case 1: Without applying this patch, we can mark retryHoldingCommandsInRequest() as public here . Then we can comment out(or remove) m_hostRoleCommandDAO.merge(hrc); here . Now, if we run test, it would fail, which should not if Transaction was applied to retryHoldingCommandsInRequest() because any changes made to HostRoleCommandEntity within Transaction would get auto-committed to DB if the actual transaction was applied. Case 2: After applying this patch, we can comment out(or remove) m_hostRoleCommandDAO.merge(hrc); here . Now if we run test, it would succeed because we don't need to explicitly merge(commit) HostRoleCommandEntity as any change within transaction would be auto-committed to DB after successful execution of retryHoldingCommandsInRequest(). |
@jonathan-hurley Would you like to recommend removing |
Updated the PR with the changes requested. Tested and it is working fine. |
Refer to this link for build results (access rights to CI server needed): |
Could you please review @jonathan-hurley |
Thanks for the review @jonathan-hurley |
@jonathan-hurley if code freeze is not applied for 2.7.4 release, could you please help me merge this patch(trunk) and backport patch(branch-2.7)? |
What changes were proposed in this pull request?
non-public method in the same instance with guice @Transactional doesn't initiate Transaction at the beginning of the method and tear down after execution of the method. The same is the case with RetryUpgradeActionService updating host_role_command entries during Rolling Upgrade for commands with HOLDING_* failed status. Created a new Singleton class to offload the responsibility of creating Transaction using AOP proxy so that Transaction is applied to retryHoldingCommandsInRequest()
How was this patch tested?
The patch was tested manually during Rolling Upgrade as well as with unit testing available in RetryUpgradeActionServiceTest. Verified Transactional behavior with/without some Exception to Rollback/Commit the ongoing Transaction for both - before/after applying the patch