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

optimize: remove druid dependency in ConnectionProxy #5104

Merged
merged 6 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion changes/en-us/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/5104)] remove the druid dependency in ConnectionProxy


### test:
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/5104)] ConnectionProxy脱离对druid的依赖

### test:
- [[#4411](https://github.com/seata/seata/pull/4411)] 测试Oracle数据库AT模式下类型支持
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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());
Expand Down