cherrypick: add lock wait time#24885
Open
daviszhen wants to merge 1 commit into
Open
Conversation
1, 启用lock_wait_timeout session 级别变量. mysql也有. 用户可以设置此值. lock_wait_timeout 的默认值 `31536000 (1 year)`, 能兼容目前的行为. 如果用户设置了超时时间就用用户的值. 2, 增加lock rpc timeout . 如果lock_wait_timeout设置了, lock rpc timeout 就用 lock_wait_timeout值. 避免几个小时加锁傻等. 3, 修改lockoption 增加lockwaittimeout选项. 4, 给 RPC 加 slack(宽松预算):RPC 超时 = lock_wait_timeout + 30s,让服务端有足够时间返回超时结果 5, 服务端异步路径也强制检查超时:之前异步路径(远程锁走这条)从不检查 LockWaitTimeout,现在 waiterEvents.check() 里会定期检查并通知超时 6, 客户端翻译 deadline 错误:如果 RPC deadline 到了但 caller context 还没到,说明是锁超时而非连接问题,直接翻译成 ErrLockTimeout 修改后的效果: session 1 begin个事务, 加行锁. session 2 delete 行, 等锁, 超时 ``` session1 MySQL [test]> select * from t1; +------+ | a | +------+ | 2 | | 3 | | 4 | | 1 | +------+ 4 rows in set (0.001 sec) MySQL [test]> MySQL [test]> MySQL [test]> begin; Query OK, 0 rows affected (0.000 sec) MySQL [test]> select * from t1 where a = 1 for update; +------+ | a | +------+ | 1 | +------+ 1 row in set (0.001 sec) MySQL [test]> ``` ``` session2 MySQL [test]> select @@session.lock_wait_timeout; +---------------------+ | @@lock_wait_timeout | +---------------------+ | 180 | +---------------------+ 1 row in set (0.000 sec) MySQL [test]> delete from t1 where a = 1; ERROR 1105 (HY000): context deadline exceeded MySQL [test]> ``` Approved by: @iamlinjunhong, @ouyuanning, @XuPeng-SH, @aunjgr, @fengttt
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
aptend
approved these changes
Jun 8, 2026
aptend
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Reviewed the lock_wait_timeout propagation from session/txn options into lock options, local and remote lock wait handling, async waiter timeout path, and related tests. No blocking issues found.
aunjgr
approved these changes
Jun 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
issue ##24420
What this PR does / why we need it:
1, 启用lock_wait_timeout session 级别变量. mysql也有. 用户可以设置此值. lock_wait_timeout 的默认值
31536000 (1 year), 能兼容目前的行为. 如果用户设置了超时时间就用用户的值. 2, 增加lock rpc timeout . 如果lock_wait_timeout设置了, lock rpc timeout 就用 lock_wait_timeout值.避免几个小时加锁傻等.
3, 修改lockoption 增加lockwaittimeout选项.
4, 给 RPC 加 slack(宽松预算):RPC 超时 = lock_wait_timeout + 30s,让服务端有足够时间返回超时结果 5, 服务端异步路径也强制检查超时:之前异步路径(远程锁走这条)从不检查 LockWaitTimeout,现在 waiterEvents.check() 里会定期检查并通知超时 6, 客户端翻译 deadline 错误:如果 RPC deadline 到了但 caller context 还没到,说明是锁超时而非连接问题,直接翻译成 ErrLockTimeout
修改后的效果:
session 1 begin个事务, 加行锁.
session 2 delete 行, 等锁, 超时