
# 持锁长事务导致后续业务报等锁超时的解决办法
#### 场景描述
业务侧实例上报错误码1205，等锁超时提示。
MySQL error code MY-001205 (ER_LOCK_WAIT_TIMEOUT): **Lock** **wait** **timeout** **exceeded**; try restarting transaction
#### 原因分析
1. 查看监控指标"行锁花费时间"，监控到行锁等待时间较长，说明该系统出现过锁冲突的现象。 监控指标详细内容请参考[查看监控指标](https://support.huaweicloud.com/usermanual-taurusdb/taurusdb_03_0088.html)。
   ![](https://support.huaweicloud.com/taurusdb_faq/figure/zh-cn_image_0000001882572216.png "点击放大")
   
2. 登录实例，执行如下SQL，查看系统当前存在的长事务，以及事务持有的行锁信息。
   ```
   select trx_mysql_thread_id, trx_id, trx_state, trx_started, trx_tables_locked, trx_rows_locked, trx_isolation_level, trx_query, trx_operation_state from information_schema.innodb_trx order by trx_started;
   ```
   ![](https://support.huaweicloud.com/taurusdb_faq/figure/zh-cn_image_0000001882732140.png "点击放大")
   - information_schema.innodb_trx表包含了当前innodb内部正在运行的事务信息。
   
   - trx_started：表示事务的开始时间，用来判断当前事务是否是长事务，当前时间减去开始时间就是事务的执行时间。
   
   - trx_state ：表示当前事务的状态，取值如下：
     - RUNNING：运行。
     
     - LOCK WAIT：等待锁。如果事务当前的状态是LOCK WAIT，即表示事务持有行锁。
     
     - ROLLING BACK：正在回滚。
     
     - COMMITTING：正在提交。
      
    
 
#### 解决方案
由于持锁长事务长时间未提交或回滚导致后续操作阻塞，如果持锁长事务已经阻塞了后续的业务，需要将长事务KILL，后续业务侧尽量避免持锁长事务。
