Skip to content
Snippets Groups Projects
Unverified Commit d4b20ece authored by 曹华栋's avatar 曹华栋 Committed by GitHub
Browse files

bugfix: fix the case that could not retry acquire global lock (#3687)

parent a8e553f5
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
<version>1.4.2</version>
<version>1.5.0-SNAPSHOT</version>
<name>Seata All-in-one ${project.version}</name>
<url>http://seata.io</url>
......
......@@ -20,7 +20,7 @@
<groupId>io.seata</groupId>
<artifactId>seata-bom</artifactId>
<version>1.4.2</version>
<version>1.5.0-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
......
......@@ -29,6 +29,7 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
- [[#3678](https://github.com/seata/seata/pull/3678)] 补充遗漏的配置及新版本pr登记md文件
- [[#3654](https://github.com/seata/seata/pull/3654)] 修正拼写,applicationContex -> applicationContext
- [[#3687](https://github.com/seata/seata/pull/3687)] 修复某些场景下无法重试全局锁的问题
### test:
......@@ -40,6 +41,7 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单
- [slievrly](https://github.com/slievrly)
- [a364176773](https://github.com/a364176773)
- [drgnchan](https://github.com/drgnchan)
- [caohdgege](https://github.com/caohdgege)
......
......@@ -29,6 +29,8 @@
- [[#3678](https://github.com/seata/seata/pull/3678)] supplement missing configuration and new version documents
- [[#3654](https://github.com/seata/seata/pull/3654)] fix typo,applicationContex -> applicationContext
- [[#3687](https://github.com/seata/seata/pull/3687)] fix the case that could not retry acquire global lock
### test:
......@@ -39,8 +41,9 @@
- [slievrly](https://github.com/slievrly)
- [a364176773](https://github.com/a364176773)
- [drgnchan](https://github.com/drgnchan)
- [caohdgege](https://github.com/caohdgege)
Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
......
......@@ -32,7 +32,7 @@ public class Version {
/**
* The constant CURRENT.
*/
private static final String CURRENT = "1.4.2";
private static final String CURRENT = "1.5.0-SNAPSHOT";
private static final String VERSION_0_7_1 = "0.7.1";
private static final int MAX_VERSION_DOT = 3;
......
......@@ -89,7 +89,7 @@
<properties>
<!-- seata version -->
<revision>1.4.2</revision>
<revision>1.5.0-SNAPSHOT</revision>
<!-- Compiler settings properties -->
<maven.compiler.source>1.8</maven.compiler.source>
......
......@@ -48,7 +48,9 @@ public class ConnectionProxy extends AbstractConnectionProxy {
private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionProxy.class);
private ConnectionContext context = new ConnectionContext();
private final ConnectionContext context = new ConnectionContext();
private final LockRetryPolicy lockRetryPolicy = new LockRetryPolicy(this);
private static final int REPORT_RETRY_COUNT = ConfigurationFactory.getInstance().getInt(
ConfigurationKeys.CLIENT_REPORT_RETRY_COUNT, DEFAULT_CLIENT_REPORT_RETRY_COUNT);
......@@ -56,8 +58,6 @@ public class ConnectionProxy extends AbstractConnectionProxy {
public static final boolean IS_REPORT_SUCCESS_ENABLE = ConfigurationFactory.getInstance().getBoolean(
ConfigurationKeys.CLIENT_REPORT_SUCCESS_ENABLE, DEFAULT_CLIENT_REPORT_SUCCESS_ENABLE);
private final static LockRetryPolicy LOCK_RETRY_POLICY = new LockRetryPolicy();
/**
* Instantiates a new Connection proxy.
*
......@@ -184,7 +184,7 @@ public class ConnectionProxy extends AbstractConnectionProxy {
@Override
public void commit() throws SQLException {
try {
LOCK_RETRY_POLICY.execute(() -> {
lockRetryPolicy.execute(() -> {
doCommit();
return null;
});
......@@ -328,10 +328,21 @@ public class ConnectionProxy extends AbstractConnectionProxy {
protected static final boolean LOCK_RETRY_POLICY_BRANCH_ROLLBACK_ON_CONFLICT = ConfigurationFactory
.getInstance().getBoolean(ConfigurationKeys.CLIENT_LOCK_RETRY_POLICY_BRANCH_ROLLBACK_ON_CONFLICT, DEFAULT_CLIENT_LOCK_RETRY_POLICY_BRANCH_ROLLBACK_ON_CONFLICT);
protected final ConnectionProxy connection;
public LockRetryPolicy(ConnectionProxy connection) {
this.connection = connection;
}
public <T> T execute(Callable<T> callable) throws Exception {
if (LOCK_RETRY_POLICY_BRANCH_ROLLBACK_ON_CONFLICT) {
// the only case that not need to retry acquire lock hear is
// LOCK_RETRY_POLICY_BRANCH_ROLLBACK_ON_CONFLICT == true && connection#autoCommit == true
// because it has retry acquire lock when AbstractDMLBaseExecutor#executeAutoCommitTrue
if (LOCK_RETRY_POLICY_BRANCH_ROLLBACK_ON_CONFLICT && connection.getContext().isAutoCommitChanged()) {
return callable.call();
} else {
// LOCK_RETRY_POLICY_BRANCH_ROLLBACK_ON_CONFLICT == false
// or LOCK_RETRY_POLICY_BRANCH_ROLLBACK_ON_CONFLICT == true && autoCommit == false
return doRetryOnLockConflict(callable);
}
}
......
......@@ -172,10 +172,9 @@ public abstract class AbstractDMLBaseExecutor<T, S extends Statement> extends Ba
protected abstract TableRecords afterImage(TableRecords beforeImage) throws SQLException;
private static class LockRetryPolicy extends ConnectionProxy.LockRetryPolicy {
private final ConnectionProxy connection;
LockRetryPolicy(final ConnectionProxy connection) {
this.connection = connection;
super(connection);
}
@Override
......
......@@ -20,8 +20,9 @@ import io.seata.core.exception.TransactionExceptionCode;
import io.seata.core.model.BranchType;
import io.seata.core.model.ResourceManager;
import io.seata.rm.DefaultResourceManager;
import io.seata.rm.datasource.exec.LockConflictException;
import io.seata.rm.datasource.exec.LockWaitTimeoutException;
import io.seata.rm.datasource.mock.MockConnection;
import io.seata.rm.datasource.mock.MockDriver;
import io.seata.rm.datasource.undo.SQLUndoLog;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
......@@ -72,11 +73,10 @@ public class ConnectionProxyTest {
public void testLockRetryPolicyRollbackOnConflict() throws Exception {
boolean oldBranchRollbackFlag = (boolean) branchRollbackFlagField.get(null);
branchRollbackFlagField.set(null, true);
ConnectionProxy connectionProxy = new ConnectionProxy(dataSourceProxy, null);
connectionProxy.bind(TEST_XID);
ConnectionProxy connectionProxy = new ConnectionProxy(dataSourceProxy, new MockConnection(new MockDriver(), "", null)); connectionProxy.bind(TEST_XID);
connectionProxy.appendUndoLog(new SQLUndoLog());
connectionProxy.appendLockKey(lockKey);
Assertions.assertThrows(LockConflictException.class, connectionProxy::commit);
Assertions.assertThrows(LockWaitTimeoutException.class, connectionProxy::commit);
branchRollbackFlagField.set(null, oldBranchRollbackFlag);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment