You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "changeAtLater (via GitHub)" <gi...@apache.org> on 2024/09/09 03:49:16 UTC
[PR] 完善批量插入锁时的异常判断逻辑 [incubator-seata]
changeAtLater opened a new pull request, #6833:
URL: https://github.com/apache/incubator-seata/pull/6833
<!-- Please make sure you have read and understood the contributing guidelines -->
- [ ] I have registered the PR [changes](../changes).
### Ⅰ. Describe what this PR did
### Ⅱ. Does this pull request fix one issue?
<!-- If that, add "fixes #xxx" below in the next line, for example, fixes #97. -->
fixes #6822
### Ⅲ. Why don't you add test cases (unit test/integration test)?
### Ⅳ. Describe how to verify it
### Ⅴ. Special notes for reviews
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: SQLIntegrityConstraintViolationException capture incorrectly when inserting a globallock [incubator-seata]
Posted by "changeAtLater (via GitHub)" <gi...@apache.org>.
changeAtLater commented on code in PR #6833:
URL: https://github.com/apache/incubator-seata/pull/6833#discussion_r1751141961
##########
server/src/main/java/org/apache/seata/server/storage/db/lock/LockStoreDataBaseDAO.java:
##########
@@ -372,10 +373,23 @@ protected boolean doAcquireLocks(Connection conn, List<LockDO> lockDOs) throws S
return ps.executeBatch().length == lockDOs.size();
} catch (SQLIntegrityConstraintViolationException e) {
LOGGER.error("Global lock batch acquire error: {}", e.getMessage(), e);
- //return false,let the caller go to conn.rollabck()
+ //return false,let the caller go to conn.rollback()
return false;
- } catch (SQLException e) {
- throw e;
+ } catch (BatchUpdateException e) {
+ Throwable cause = e.getCause();
+ if (cause != null) {
+ if (cause instanceof SQLIntegrityConstraintViolationException) {
+ return false;
+ }
+ throw e;
+ }
+ SQLException nextException = e.getNextException();
+ if (nextException == null) {
+ throw e;
+ } else if (nextException instanceof SQLIntegrityConstraintViolationException) {
+ return false;
+ }
+ throw nextException;
Review Comment:
那单元测试也可以删了,测试不能通过,另外我只试过mysql和h2,不能保证其他数据库的异常都在cause中,如果你坚持的话,那我就把这段和单元测试都删了
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: SQLIntegrityConstraintViolationException capture incorrectly when inserting a globallock [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #6833:
URL: https://github.com/apache/incubator-seata/pull/6833#discussion_r1751140040
##########
server/src/main/java/org/apache/seata/server/storage/db/lock/LockStoreDataBaseDAO.java:
##########
@@ -372,10 +373,23 @@ protected boolean doAcquireLocks(Connection conn, List<LockDO> lockDOs) throws S
return ps.executeBatch().length == lockDOs.size();
} catch (SQLIntegrityConstraintViolationException e) {
LOGGER.error("Global lock batch acquire error: {}", e.getMessage(), e);
- //return false,let the caller go to conn.rollabck()
+ //return false,let the caller go to conn.rollback()
return false;
- } catch (SQLException e) {
- throw e;
+ } catch (BatchUpdateException e) {
+ Throwable cause = e.getCause();
+ if (cause != null) {
+ if (cause instanceof SQLIntegrityConstraintViolationException) {
+ return false;
+ }
+ throw e;
+ }
+ SQLException nextException = e.getNextException();
+ if (nextException == null) {
+ throw e;
+ } else if (nextException instanceof SQLIntegrityConstraintViolationException) {
+ return false;
+ }
+ throw nextException;
Review Comment:
我认为这一块代码都是不需要的
I don't think this piece of code is necessary
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: SQLIntegrityConstraintViolationException capture incorrectly when inserting a globallock [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on PR #6833:
URL: https://github.com/apache/incubator-seata/pull/6833#issuecomment-2339449786
```
Caused by: java.sql.BatchUpdateException: Duplicate entry 'jdbc:mysql://127.0.0.1:3306/oa^^^sys_user_role^^^10000002_3' for key 'lock_table.PRIMARY'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_231]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_231]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_231]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[na:1.8.0_231]
at com.mysql.cj.util.Util.handleNewInstance(Util.java:192) ~[mysql-connector-java-8.0.27.jar:8.0.27]
at com.mysql.cj.util.Util.getInstance(Util.java:167) ~[mysql-connector-java-8.0.27.jar:8.0.27]
at com.mysql.cj.util.Util.getInstance(Util.java:174) ~[mysql-connector-java-8.0.27.jar:8.0.27]
at com.mysql.cj.jdbc.exceptions.SQLError.createBatchUpdateException(SQLError.java:224) ~[mysql-connector-java-8.0.27.jar:8.0.27]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchedInserts(ClientPreparedStatement.java:755) ~[mysql-connector-java-8.0.27.jar:8.0.27]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchInternal(ClientPreparedStatement.java:426) ~[mysql-connector-java-8.0.27.jar:8.0.27]
at com.mysql.cj.jdbc.StatementImpl.executeBatch(StatementImpl.java:800) ~[mysql-connector-java-8.0.27.jar:8.0.27]
at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeBatch(DruidPooledPreparedStatement.java:565) ~[druid-1.2.6.jar:1.2.6]
at io.seata.server.storage.db.lock.LockStoreDataBaseDAO.doAcquireLocks(LockStoreDataBaseDAO.java:371) ~[classes!/:1.7.0]
at io.seata.server.storage.db.lock.LockStoreDataBaseDAO.acquireLock(LockStoreDataBaseDAO.java:187) ~[classes!/:1.7.0]
... 24 common frames omitted
Caused by: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry 'jdbc:mysql://127.0.0.1:3306/oa^^^sys_user_role^^^10000002_3' for key 'lock_table.PRIMARY'
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:117) ~[mysql-connector-java-8.0.27.jar:8.0.27]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.27.jar:8.0.27]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) ~[mysql-connector-java-8.0.27.jar:8.0.27]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1098) ~[mysql-connector-java-8.0.27.jar:8.0.27]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1046) ~[mysql-connector-java-8.0.27.jar:8.0.27]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1371) ~[mysql-connector-java-8.0.27.jar:8.0.27]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchedInserts(ClientPreparedStatement.java:716) ~[mysql-connector-java-8.0.27.jar:8.0.27]
... 29 common frames omitted
<==
```
根据这个堆栈,其实可以看到批量插入的时候,nextException是SQLIntegrityConstraintViolationException,如果存在其他异常,可能是数据库之类的异常,这种情况应该属于sqlexception,也不需要额外处理,直接抛出去即可
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: SQLIntegrityConstraintViolationException capture incorrectly when inserting a globallock [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #6833:
URL: https://github.com/apache/incubator-seata/pull/6833#discussion_r1751921226
##########
server/src/main/java/org/apache/seata/server/storage/db/lock/LockStoreDataBaseDAO.java:
##########
@@ -372,10 +373,23 @@ protected boolean doAcquireLocks(Connection conn, List<LockDO> lockDOs) throws S
return ps.executeBatch().length == lockDOs.size();
} catch (SQLIntegrityConstraintViolationException e) {
LOGGER.error("Global lock batch acquire error: {}", e.getMessage(), e);
- //return false,let the caller go to conn.rollabck()
+ //return false,let the caller go to conn.rollback()
return false;
- } catch (SQLException e) {
- throw e;
+ } catch (BatchUpdateException e) {
+ Throwable cause = e.getCause();
+ if (cause != null) {
+ if (cause instanceof SQLIntegrityConstraintViolationException) {
+ return false;
+ }
+ throw e;
+ }
+ SQLException nextException = e.getNextException();
+ if (nextException == null) {
+ throw e;
+ } else if (nextException instanceof SQLIntegrityConstraintViolationException) {
+ return false;
+ }
+ throw nextException;
Review Comment:
根据h2的结果来看,似乎这段代码是有意义的,那就按这样留着吧
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: SQLIntegrityConstraintViolationException capture incorrectly when inserting a globallock [incubator-seata]
Posted by "changeAtLater (via GitHub)" <gi...@apache.org>.
changeAtLater commented on code in PR #6833:
URL: https://github.com/apache/incubator-seata/pull/6833#discussion_r1751148528
##########
server/src/main/java/org/apache/seata/server/storage/db/lock/LockStoreDataBaseDAO.java:
##########
@@ -372,10 +373,23 @@ protected boolean doAcquireLocks(Connection conn, List<LockDO> lockDOs) throws S
return ps.executeBatch().length == lockDOs.size();
} catch (SQLIntegrityConstraintViolationException e) {
LOGGER.error("Global lock batch acquire error: {}", e.getMessage(), e);
- //return false,let the caller go to conn.rollabck()
+ //return false,let the caller go to conn.rollback()
return false;
- } catch (SQLException e) {
- throw e;
+ } catch (BatchUpdateException e) {
+ Throwable cause = e.getCause();
+ if (cause != null) {
+ if (cause instanceof SQLIntegrityConstraintViolationException) {
+ return false;
+ }
+ throw e;
+ }
+ SQLException nextException = e.getNextException();
+ if (nextException == null) {
+ throw e;
+ } else if (nextException instanceof SQLIntegrityConstraintViolationException) {
+ return false;
+ }
+ throw nextException;
Review Comment:
mysql:

h2:

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: SQLIntegrityConstraintViolationException capture incorrectly when inserting a globallock [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on PR #6833:
URL: https://github.com/apache/incubator-seata/pull/6833#issuecomment-2340787624
Error: Failures:
Error: DataBaseLockStoreDAOTest.tes_unLocks:178 expected: <true> but was: <false>
Error: DataBaseLockStoreDAOTest.test_acquireLocks:100 expected: <true> but was: <false>
Error: DataBaseLockStoreDAOTest.test_isLockable_can:226 expected: <true> but was: <false>
Error: DataBaseLockStoreDAOTest.test_re_acquireLocks:138 expected: <true> but was: <false>
[INFO]
Error: Tests run: 184, Failures: 4, Errors: 0, Skipped: 3
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: SQLIntegrityConstraintViolationException capture incorrectly when inserting a globallock [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #6833:
URL: https://github.com/apache/incubator-seata/pull/6833#discussion_r1751132254
##########
server/src/main/java/org/apache/seata/server/storage/db/lock/LockStoreDataBaseDAO.java:
##########
@@ -372,10 +368,27 @@ protected boolean doAcquireLocks(Connection conn, List<LockDO> lockDOs) throws S
return ps.executeBatch().length == lockDOs.size();
} catch (SQLIntegrityConstraintViolationException e) {
LOGGER.error("Global lock batch acquire error: {}", e.getMessage(), e);
- //return false,let the caller go to conn.rollabck()
+ //return false,let the caller go to conn.rollback()
+ return false;
+ } catch (BatchUpdateException e) {
+ Throwable cause = e.getCause();
+ if (cause != null) {
+ if (cause instanceof SQLIntegrityConstraintViolationException) {
+ return false;
+ }
+ throw e;
+ }
+ SQLException nextException = e.getNextException();
+ if (nextException == null) {
+ throw e;
+ }
+ while (nextException != null) {
Review Comment:
> Author
BatchUpdateException中的nextException主要与发出的sql有关,这么多的sql可能触发什么异常,那么nextException就可能有哪些异常,所以需要根据这个sql进行判断,目前这个sql只是一个批量的insert,再结合其只有一个主键作为rowkey,防止脏写,所以我认为他只可能出现SQLIntegrityConstraintViolationException这个nextException,不太可能出现其它的异常。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: SQLIntegrityConstraintViolationException capture incorrectly when inserting a globallock [incubator-seata]
Posted by "changeAtLater (via GitHub)" <gi...@apache.org>.
changeAtLater commented on PR #6833:
URL: https://github.com/apache/incubator-seata/pull/6833#issuecomment-2339455138
nextException并不会在日志中打印出来,因此我最后选择抛出nextException,可以更好的知道是什么异常
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: SQLIntegrityConstraintViolationException capture incorrectly when inserting a globallock [incubator-seata]
Posted by "changeAtLater (via GitHub)" <gi...@apache.org>.
changeAtLater commented on code in PR #6833:
URL: https://github.com/apache/incubator-seata/pull/6833#discussion_r1751112093
##########
server/src/main/java/org/apache/seata/server/storage/db/lock/LockStoreDataBaseDAO.java:
##########
@@ -372,10 +368,27 @@ protected boolean doAcquireLocks(Connection conn, List<LockDO> lockDOs) throws S
return ps.executeBatch().length == lockDOs.size();
} catch (SQLIntegrityConstraintViolationException e) {
LOGGER.error("Global lock batch acquire error: {}", e.getMessage(), e);
- //return false,let the caller go to conn.rollabck()
+ //return false,let the caller go to conn.rollback()
+ return false;
+ } catch (BatchUpdateException e) {
+ Throwable cause = e.getCause();
+ if (cause != null) {
+ if (cause instanceof SQLIntegrityConstraintViolationException) {
+ return false;
+ }
+ throw e;
+ }
+ SQLException nextException = e.getNextException();
+ if (nextException == null) {
+ throw e;
+ }
+ while (nextException != null) {
Review Comment:
BatchUpdateException存在多个异常时nextException会多层嵌套,我希望判断每个异常,如果存在非主键冲突的异常就抛出.当然,我没有处理过BatchUpdateException,遍历所有异常来判断或许过于极端, 还请你提供建议,谢谢
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: SQLIntegrityConstraintViolationException capture incorrectly when inserting a globallock [incubator-seata]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #6833:
URL: https://github.com/apache/incubator-seata/pull/6833#issuecomment-2342436961
## [Codecov](https://app.codecov.io/gh/apache/incubator-seata/pull/6833?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
Attention: Patch coverage is `33.33333%` with `8 lines` in your changes missing coverage. Please review.
> Project coverage is 52.43%. Comparing base [(`fde59c1`)](https://app.codecov.io/gh/apache/incubator-seata/commit/fde59c10237d9ad788eba006528a39b9857d8d95?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`942091a`)](https://app.codecov.io/gh/apache/incubator-seata/commit/942091a406ae9b5f5d97c102e73a991b66eaddca?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
| [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/6833?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...a/server/storage/db/lock/LockStoreDataBaseDAO.java](https://app.codecov.io/gh/apache/incubator-seata/pull/6833?src=pr&el=tree&filepath=server%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fserver%2Fstorage%2Fdb%2Flock%2FLockStoreDataBaseDAO.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9zZXJ2ZXIvc3RvcmFnZS9kYi9sb2NrL0xvY2tTdG9yZURhdGFCYXNlREFPLmphdmE=) | 33.33% | [5 Missing and 3 partials :warning: ](https://app.codecov.io/gh/apache/incubator-seata/pull/6833?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/incubator-seata/pull/6833?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## 2.x #6833 +/- ##
============================================
+ Coverage 52.41% 52.43% +0.02%
- Complexity 6379 6384 +5
============================================
Files 1080 1080
Lines 37565 37575 +10
Branches 4451 4457 +6
============================================
+ Hits 19691 19704 +13
+ Misses 15923 15920 -3
Partials 1951 1951
```
| [Files with missing lines](https://app.codecov.io/gh/apache/incubator-seata/pull/6833?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...a/server/storage/db/lock/LockStoreDataBaseDAO.java](https://app.codecov.io/gh/apache/incubator-seata/pull/6833?src=pr&el=tree&filepath=server%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fseata%2Fserver%2Fstorage%2Fdb%2Flock%2FLockStoreDataBaseDAO.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2VydmVyL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zZWF0YS9zZXJ2ZXIvc3RvcmFnZS9kYi9sb2NrL0xvY2tTdG9yZURhdGFCYXNlREFPLmphdmE=) | `52.77% <33.33%> (+2.29%)` | :arrow_up: |
... and [3 files with indirect coverage changes](https://app.codecov.io/gh/apache/incubator-seata/pull/6833/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: SQLIntegrityConstraintViolationException capture incorrectly when inserting a globallock [incubator-seata]
Posted by "changeAtLater (via GitHub)" <gi...@apache.org>.
changeAtLater commented on code in PR #6833:
URL: https://github.com/apache/incubator-seata/pull/6833#discussion_r1751133532
##########
server/src/main/java/org/apache/seata/server/storage/db/lock/LockStoreDataBaseDAO.java:
##########
@@ -372,10 +368,27 @@ protected boolean doAcquireLocks(Connection conn, List<LockDO> lockDOs) throws S
return ps.executeBatch().length == lockDOs.size();
} catch (SQLIntegrityConstraintViolationException e) {
LOGGER.error("Global lock batch acquire error: {}", e.getMessage(), e);
- //return false,let the caller go to conn.rollabck()
+ //return false,let the caller go to conn.rollback()
+ return false;
+ } catch (BatchUpdateException e) {
+ Throwable cause = e.getCause();
+ if (cause != null) {
+ if (cause instanceof SQLIntegrityConstraintViolationException) {
+ return false;
+ }
+ throw e;
+ }
+ SQLException nextException = e.getNextException();
+ if (nextException == null) {
+ throw e;
+ }
+ while (nextException != null) {
Review Comment:
ok,那我修改一下
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: SQLIntegrityConstraintViolationException capture incorrectly when inserting a globallock [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on PR #6833:
URL: https://github.com/apache/incubator-seata/pull/6833#issuecomment-2342438725
Thank you for your contributions to Seata. If possible, please send your Dingtalk contact information to my email, and I will invite you to join the Seata developer group.
[jianbin@apache.org](mailto:jianbin@apache.org)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: SQLIntegrityConstraintViolationException capture incorrectly when inserting a globallock [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on code in PR #6833:
URL: https://github.com/apache/incubator-seata/pull/6833#discussion_r1749591561
##########
server/src/main/java/org/apache/seata/server/storage/db/lock/LockStoreDataBaseDAO.java:
##########
@@ -372,10 +368,27 @@ protected boolean doAcquireLocks(Connection conn, List<LockDO> lockDOs) throws S
return ps.executeBatch().length == lockDOs.size();
} catch (SQLIntegrityConstraintViolationException e) {
LOGGER.error("Global lock batch acquire error: {}", e.getMessage(), e);
- //return false,let the caller go to conn.rollabck()
+ //return false,let the caller go to conn.rollback()
+ return false;
+ } catch (BatchUpdateException e) {
+ Throwable cause = e.getCause();
+ if (cause != null) {
+ if (cause instanceof SQLIntegrityConstraintViolationException) {
+ return false;
+ }
+ throw e;
+ }
+ SQLException nextException = e.getNextException();
+ if (nextException == null) {
+ throw e;
+ }
+ while (nextException != null) {
Review Comment:
SQLIntegrityConstraintViolationException 有可能会被这么多层包裹吗?
Is it possible for SQLIntegrityConstraintViolationException to be wrapped in so many layers?
##########
server/src/main/java/org/apache/seata/server/storage/db/lock/LockStoreDataBaseDAO.java:
##########
@@ -16,11 +16,7 @@
*/
package org.apache.seata.server.storage.db.lock;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.SQLIntegrityConstraintViolationException;
+import java.sql.*;
Review Comment:
不要使用*引入
Do not use * introduce
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: SQLIntegrityConstraintViolationException capture incorrectly when inserting a globallock [incubator-seata]
Posted by "changeAtLater (via GitHub)" <gi...@apache.org>.
changeAtLater commented on PR #6833:
URL: https://github.com/apache/incubator-seata/pull/6833#issuecomment-2339453046
> ```
> Caused by: java.sql.BatchUpdateException: Duplicate entry 'jdbc:mysql://127.0.0.1:3306/oa^^^sys_user_role^^^10000002_3' for key 'lock_table.PRIMARY'
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_231]
> at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_231]
> at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[na:1.8.0_231]
> at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[na:1.8.0_231]
> at com.mysql.cj.util.Util.handleNewInstance(Util.java:192) ~[mysql-connector-java-8.0.27.jar:8.0.27]
> at com.mysql.cj.util.Util.getInstance(Util.java:167) ~[mysql-connector-java-8.0.27.jar:8.0.27]
> at com.mysql.cj.util.Util.getInstance(Util.java:174) ~[mysql-connector-java-8.0.27.jar:8.0.27]
> at com.mysql.cj.jdbc.exceptions.SQLError.createBatchUpdateException(SQLError.java:224) ~[mysql-connector-java-8.0.27.jar:8.0.27]
> at com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchedInserts(ClientPreparedStatement.java:755) ~[mysql-connector-java-8.0.27.jar:8.0.27]
> at com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchInternal(ClientPreparedStatement.java:426) ~[mysql-connector-java-8.0.27.jar:8.0.27]
> at com.mysql.cj.jdbc.StatementImpl.executeBatch(StatementImpl.java:800) ~[mysql-connector-java-8.0.27.jar:8.0.27]
> at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeBatch(DruidPooledPreparedStatement.java:565) ~[druid-1.2.6.jar:1.2.6]
> at io.seata.server.storage.db.lock.LockStoreDataBaseDAO.doAcquireLocks(LockStoreDataBaseDAO.java:371) ~[classes!/:1.7.0]
> at io.seata.server.storage.db.lock.LockStoreDataBaseDAO.acquireLock(LockStoreDataBaseDAO.java:187) ~[classes!/:1.7.0]
> ... 24 common frames omitted
> Caused by: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry 'jdbc:mysql://127.0.0.1:3306/oa^^^sys_user_role^^^10000002_3' for key 'lock_table.PRIMARY'
> at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:117) ~[mysql-connector-java-8.0.27.jar:8.0.27]
> at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.27.jar:8.0.27]
> at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) ~[mysql-connector-java-8.0.27.jar:8.0.27]
> at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1098) ~[mysql-connector-java-8.0.27.jar:8.0.27]
> at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1046) ~[mysql-connector-java-8.0.27.jar:8.0.27]
> at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1371) ~[mysql-connector-java-8.0.27.jar:8.0.27]
> at com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchedInserts(ClientPreparedStatement.java:716) ~[mysql-connector-java-8.0.27.jar:8.0.27]
> ... 29 common frames omitted
> <==
> ```
>
> 根据这个堆栈,其实可以看到批量插入的时候,nextException是SQLIntegrityConstraintViolationException,如果存在其他异常,可能是数据库之类的异常,这种情况应该属于sqlexception,也不需要额外处理,直接抛出去即可
我用mysql测试时,SQLIntegrityConstraintViolationException在cause中, 但我写单元测试时发现, h2的SQLIntegrityConstraintViolationException在nextException中
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org
Re: [PR] bugfix: SQLIntegrityConstraintViolationException capture incorrectly when inserting a globallock [incubator-seata]
Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes merged PR #6833:
URL: https://github.com/apache/incubator-seata/pull/6833
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org