On Configuring Lock Timeout Settings

This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 关于设置锁超时配置

| username: terry0219

What is the difference between pessimistic-txn.wait-for-lock-timeout in TiKV and innodb_lock_wait_timeout in TiDB?

| username: Kamner | Original post link


  • The maximum time a pessimistic transaction waits in TiKV for other transactions to release locks. If it times out, an error will be returned to TiDB, and TiDB will retry acquiring the lock. The maximum lock wait time for a statement is controlled by innodb_lock_wait_timeout.
  • Default value: 1s
  • Minimum value: 1ms
| username: terry0219 | Original post link

It means that the lock timeout is first controlled by the wait-for-lock-timeout parameter. If the lock times out, then the innodb_lock_wait_timeout parameter controls the lock wait time. Is this understanding correct?

| username: Kamner | Original post link

Understanding from the architecture of TiDB, one is the control parameters of the TiKV server, and the other is the control parameters of the TiDB server SQL layer.

| username: tidb菜鸟一只 | Original post link

When you execute a statement on tidb-server, for example, to lock a row, it is pushed down to TiKV, and it starts waiting to acquire the lock. If the row is already locked, it waits for the wait-for-lock-timeout duration. If the lock is released within this time, it acquires the lock. If the lock is still present after this time and cannot be acquired, it falls back to tidb-server. Tidb-server then checks if the innodb_lock_wait_timeout has been exceeded. If it has, it directly reports MySQL error 1205. If it is still within the time limit, it continues to push down to TiKV to wait for the lock again, repeating this process.

You can understand it this way: when tidb-server tries to acquire a lock and fails, it repeatedly pushes down to TiKV. Each time, the waiting time in TiKV is controlled by wait-for-lock-timeout, but the total waiting time for the SQL on tidb-server is controlled by innodb_lock_wait_timeout.

| username: terry0219 | Original post link

Got it, thanks.

| username: shigp_TIDBER | Original post link

The official website should have an introduction to this.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.