What is the TTL duration for a pessimistic lock?

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

Original topic: 悲观锁ttl时间是多久呢

| username: TiDBer_mJ6BSaZU

In the 2PC transaction process, if the primary row does not proceed to the second phase commit after prewrite, it will remain locked until the TTL expires, continuously blocking other transactions?

| username: zhh_912 | Original post link

If it is a pessimistic lock, you need to check the logs.

| username: TiDBer_jYQINSnf | Original post link

If the prewrite node is still alive and the transaction is too large, it will keep executing txn_heartbeat to extend the TTL. There is a check_txn_status; if this lock expires (indicating that the node that initially executed the prewrite has crashed), the lock will be cleaned up by other nodes.

| username: TiDBer_H5NdJb5Q | Original post link

  • By using the innodb_lock_wait_timeout variable, you can set the timeout period for transactions waiting for locks (the default value is 50 seconds). When the lock wait times out, it returns the MySQL-compatible error code 1205. If multiple transactions are waiting for the same lock to be released, the lock will be acquired roughly in the order of the transaction start ts.
| username: TiDBer_mJ6BSaZU | Original post link

50 seconds feels very long. If the prewrite node crashes and never commits, you need to wait for 50 seconds for the lock to expire and be cleared before other transactions can proceed.

| username: yytest | Original post link

Need to check the logs.