Skip to content

Commit

Permalink
optimize: pass the sqlexception to client when get lock (#4946)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bughue committed Sep 28, 2022
1 parent 843489d commit 141d855
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions changes/en-us/develop.md
Expand Up @@ -37,6 +37,7 @@ Add changes here for all PR submitted to the develop branch.
- [[#4917](https://github.com/seata/seata/pull/4917)] upgrade package-lock.json fix vulnerabilities
- [[#4924](https://github.com/seata/seata/pull/4924)] optimize pom dependencies
- [[#4932](https://github.com/seata/seata/pull/4932)] extract the default values for some properties
- [[#4946](https://github.com/seata/seata/pull/4946)] pass the sqlexception to client when get lock
- [[#4962](https://github.com/seata/seata/pull/4962)] optimize build and fix the base image

### test:
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/develop.md
Expand Up @@ -36,6 +36,7 @@
- [[#4917](https://github.com/seata/seata/pull/4917)] 升级 package-lock.json 修复漏洞
- [[#4924](https://github.com/seata/seata/pull/4924)] 优化 pom 依赖
- [[#4932](https://github.com/seata/seata/pull/4932)] 抽取部分配置的默认值
- [[#4946](https://github.com/seata/seata/pull/4946)] 将获取锁时遇到的sql异常传递给客户端
- [[#4962](https://github.com/seata/seata/pull/4962)] 优化构建配置,并修正docker镜像的基础镜像

### test:
Expand Down
Expand Up @@ -19,6 +19,7 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -347,7 +348,7 @@ protected boolean doAcquireLock(Connection conn, LockDO lockDO) {
* @param lockDOs the lock do list
* @return the boolean
*/
protected boolean doAcquireLocks(Connection conn, List<LockDO> lockDOs) {
protected boolean doAcquireLocks(Connection conn, List<LockDO> lockDOs) throws SQLException {
PreparedStatement ps = null;
try {
//insert
Expand All @@ -365,10 +366,12 @@ protected boolean doAcquireLocks(Connection conn, List<LockDO> lockDOs) {
ps.addBatch();
}
return ps.executeBatch().length == lockDOs.size();
} catch (SQLException e) {
} catch (SQLIntegrityConstraintViolationException e) {
LOGGER.error("Global lock batch acquire error: {}", e.getMessage(), e);
//return false,let the caller go to conn.rollabck()
return false;
} catch (SQLException e) {
throw e;
} finally {
IOUtil.close(ps);
}
Expand Down

0 comments on commit 141d855

Please sign in to comment.