From cc9cf9147fdf32e9de0c950a8c00428a55ee6049 Mon Sep 17 00:00:00 2001 From: zhangjiawei <349071347@qq.com> Date: Wed, 23 Nov 2022 19:07:03 +0800 Subject: [PATCH 1/5] remote druid dependency in ConnectionProxy --- .../src/main/java/io/seata/rm/datasource/ConnectionProxy.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/ConnectionProxy.java b/rm-datasource/src/main/java/io/seata/rm/datasource/ConnectionProxy.java index fc633a75358..e93fcd5cf66 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/ConnectionProxy.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/ConnectionProxy.java @@ -19,7 +19,6 @@ import java.sql.SQLException; import java.sql.Savepoint; import java.util.concurrent.Callable; -import com.alibaba.druid.mock.MockConnection; import io.seata.common.util.StringUtils; import io.seata.config.ConfigurationFactory; import io.seata.core.constants.ConfigurationKeys; @@ -272,8 +271,7 @@ private void register() throws TransactionException { } Long branchId = DefaultResourceManager.get().branchRegister(BranchType.AT, getDataSourceProxy().getResourceId(), - null, context.getXid(), this.targetConnection == null || this.targetConnection instanceof MockConnection - ? null : context.getApplicationData(), + null, context.getXid(), context.getApplicationData(), context.buildLockKeys()); context.setBranchId(branchId); } From f9d8736d5acbb7580f1a6fe0f57e3204f1b0b712 Mon Sep 17 00:00:00 2001 From: zhangjiawei <349071347@qq.com> Date: Wed, 23 Nov 2022 19:32:18 +0800 Subject: [PATCH 2/5] fix ConnectionProxyTest --- .../rm/datasource/ConnectionProxyTest.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/ConnectionProxyTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/ConnectionProxyTest.java index 0e26e254598..4a493a07fdb 100644 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/ConnectionProxyTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/ConnectionProxyTest.java @@ -15,10 +15,12 @@ */ package io.seata.rm.datasource; +import io.seata.common.LockStrategyMode; +import io.seata.core.context.GlobalLockConfigHolder; import io.seata.core.exception.TransactionException; import io.seata.core.exception.TransactionExceptionCode; import io.seata.core.model.BranchType; -import io.seata.core.model.ResourceManager; +import io.seata.core.model.GlobalLockConfig; import io.seata.rm.DefaultResourceManager; import io.seata.rm.datasource.exec.LockWaitTimeoutException; import io.seata.rm.datasource.mock.MockConnection; @@ -51,6 +53,8 @@ public class ConnectionProxyTest { private final static String lockKey = "order:123"; + private final static String DB_TYPE = "mysql"; + private Field branchRollbackFlagField; @BeforeEach @@ -66,8 +70,10 @@ public void initBeforeEach() throws Exception { dataSourceProxy = Mockito.mock(DataSourceProxy.class); Mockito.when(dataSourceProxy.getResourceId()) .thenReturn(TEST_RESOURCE_ID); - ResourceManager rm = Mockito.mock(ResourceManager.class); - Mockito.when(rm.branchRegister(BranchType.AT, dataSourceProxy.getResourceId(), null, TEST_XID, null, lockKey)) + Mockito.when(dataSourceProxy.getDbType()).thenReturn(DB_TYPE); + DefaultResourceManager rm = Mockito.mock(DefaultResourceManager.class); + + Mockito.when(rm.branchRegister(BranchType.AT, dataSourceProxy.getResourceId(), null, TEST_XID, "{\"autoCommit\":false}", lockKey)) .thenThrow(new TransactionException(TransactionExceptionCode.LockKeyConflict)); DefaultResourceManager defaultResourceManager = DefaultResourceManager.get(); Assertions.assertNotNull(defaultResourceManager); @@ -78,6 +84,11 @@ public void initBeforeEach() throws Exception { public void testLockRetryPolicyRollbackOnConflict() throws Exception { boolean oldBranchRollbackFlag = (boolean) branchRollbackFlagField.get(null); branchRollbackFlagField.set(null, true); + GlobalLockConfig preGlobalLockConfig = new GlobalLockConfig(); + preGlobalLockConfig.setLockRetryTimes(0); + preGlobalLockConfig.setLockRetryInterval(10); + preGlobalLockConfig.setLockStrategyMode(LockStrategyMode.PESSIMISTIC); + GlobalLockConfig globalLockConfig = GlobalLockConfigHolder.setAndReturnPrevious(preGlobalLockConfig); ConnectionProxy connectionProxy = new ConnectionProxy(dataSourceProxy, new MockConnection(new MockDriver(), "", null)); connectionProxy.bind(TEST_XID); SQLUndoLog sqlUndoLog = new SQLUndoLog(); @@ -95,6 +106,11 @@ public void testLockRetryPolicyRollbackOnConflict() throws Exception { public void testLockRetryPolicyNotRollbackOnConflict() throws Exception { boolean oldBranchRollbackFlag = (boolean) branchRollbackFlagField.get(null); branchRollbackFlagField.set(null, false); + GlobalLockConfig preGlobalLockConfig = new GlobalLockConfig(); + preGlobalLockConfig.setLockRetryTimes(30); + preGlobalLockConfig.setLockRetryInterval(10); + preGlobalLockConfig.setLockStrategyMode(LockStrategyMode.PESSIMISTIC); + GlobalLockConfig globalLockConfig = GlobalLockConfigHolder.setAndReturnPrevious(preGlobalLockConfig); ConnectionProxy connectionProxy = new ConnectionProxy(dataSourceProxy, null); connectionProxy.bind(TEST_XID); connectionProxy.appendUndoLog(new SQLUndoLog()); From 7c8d2027c2ef6650f6d544009b8642bf89b38346 Mon Sep 17 00:00:00 2001 From: zhangjiawei <349071347@qq.com> Date: Wed, 23 Nov 2022 21:38:40 +0800 Subject: [PATCH 3/5] change develop.md --- changes/en-us/develop.md | 1 + changes/zh-cn/develop.md | 1 + 2 files changed, 2 insertions(+) diff --git a/changes/en-us/develop.md b/changes/en-us/develop.md index 9b5bd9ca5c4..e47945fe210 100644 --- a/changes/en-us/develop.md +++ b/changes/en-us/develop.md @@ -70,6 +70,7 @@ Add changes here for all PR submitted to the develop branch. - [[#5047](https://github.com/seata/seata/pull/5047)] remove useless code - [[#5051](https://github.com/seata/seata/pull/5051)] undo log dirty throw BranchRollbackFailed_Unretriable - [[#5075](https://github.com/seata/seata/pull/5075)] intercept the InsertOnDuplicateUpdate statement which has no primary key and unique index value +- [[#5104](https://github.com/seata/seata/pull/5075)] remove the druid dependency in ConnectionProxy ### test: diff --git a/changes/zh-cn/develop.md b/changes/zh-cn/develop.md index a19e3f73d72..9f8d58a402b 100644 --- a/changes/zh-cn/develop.md +++ b/changes/zh-cn/develop.md @@ -70,6 +70,7 @@ - [[#5047](https://github.com/seata/seata/pull/5047)] 移除无用代码 - [[#5051](https://github.com/seata/seata/pull/5051)] 回滚时undolog产生脏写需要抛出不再重试(BranchRollbackFailed_Unretriable)的异常 - [[#5075](https://github.com/seata/seata/pull/5075)] 拦截没有主键及唯一索引值的insert on duplicate update语句 +- [[#5104](https://github.com/seata/seata/pull/5075)] ConnectionProxy脱离对druid的依赖 ### test: - [[#4411](https://github.com/seata/seata/pull/4411)] 测试Oracle数据库AT模式下类型支持 From 5311ca1d742b68ba3047ab5ba4a7068d8c3e8fd3 Mon Sep 17 00:00:00 2001 From: zhangjiawei <349071347@qq.com> Date: Wed, 23 Nov 2022 23:15:14 +0800 Subject: [PATCH 4/5] change develop.md --- changes/en-us/develop.md | 2 +- changes/zh-cn/develop.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changes/en-us/develop.md b/changes/en-us/develop.md index e47945fe210..0a491734089 100644 --- a/changes/en-us/develop.md +++ b/changes/en-us/develop.md @@ -70,7 +70,7 @@ Add changes here for all PR submitted to the develop branch. - [[#5047](https://github.com/seata/seata/pull/5047)] remove useless code - [[#5051](https://github.com/seata/seata/pull/5051)] undo log dirty throw BranchRollbackFailed_Unretriable - [[#5075](https://github.com/seata/seata/pull/5075)] intercept the InsertOnDuplicateUpdate statement which has no primary key and unique index value -- [[#5104](https://github.com/seata/seata/pull/5075)] remove the druid dependency in ConnectionProxy +- [[#5104](https://github.com/seata/seata/pull/5104)] remove the druid dependency in ConnectionProxy ### test: diff --git a/changes/zh-cn/develop.md b/changes/zh-cn/develop.md index 9f8d58a402b..df8803a8249 100644 --- a/changes/zh-cn/develop.md +++ b/changes/zh-cn/develop.md @@ -70,7 +70,7 @@ - [[#5047](https://github.com/seata/seata/pull/5047)] 移除无用代码 - [[#5051](https://github.com/seata/seata/pull/5051)] 回滚时undolog产生脏写需要抛出不再重试(BranchRollbackFailed_Unretriable)的异常 - [[#5075](https://github.com/seata/seata/pull/5075)] 拦截没有主键及唯一索引值的insert on duplicate update语句 -- [[#5104](https://github.com/seata/seata/pull/5075)] ConnectionProxy脱离对druid的依赖 +- [[#5104](https://github.com/seata/seata/pull/5104)] ConnectionProxy脱离对druid的依赖 ### test: - [[#4411](https://github.com/seata/seata/pull/4411)] 测试Oracle数据库AT模式下类型支持 From 783411b381128943363ae7536d265e05dc58dd82 Mon Sep 17 00:00:00 2001 From: zhangjiawei <349071347@qq.com> Date: Wed, 23 Nov 2022 23:26:54 +0800 Subject: [PATCH 5/5] change develop.md --- changes/en-us/develop.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changes/en-us/develop.md b/changes/en-us/develop.md index 0a491734089..53bbe196e55 100644 --- a/changes/en-us/develop.md +++ b/changes/en-us/develop.md @@ -47,7 +47,7 @@ Add changes here for all PR submitted to the develop branch. - [[#4750](https://github.com/seata/seata/pull/4750)] optimize unBranchLock romove xid - [[#4797](https://github.com/seata/seata/pull/4797)] optimize the github actions - [[#4800](https://github.com/seata/seata/pull/4800)] Add NOTICE as Apache License V2 -- [[#4681](https://github.com/seata/seata/pull/4681)] optimize lock priority attempts to insert +- [[#4681](https://github.com/seata/seata/pull/4681)] optimize the check lock during global transaction - [[#4761](https://github.com/seata/seata/pull/4761)] use hget replace hmget because only one field - [[#4414](https://github.com/seata/seata/pull/4414)] exclude log4j dependencies - [[#4836](https://github.com/seata/seata/pull/4836)] optimize BaseTransactionalExecutor#buildLockKey(TableRecords rowsIncludingPK) method more readable