Skip to content

Commit

Permalink
optimize: optimize lock release logic in AT transaction mode (#7002)
Browse files Browse the repository at this point in the history
  • Loading branch information
slievrly authored Nov 15, 2024
1 parent ba7c771 commit 89381a4
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 20 deletions.
1 change: 1 addition & 0 deletions changes/en-us/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Add changes here for all PR submitted to the develop branch.
- [[#6044](https://github.com/seata/seata/pull/6044)] optimize derivative product check base on mysql
- [[#6361](https://github.com/seata/seata/pull/6361)] optimize 401 issues for some links
- [[#6903](https://github.com/apache/incubator-seata/pull/6903)] optimize `tableMeta` cache scheduled refresh issue
- [[#7002](https://github.com/apache/incubator-seata/pull/7002)] optimize lock release logic in AT transaction mode

### security:
- [[#PR_NO](https://github.com/seata/seata/pull/PR_NO)] A brief and accurate description of PR
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 @@ -23,6 +23,7 @@
- [[#6044](https://github.com/seata/seata/pull/6044)] 优化MySQL衍生数据库判断逻辑
- [[#6361](https://github.com/seata/seata/pull/6361)] 优化部分链接 401 的问题
- [[#6903](https://github.com/apache/incubator-seata/pull/6903)] 优化`tableMeta`缓存定时刷新问题
- [[#7002](https://github.com/apache/incubator-seata/pull/7002)] 优化 AT 事务模式锁释放逻辑

### security:
- [[#PR_NO](https://github.com/seata/seata/pull/PR_NO)] 准确简要的PR描述
Expand Down
7 changes: 7 additions & 0 deletions common/src/main/java/io/seata/common/ConfigurationKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,16 @@ public interface ConfigurationKeys {

/**
* The constant ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE.
* This configuration is deprecated, please use {@link #ROLLBACK_FAILED_UNLOCK_ENABLE} instead.
*/
@Deprecated
String ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE = SERVER_PREFIX + "rollbackRetryTimeoutUnlockEnable";

/**
* The constant ROLLBACK_FAILED_UNLOCK_ENABLE.
*/
String ROLLBACK_FAILED_UNLOCK_ENABLE = SERVER_PREFIX + "rollbackFailedUnlockEnable";

/**
* the constant RETRY_DEAD_THRESHOLD
*/
Expand Down
169 changes: 164 additions & 5 deletions common/src/main/java/io/seata/common/DefaultValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,139 @@
import java.time.Duration;

/**
* @author xingfudeshi@gmail.com
* The interface Default values.
*
* @author xingfudeshi @gmail.com
*/
public interface DefaultValues {
/**
* The constant DEFAULT_CLIENT_LOCK_RETRY_INTERVAL.
*/
int DEFAULT_CLIENT_LOCK_RETRY_INTERVAL = 10;
/**
* The constant DEFAULT_TM_DEGRADE_CHECK_ALLOW_TIMES.
*/
int DEFAULT_TM_DEGRADE_CHECK_ALLOW_TIMES = 10;
/**
* The constant DEFAULT_CLIENT_LOCK_RETRY_TIMES.
*/
int DEFAULT_CLIENT_LOCK_RETRY_TIMES = 30;
/**
* The constant DEFAULT_CLIENT_LOCK_RETRY_POLICY_BRANCH_ROLLBACK_ON_CONFLICT.
*/
boolean DEFAULT_CLIENT_LOCK_RETRY_POLICY_BRANCH_ROLLBACK_ON_CONFLICT = true;
/**
* The constant DEFAULT_LOG_EXCEPTION_RATE.
*/
int DEFAULT_LOG_EXCEPTION_RATE = 100;
/**
* The constant DEFAULT_CLIENT_ASYNC_COMMIT_BUFFER_LIMIT.
*/
int DEFAULT_CLIENT_ASYNC_COMMIT_BUFFER_LIMIT = 10000;
/**
* The constant DEFAULT_TM_DEGRADE_CHECK_PERIOD.
*/
int DEFAULT_TM_DEGRADE_CHECK_PERIOD = 2000;
/**
* The constant DEFAULT_CLIENT_REPORT_RETRY_COUNT.
*/
int DEFAULT_CLIENT_REPORT_RETRY_COUNT = 5;
/**
* The constant DEFAULT_CLIENT_REPORT_SUCCESS_ENABLE.
*/
boolean DEFAULT_CLIENT_REPORT_SUCCESS_ENABLE = false;
/**
* The constant DEFAULT_CLIENT_TABLE_META_CHECK_ENABLE.
*/
boolean DEFAULT_CLIENT_TABLE_META_CHECK_ENABLE = true;
/**
* The constant DEFAULT_TABLE_META_CHECKER_INTERVAL.
*/
long DEFAULT_TABLE_META_CHECKER_INTERVAL = 60000L;
/**
* The constant DEFAULT_TM_DEGRADE_CHECK.
*/
boolean DEFAULT_TM_DEGRADE_CHECK = false;
/**
* The constant DEFAULT_CLIENT_SAGA_BRANCH_REGISTER_ENABLE.
*/
boolean DEFAULT_CLIENT_SAGA_BRANCH_REGISTER_ENABLE = false;
/**
* The constant DEFAULT_CLIENT_SAGA_RETRY_PERSIST_MODE_UPDATE.
*/
boolean DEFAULT_CLIENT_SAGA_RETRY_PERSIST_MODE_UPDATE = false;
/**
* The constant DEFAULT_CLIENT_SAGA_COMPENSATE_PERSIST_MODE_UPDATE.
*/
boolean DEFAULT_CLIENT_SAGA_COMPENSATE_PERSIST_MODE_UPDATE = false;

/**
* Shutdown timeout default 3s
*/
int DEFAULT_SHUTDOWN_TIMEOUT_SEC = 3;
/**
* The constant DEFAULT_SELECTOR_THREAD_SIZE.
*/
int DEFAULT_SELECTOR_THREAD_SIZE = 1;
/**
* The constant DEFAULT_BOSS_THREAD_SIZE.
*/
int DEFAULT_BOSS_THREAD_SIZE = 1;


/**
* The constant DEFAULT_SELECTOR_THREAD_PREFIX.
*/
String DEFAULT_SELECTOR_THREAD_PREFIX = "NettyClientSelector";
/**
* The constant DEFAULT_WORKER_THREAD_PREFIX.
*/
String DEFAULT_WORKER_THREAD_PREFIX = "NettyClientWorkerThread";
/**
* The constant DEFAULT_ENABLE_CLIENT_BATCH_SEND_REQUEST.
*/
@Deprecated
boolean DEFAULT_ENABLE_CLIENT_BATCH_SEND_REQUEST = true;
/**
* The constant DEFAULT_ENABLE_TM_CLIENT_BATCH_SEND_REQUEST.
*/
boolean DEFAULT_ENABLE_TM_CLIENT_BATCH_SEND_REQUEST = false;
/**
* The constant DEFAULT_ENABLE_RM_CLIENT_BATCH_SEND_REQUEST.
*/
boolean DEFAULT_ENABLE_RM_CLIENT_BATCH_SEND_REQUEST = true;
/**
* The constant DEFAULT_ENABLE_TC_SERVER_BATCH_SEND_RESPONSE.
*/
boolean DEFAULT_ENABLE_TC_SERVER_BATCH_SEND_RESPONSE = false;


/**
* The constant DEFAULT_BOSS_THREAD_PREFIX.
*/
String DEFAULT_BOSS_THREAD_PREFIX = "NettyBoss";
/**
* The constant DEFAULT_NIO_WORKER_THREAD_PREFIX.
*/
String DEFAULT_NIO_WORKER_THREAD_PREFIX = "NettyServerNIOWorker";
/**
* The constant DEFAULT_EXECUTOR_THREAD_PREFIX.
*/
String DEFAULT_EXECUTOR_THREAD_PREFIX = "NettyServerBizHandler";

/**
* The constant DEFAULT_TRANSPORT_HEARTBEAT.
*/
boolean DEFAULT_TRANSPORT_HEARTBEAT = true;
/**
* The constant DEFAULT_TRANSACTION_UNDO_DATA_VALIDATION.
*/
boolean DEFAULT_TRANSACTION_UNDO_DATA_VALIDATION = true;
/**
* The constant DEFAULT_TRANSACTION_UNDO_LOG_SERIALIZATION.
*/
String DEFAULT_TRANSACTION_UNDO_LOG_SERIALIZATION = "jackson";
/**
* The constant DEFAULT_ONLY_CARE_UPDATE_COLUMNS.
*/
boolean DEFAULT_ONLY_CARE_UPDATE_COLUMNS = true;
/**
* The constant DEFAULT_TRANSACTION_UNDO_LOG_TABLE.
Expand All @@ -86,35 +176,86 @@ public interface DefaultValues {
*/
String DEFAULT_DISTRIBUTED_LOCK_DB_TABLE = "distributed_lock";

/**
* The constant DEFAULT_TM_COMMIT_RETRY_COUNT.
*/
int DEFAULT_TM_COMMIT_RETRY_COUNT = 5;
/**
* The constant DEFAULT_TM_ROLLBACK_RETRY_COUNT.
*/
int DEFAULT_TM_ROLLBACK_RETRY_COUNT = 5;
/**
* The constant DEFAULT_GLOBAL_TRANSACTION_TIMEOUT.
*/
int DEFAULT_GLOBAL_TRANSACTION_TIMEOUT = 60000;

/**
* The constant DEFAULT_TX_GROUP.
*/
String DEFAULT_TX_GROUP = "default_tx_group";
/**
* The constant DEFAULT_TX_GROUP_OLD.
*/
@Deprecated
String DEFAULT_TX_GROUP_OLD = "my_test_tx_group";
/**
* The constant DEFAULT_TC_CLUSTER.
*/
String DEFAULT_TC_CLUSTER = "default";
/**
* The constant DEFAULT_GROUPLIST.
*/
String DEFAULT_GROUPLIST = "127.0.0.1:8091";

/**
* The constant DEFAULT_DATA_SOURCE_PROXY_MODE.
*/
String DEFAULT_DATA_SOURCE_PROXY_MODE = "AT";

/**
* The constant DEFAULT_DISABLE_GLOBAL_TRANSACTION.
*/
boolean DEFAULT_DISABLE_GLOBAL_TRANSACTION = false;

/**
* The constant SERVICE_DEFAULT_PORT.
*/
//currently not use and will be delete in the next version
@Deprecated
int SERVICE_DEFAULT_PORT = 8091;

/**
* The constant SERVICE_OFFSET_SPRING_BOOT.
*/
int SERVICE_OFFSET_SPRING_BOOT = 1000;

/**
* The constant SERVER_PORT.
*/
String SERVER_PORT = "seata.server.port";

/**
* The constant SERVER_DEFAULT_STORE_MODE.
*/
String SERVER_DEFAULT_STORE_MODE = "file";

/**
* The constant DEFAULT_SAGA_JSON_PARSER.
*/
String DEFAULT_SAGA_JSON_PARSER = "fastjson";

/**
* The constant DEFAULT_SERVER_ENABLE_CHECK_AUTH.
*/
boolean DEFAULT_SERVER_ENABLE_CHECK_AUTH = true;

/**
* The constant DEFAULT_LOAD_BALANCE.
*/
String DEFAULT_LOAD_BALANCE = "XID";
/**
* The constant VIRTUAL_NODES_DEFAULT.
*/
int VIRTUAL_NODES_DEFAULT = 10;

/**
Expand Down Expand Up @@ -256,9 +397,9 @@ public interface DefaultValues {
long DEFAULT_MAX_ROLLBACK_RETRY_TIMEOUT = -1L;

/**
* the const DEFAULT_ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE
* The constant DEFAULT_ROLLBACK_FAILED_UNLOCK_ENABLE.
*/
boolean DEFAULT_ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE = false;
boolean DEFAULT_ROLLBACK_FAILED_UNLOCK_ENABLE = false;

/**
* DEFAULT_DISTRIBUTED_LOCK_EXPIRE_TIME
Expand All @@ -270,16 +411,34 @@ public interface DefaultValues {
*/
boolean DEFAULT_ENABLE_BRANCH_ASYNC_REMOVE = false;

/**
* The constant DEFAULT_DB_MAX_CONN.
*/
int DEFAULT_DB_MAX_CONN = 100;

/**
* The constant DEFAULT_DB_MIN_CONN.
*/
int DEFAULT_DB_MIN_CONN = 10;

/**
* The constant DEFAULT_REDIS_MAX_IDLE.
*/
int DEFAULT_REDIS_MAX_IDLE = 100;

/**
* The constant DEFAULT_REDIS_MAX_TOTAL.
*/
int DEFAULT_REDIS_MAX_TOTAL = 100;

/**
* The constant DEFAULT_REDIS_MIN_IDLE.
*/
int DEFAULT_REDIS_MIN_IDLE = 10;

/**
* The constant DEFAULT_QUERY_LIMIT.
*/
int DEFAULT_QUERY_LIMIT = 1000;

/**
Expand Down
2 changes: 1 addition & 1 deletion script/config-center/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.rollbackRetryTimeoutUnlockEnable=false
server.rollbackFailedUnlockEnable=false
server.distributedLockExpireTime=10000
server.xaerNotaRetryTimeout=60000
server.session.branchAsyncQueueSize=5000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
import static io.seata.common.DefaultValues.DEFAULT_MAX_COMMIT_RETRY_TIMEOUT;
import static io.seata.common.DefaultValues.DEFAULT_MAX_ROLLBACK_RETRY_TIMEOUT;
import static io.seata.common.DefaultValues.DEFAULT_ROLLBACKING_RETRY_PERIOD;
import static io.seata.common.DefaultValues.DEFAULT_ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE;
import static io.seata.common.DefaultValues.DEFAULT_ROLLBACK_FAILED_UNLOCK_ENABLE;
import static io.seata.common.DefaultValues.DEFAULT_TIMEOUT_RETRY_PERIOD;
import static io.seata.common.DefaultValues.DEFAULT_UNDO_LOG_DELETE_PERIOD;

Expand Down Expand Up @@ -148,7 +148,10 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
ConfigurationKeys.MAX_ROLLBACK_RETRY_TIMEOUT, DEFAULT_MAX_ROLLBACK_RETRY_TIMEOUT);

private static final boolean ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE = ConfigurationFactory.getInstance().getBoolean(
ConfigurationKeys.ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE, DEFAULT_ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE);
ConfigurationKeys.ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE, DEFAULT_ROLLBACK_FAILED_UNLOCK_ENABLE);

private static final boolean ROLLBACK_FAILED_UNLOCK_ENABLE = ConfigurationFactory.getInstance().getBoolean(
ConfigurationKeys.ROLLBACK_FAILED_UNLOCK_ENABLE, DEFAULT_ROLLBACK_FAILED_UNLOCK_ENABLE);

private final ScheduledThreadPoolExecutor retryRollbacking =
new ScheduledThreadPoolExecutor(1, new NamedThreadFactory(RETRY_ROLLBACKING, 1));
Expand Down Expand Up @@ -318,15 +321,15 @@ protected void doLockCheck(GlobalLockQueryRequest request, GlobalLockQueryRespon
protected void timeoutCheck() {
SessionCondition sessionCondition = new SessionCondition(GlobalStatus.Begin);
sessionCondition.setLazyLoadBranch(true);
Collection<GlobalSession> beginGlobalsessions =
Collection<GlobalSession> beginGlobalSessions =
SessionHolder.getRootSessionManager().findGlobalSessions(sessionCondition);
if (CollectionUtils.isEmpty(beginGlobalsessions)) {
if (CollectionUtils.isEmpty(beginGlobalSessions)) {
return;
}
if (!beginGlobalsessions.isEmpty() && LOGGER.isDebugEnabled()) {
LOGGER.debug("Global transaction timeout check begin, size: {}", beginGlobalsessions.size());
if (!beginGlobalSessions.isEmpty() && LOGGER.isDebugEnabled()) {
LOGGER.debug("Global transaction timeout check begin, size: {}", beginGlobalSessions.size());
}
SessionHelper.forEach(beginGlobalsessions, globalSession -> {
SessionHelper.forEach(beginGlobalSessions, globalSession -> {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
globalSession.getXid() + " " + globalSession.getStatus() + " " + globalSession.getBeginTime() + " "
Expand All @@ -353,7 +356,7 @@ protected void timeoutCheck() {
return true;
});
});
if (!beginGlobalsessions.isEmpty() && LOGGER.isDebugEnabled()) {
if (!beginGlobalSessions.isEmpty() && LOGGER.isDebugEnabled()) {
LOGGER.debug("Global transaction timeout check end. ");
}

Expand Down Expand Up @@ -381,7 +384,7 @@ protected void handleRetryRollbacking() {
return;
}
if (isRetryTimeout(now, MAX_ROLLBACK_RETRY_TIMEOUT, rollbackingSession.getBeginTime())) {
if (ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE) {
if (ROLLBACK_RETRY_TIMEOUT_UNLOCK_ENABLE || ROLLBACK_FAILED_UNLOCK_ENABLE) {
rollbackingSession.clean();
}

Expand Down
Loading

0 comments on commit 89381a4

Please sign in to comment.