Skip to content

Commit bb88c40

Browse files
committed
<fix>[dependency]: upgrade mysql-connector
Resolves: ZHCI-1490 Change-Id: I66687a6d706d6f6f637776656277796c6b686b6d Signed-off-by: AlanJager <[email protected]>
1 parent c1c2d79 commit bb88c40

File tree

9 files changed

+22
-25
lines changed

9 files changed

+22
-25
lines changed

compute/src/main/java/org/zstack/compute/vm/VmInstanceManagerImpl.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package org.zstack.compute.vm;
22

33
import com.google.common.collect.Maps;
4-
import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;
5-
import org.apache.commons.collections.CollectionUtils;
64
import org.apache.commons.lang.StringUtils;
75
import org.apache.commons.validator.routines.DomainValidator;
86
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,8 +23,8 @@
2523
import org.zstack.core.jsonlabel.JsonLabel;
2624
import org.zstack.core.thread.*;
2725
import org.zstack.core.workflow.FlowChainBuilder;
28-
import org.zstack.directory.ResourceDirectoryRefVO;
2926
import org.zstack.core.workflow.ShareFlow;
27+
import org.zstack.directory.ResourceDirectoryRefVO;
3028
import org.zstack.header.AbstractService;
3129
import org.zstack.header.allocator.AllocateHostDryRunReply;
3230
import org.zstack.header.allocator.DesignatedAllocateHostMsg;
@@ -82,10 +80,7 @@
8280
import org.zstack.tag.SystemTagCreator;
8381
import org.zstack.tag.SystemTagUtils;
8482
import org.zstack.tag.TagManager;
85-
import org.zstack.utils.ExceptionDSL;
86-
import org.zstack.utils.ObjectUtils;
87-
import org.zstack.utils.TagUtils;
88-
import org.zstack.utils.Utils;
83+
import org.zstack.utils.*;
8984
import org.zstack.utils.function.Function;
9085
import org.zstack.utils.logging.CLogger;
9186
import org.zstack.utils.network.IPv6NetworkUtils;
@@ -94,6 +89,7 @@
9489
import javax.persistence.PersistenceException;
9590
import javax.persistence.Tuple;
9691
import javax.persistence.TypedQuery;
92+
import java.sql.SQLIntegrityConstraintViolationException;
9793
import java.sql.Timestamp;
9894
import java.util.*;
9995
import java.util.concurrent.Future;
@@ -825,7 +821,7 @@ protected void scripts() {
825821
}.execute();
826822
break;
827823
} catch (PersistenceException e) {
828-
if (ExceptionDSL.isCausedBy(e, MySQLIntegrityConstraintViolationException.class, "Duplicate entry")) {
824+
if (ExceptionDSL.isCausedBy(e, SQLIntegrityConstraintViolationException.class, "Duplicate entry")) {
829825
logger.debug(String.format("Concurrent mac allocation. Mac[%s] has been allocated, try allocating another one. " +
830826
"The error[Duplicate entry] printed by jdbc.spi.SqlExceptionHelper is no harm, " +
831827
"we will try finding another mac", nicVO.getMac()));

compute/src/main/java/org/zstack/compute/vm/VmNicFactory.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.zstack.compute.vm;
22

3-
import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;
43
import org.springframework.beans.factory.annotation.Autowired;
54
import org.zstack.core.db.DatabaseFacade;
65
import org.zstack.header.core.workflow.FlowException;
@@ -16,6 +15,7 @@
1615
import org.zstack.utils.network.NetworkUtils;
1716

1817
import javax.persistence.PersistenceException;
18+
import java.sql.SQLIntegrityConstraintViolationException;
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

@@ -71,7 +71,7 @@ private VmNicVO persistAndRetryIfMacCollision(VmNicVO vo) {
7171
try {
7272
return dbf.persistAndRefresh(vo);
7373
} catch (PersistenceException e) {
74-
if (ExceptionDSL.isCausedBy(e, MySQLIntegrityConstraintViolationException.class, "Duplicate entry")) {
74+
if (ExceptionDSL.isCausedBy(e, SQLIntegrityConstraintViolationException.class, "Duplicate entry")) {
7575
logger.debug(String.format("Concurrent mac allocation. Mac[%s] has been allocated, try allocating another one. " +
7676
"The error[Duplicate entry] printed by jdbc.spi.SqlExceptionHelper is no harm, " +
7777
"we will try finding another mac", vo.getMac()));

core/src/main/java/org/zstack/core/aspect/DbDeadlockAspect.aj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.zstack.core.aspect;
22

3-
import com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException;
3+
import java.sql.SQLTransactionRollbackException;
44
import org.springframework.transaction.annotation.Transactional;
55
import org.zstack.core.db.DatabaseGlobalProperty;
66
import org.zstack.utils.DebugUtils;
@@ -51,7 +51,7 @@ public aspect DbDeadlockAspect {
5151

5252
Throwable root = DebugUtils.getRootCause(re);
5353

54-
if (root instanceof MySQLTransactionRollbackException && root.getMessage().contains("Deadlock")) {
54+
if (root instanceof SQLTransactionRollbackException && root.getMessage().contains("Deadlock")) {
5555
logger.warn("deadlock happened, retry");
5656
DatabaseFacadeImpl.increaseDeadlock();
5757
try {

core/src/main/java/org/zstack/core/db/DatabaseFacadeImpl.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.zstack.core.db;
22

3-
import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;
43
import org.hibernate.exception.ConstraintViolationException;
54
import org.springframework.beans.factory.annotation.Autowired;
65
import org.springframework.core.NestedExceptionUtils;
@@ -26,6 +25,7 @@
2625
import javax.persistence.criteria.CriteriaBuilder;
2726
import javax.sql.DataSource;
2827
import java.lang.reflect.Field;
28+
import java.sql.SQLIntegrityConstraintViolationException;
2929
import java.sql.Timestamp;
3030
import java.util.*;
3131
import java.util.concurrent.atomic.AtomicLong;
@@ -240,11 +240,11 @@ private Object getVOPrimaryKeyValue(Object entity) {
240240
private void updateEO(Object entity, RuntimeException de) {
241241
Throwable rootCause = NestedExceptionUtils.getRootCause(de);
242242
if (rootCause == null
243-
|| !MySQLIntegrityConstraintViolationException.class.isAssignableFrom(rootCause.getClass())) {
243+
|| !SQLIntegrityConstraintViolationException.class.isAssignableFrom(rootCause.getClass())) {
244244
throw de;
245245
}
246246

247-
MySQLIntegrityConstraintViolationException me = (MySQLIntegrityConstraintViolationException) rootCause;
247+
SQLIntegrityConstraintViolationException me = (SQLIntegrityConstraintViolationException) rootCause;
248248
if (!(me.getErrorCode() == 1062 && "23000".equals(me.getSQLState()) && me.getMessage().contains("PRIMARY"))) {
249249
throw de;
250250
}

core/src/main/java/org/zstack/core/db/GLock.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ public void lock(long waitTimeout) {
115115
try {
116116
conn = dataSource.getConnection();
117117
conn.setAutoCommit(true);
118-
pstmt = conn.prepareStatement(String.format("select get_lock('%s', %s)", name, timeout));
118+
pstmt = conn.prepareStatement(String.format("select get_lock('%s', %s)", name, timeout),ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
119+
//pstmt = conn.prepareStatement(String.format("select get_lock('%s', %s)", name, timeout));
119120
if (waitTimeout > 0) {
120121
pstmt.execute(String.format("set wait_timeout=%d", waitTimeout));
121122
}
@@ -197,7 +198,7 @@ public void unlock() {
197198

198199
PreparedStatement pstmt = null;
199200
try {
200-
pstmt = conn.prepareStatement(String.format("select release_lock('%s')", name));
201+
pstmt = conn.prepareStatement(String.format("select release_lock('%s')", name), ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
201202
try (ResultSet rs = pstmt.executeQuery()) {
202203
if (!rs.next()) {
203204
throw new CloudRuntimeException("Mysql cannot find lock: " + name);

network/src/main/java/org/zstack/network/l3/L3NetworkManagerImpl.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.zstack.network.l3;
22

3-
import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;
3+
import java.sql.SQLIntegrityConstraintViolationException;
44
import org.springframework.beans.factory.annotation.Autowired;
55
import org.springframework.transaction.annotation.Transactional;
66
import org.zstack.core.Platform;
@@ -576,7 +576,7 @@ private UsedIpInventory reserveIpv6(IpRangeVO ipRange, String ip, boolean allowD
576576
vo = dbf.persistAndRefresh(vo);
577577
return UsedIpInventory.valueOf(vo);
578578
} catch (PersistenceException e) {
579-
if (ExceptionDSL.isCausedBy(e, MySQLIntegrityConstraintViolationException.class)) {
579+
if (ExceptionDSL.isCausedBy(e, SQLIntegrityConstraintViolationException.class)) {
580580
logger.debug(String.format("Concurrent ip allocation. " +
581581
"Ip[%s] in ip range[uuid:%s] has been allocated, try allocating another one. " +
582582
"The error[Duplicate entry] printed by jdbc.spi.SqlExceptionHelper is no harm, " +
@@ -608,7 +608,7 @@ private UsedIpInventory reserveIpv4(IpRangeVO ipRange, String ip, boolean allowD
608608
vo = dbf.persistAndRefresh(vo);
609609
return UsedIpInventory.valueOf(vo);
610610
} catch (PersistenceException e) {
611-
if (ExceptionDSL.isCausedBy(e, MySQLIntegrityConstraintViolationException.class)) {
611+
if (ExceptionDSL.isCausedBy(e, SQLIntegrityConstraintViolationException.class)) {
612612
logger.debug(String.format("Concurrent ip allocation. " +
613613
"Ip[%s] in ip range[uuid:%s] has been allocated, try allocating another one. " +
614614
"The error[Duplicate entry] printed by jdbc.spi.SqlExceptionHelper is no harm, " +

plugin/ldap/src/main/java/org/zstack/ldap/LdapManagerImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.zstack.ldap;
22

3-
import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;
3+
import java.sql.SQLIntegrityConstraintViolationException;
44
import org.apache.commons.lang.StringUtils;
55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.ldap.filter.AndFilter;
@@ -406,7 +406,7 @@ private void handle(APICreateLdapBindingMsg msg) {
406406
evt.setInventory(bindLdapAccount(msg.getAccountUuid(), fullDn));
407407
logger.info(String.format("create ldap binding[ldapUid=%s, ldapUseAsLoginName=%s] success", fullDn, ldapUseAsLoginName));
408408
} catch (PersistenceException e) {
409-
if (ExceptionDSL.isCausedBy(e, MySQLIntegrityConstraintViolationException.class)) {
409+
if (ExceptionDSL.isCausedBy(e, SQLIntegrityConstraintViolationException.class)) {
410410
evt.setError(err(LdapErrors.BIND_SAME_LDAP_UID_TO_MULTI_ACCOUNT,
411411
"The ldap uid has been bound to an account. "));
412412
} else {

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
<dependency>
183183
<groupId>mysql</groupId>
184184
<artifactId>mysql-connector-java</artifactId>
185-
<version>5.1.49</version>
185+
<version>8.0.28</version>
186186
</dependency>
187187
<dependency>
188188
<groupId>org.springframework</groupId>

tag/src/main/java/org/zstack/tag/SystemTag.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.zstack.tag;
22

3-
import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;
3+
import java.sql.SQLIntegrityConstraintViolationException;
44
import org.hibernate.TransactionException;
55
import org.hibernate.exception.ConstraintViolationException;
66
import org.springframework.beans.factory.annotation.Autowire;
@@ -352,7 +352,7 @@ private SystemTagInventory doCreate() {
352352
dbf.getEntityManager().flush();
353353
dbf.getEntityManager().refresh(vo);
354354
} catch (PersistenceException e) {
355-
if (ExceptionDSL.isCausedBy(e, MySQLIntegrityConstraintViolationException.class, "Duplicate entry")) {
355+
if (ExceptionDSL.isCausedBy(e, SQLIntegrityConstraintViolationException.class, "Duplicate entry")) {
356356
// tag exists
357357
if (!ignoreIfExisting) {
358358
throw new CloudRuntimeException(String.format("duplicate system tag[resourceUuid: %s," +

0 commit comments

Comments
 (0)