Skip to content
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

Merged
merged 6 commits into from Jul 14, 2018

Conversation

4 participants
@janvdbergh
Copy link
Contributor

janvdbergh commented Apr 23, 2018

Fix for issue #1171.

@codecov-io

This comment has been minimized.

Copy link

codecov-io commented Apr 23, 2018

Codecov Report

Merging #1175 into master will increase coverage by 0.01%.
The diff coverage is 75%.

@@             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
@davecramer

This comment has been minimized.

Copy link
Member

davecramer commented Apr 24, 2018

I'm wondering if there is a decent way to test this ?

@janvdbergh

This comment has been minimized.

Copy link
Contributor Author

janvdbergh commented Apr 27, 2018

Do you mean manually or automated?
I manually tested the changes by deliberately adding a deferrable foreign key constraint to my database schema, causing it fo fail during commit. After the change the distributed transaction manager (Atomikos) could determine the outcome of the transaction and properly respond.
To test this automatically you would need a similar schema in your database and run a distributed transaction against it. The outcome should be an XAException indicating that the transaction was rolled back. However it might take a lot of work to set this up.

@janvdbergh

This comment has been minimized.

Copy link
Contributor Author

janvdbergh commented May 7, 2018

@davecramer Do you still see issues before this pull request can be merged? Let me know if anything has to be adapted.

@davecramer

This comment has been minimized.

Copy link
Member

davecramer commented May 7, 2018

@janvdbergh no I see no reason not to merge it.
@vlsi ?

@vlsi
Copy link
Member

vlsi left a comment

I still wonder if you could replicate the issue with something like

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}");

This comment has been minimized.

@vlsi

vlsi May 7, 2018

Member

While regexp looks clever, it is actually specified to mean that? What if the code clashes somehow?

This comment has been minimized.

@janvdbergh

janvdbergh Jun 12, 2018

Author Contributor

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)) {

This comment has been minimized.

@vlsi

vlsi May 7, 2018

Member

Is there any reason why integrity constraint violation exceptions only are treated special?

This comment has been minimized.

@janvdbergh

janvdbergh Jun 12, 2018

Author Contributor

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.

@janvdbergh

This comment has been minimized.

Copy link
Contributor Author

janvdbergh commented Jun 12, 2018

@vlsi I made the requested change and added a test to validate the error code mapping. Any other comments?

@janvdbergh

This comment has been minimized.

Copy link
Contributor Author

janvdbergh commented Jul 11, 2018

@vlsi Can this branch be merged or is there something else to do?
Or should I just close and reopen the pull request?

@@ -584,6 +584,20 @@ public boolean setTransactionTimeout(int seconds) {
return false;
}

private int mapSQLStateToXAErrorCode(SQLException sqlException) {
if (isPostgreSQLIntegrityConstraintViolation(sqlException)) {
return XAException.XA_RBROLLBACK;

This comment has been minimized.

@vlsi

vlsi Jul 14, 2018

Member

@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

vlsi added some commits Jul 14, 2018

@vlsi

vlsi approved these changes Jul 14, 2018

@vlsi vlsi added this to the 42.2.4 milestone Jul 14, 2018

@vlsi vlsi changed the title Correctly map integrity violations to XA error codes. fix: map integrity constraint violation to XA_RBINTEGRITY instead of XAER_RMFAIL Jul 14, 2018

@vlsi vlsi merged commit f2d1352 into pgjdbc:master Jul 14, 2018

2 checks passed

codecov/project 68.73% (+0.01%) compared to 27be4e2
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@davecramer davecramer added this to In progress in 42.2.4 Release Jul 14, 2018

@davecramer davecramer moved this from In progress to Done in 42.2.4 Release Jul 14, 2018

golovnin added a commit to golovnin/pgjdbc that referenced this pull request Jul 24, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.