-
Notifications
You must be signed in to change notification settings - Fork 860
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: map integrity constraint violation to XA_RBINTEGRITY instead of XAER_RMFAIL #1175
fix: map integrity constraint violation to XA_RBINTEGRITY instead of XAER_RMFAIL #1175
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1175 +/- ##
============================================
+ Coverage 68.71% 68.73% +0.01%
- Complexity 3850 3858 +8
============================================
Files 174 174
Lines 16035 16048 +13
Branches 2614 2617 +3
============================================
+ Hits 11019 11030 +11
- Misses 3780 3781 +1
- Partials 1236 1237 +1 |
I'm wondering if there is a decent way to test this ? |
Do you mean manually or automated? |
@davecramer Do you still see issues before this pull request can be merged? Let me know if anything has to be adapted. |
@janvdbergh no I see no reason not to merge 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.
I still wonder if you could replicate the issue with something like
public XADataSourceTest() { |
At least constraint violation should not be that hard to replicate.
} | ||
|
||
private boolean isPostgreSQLIntegrityConstraintViolation(SQLException sqlException) { | ||
return sqlException instanceof PSQLException && sqlException.getSQLState().matches("23\\d{3}"); |
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.
While regexp
looks clever, it is actually specified to mean that? What if the code clashes somehow?
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.
Correct. Replaced it with a non-regex version.
@@ -584,6 +584,18 @@ public boolean setTransactionTimeout(int seconds) { | |||
return false; | |||
} | |||
|
|||
private int mapSQLStateToXAErrorCode(SQLException sqlException) { | |||
if (isPostgreSQLIntegrityConstraintViolation(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.
Is there any reason why integrity constraint violation exceptions only are treated special?
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.
These exceptions can be mapped to the correct XA Error Code. When Postgres reported an integrity constraint violation that means the change has been rolled back and can be reported as such. We can not make the same claim for other exceptions.
@vlsi I made the requested change and added a test to validate the error code mapping. Any other comments? |
@vlsi Can this branch be merged or is there something else to do? |
@@ -584,6 +584,20 @@ public boolean setTransactionTimeout(int seconds) { | |||
return false; | |||
} | |||
|
|||
private int mapSQLStateToXAErrorCode(SQLException sqlException) { | |||
if (isPostgreSQLIntegrityConstraintViolation(sqlException)) { | |||
return XAException.XA_RBROLLBACK; |
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.
@janvdbergh , what do you think of using XA_RBINTEGRITY
instead?
A condition that violates the integrity of the resource was detected
https://docs.oracle.com/javaee/6/api/javax/transaction/xa/XAException.html#XA_RBINTEGRITY
Fix for issue #1171.