前言
从库sql线程报错:worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606; lock wait timeout exceeded; try restarting transaction。
该案例可以定位到引起锁超时的事务以及语句,但是没定位到根源。kill会话和重启slave线程均会卡住,最后通过重启数据库实例解决。
1 环境信息
数据库信息:mysql5.7.22
操作系统:centos linux release 7.5
2 错误描述
早晨主从延迟告警,登录从库:
mysql> show slave status\g;
*************************** 1. row ***************************
slave_io_state: waiting for master to send event
master_host: xxxxxxxxx
master_user: xxxxxxx
master_port: 3306
connect_retry: 1
master_log_file: mysql_bin.007010
read_master_log_pos: 6372081
relay_log_file: relay.007809
relay_log_pos: 1026664439
relay_master_log_file: mysql_bin.007009
slave_io_running: yes
slave_sql_running: yes
replicate_do_db:
replicate_ignore_db:
replicate_do_table:
replicate_ignore_table:
replicate_wild_do_table:
replicate_wild_ignore_table:
last_errno: 1205
last_error: coordinator stopped because there were error(s) in the worker(s). the most recent failure being: worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606. see error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
skip_counter: 0
exec_master_log_pos: 1026664226
relay_log_space: 1080115539
until_condition: none
until_log_file:
until_log_pos: 0
master_ssl_allowed: no
master_ssl_ca_file:
master_ssl_ca_path:
master_ssl_cert:
master_ssl_cipher:
master_ssl_key:
seconds_behind_master: 11075
master_ssl_verify_server_cert: no
last_io_errno: 0
last_io_error:
last_sql_errno: 1205
last_sql_error: coordinator stopped because there were error(s) in the worker(s). the most recent failure being: worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606. see error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
replicate_ignore_server_ids:
master_server_id: 9218
master_uuid: xxxxxxxx
master_info_file: mysql.slave_master_info
sql_delay: 0
sql_remaining_delay: null
slave_sql_running_state: waiting for workers to exit
master_retry_count: 86400
master_bind:
last_io_error_timestamp:
last_sql_error_timestamp: 221012 06:58:30
master_ssl_crl:
master_ssl_crlpath:
retrieved_gtid_set: aeef80c3-1cba-11ea-b233-00163e0ab1ca:528429488-566695017
executed_gtid_set: 5cdb505c-1cbc-11ea-98f6-00163e0f2394:1-10,
aeef80c3-1cba-11ea-b233-00163e0ab1ca:1-566672256
auto_position: 1
replicate_rewrite_db:
channel_name:
master_tls_version:
1 row in set (0.00 sec)
mysql> select * from performance_schema.replication_applier_status_by_worker limit 5\g
*************************** 2. row ***************************
channel_name:
worker_id: 2
thread_id: null
service_state: off
last_seen_transaction: aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257
last_error_number: 1205
last_error_message: worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606; lock wait timeout exceeded; try restarting transaction
last_error_timestamp: 2022-10-12 06:58:30
2022-10-12 06:58:30开始报错,报错如下:
last_error_number: 1205
last_error_message: worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606; lock wait timeout exceeded; try restarting transaction
last_error_timestamp: 2022-10-12 06:58:30
3 排查
3.1 查看processlist
mysql> show processlist;
--------- ----------------- ------------------- ------ ------------- --------- --------------------------------------------------------------- ------------------
| id | user | host | db | command | time | state | info |
--------- ----------------- ------------------- ------ ------------- --------- --------------------------------------------------------------- ------------------
| 42 | system user | | null | connect | 9260 | waiting for workers to exit | null |
| 43 | system user | | null | connect | 11063 | waiting for preceding transaction to commit | null |
| 1420811 | system user | | null | connect | 1359763 | waiting for master to send event | null |
| 1512587 | xxxxxxxxx | 172.16.4.14:32398 | null | binlog dump | 10926 | master has sent all binlog to slave; waiting for more updates | null |
| 1513330 | root | localhost | null | query | 0 | starting | show processlist |
--------- ----------------- ------------------- ------ ------------- --------- --------------------------------------------------------------- ------------------
3.2 查看正在运行事务
mysql> select * from information_schema.innodb_trx;
------------ ----------- --------------------- ----------------------- ------------------ ------------ --------------------- ----------- --------------------- ------------------- ------------------- ------------------ ----------------------- ----------------- ------------------- ------------------------- --------------------- ------------------- ------------------------ ---------------------------- --------------------------- --------------------------- ------------------ ----------------------------
| trx_id | trx_state | trx_started | trx_requested_lock_id | trx_wait_started | trx_weight | trx_mysql_thread_id | trx_query | trx_operation_state | trx_tables_in_use | trx_tables_locked | trx_lock_structs | trx_lock_memory_bytes | trx_rows_locked | trx_rows_modified | trx_concurrency_tickets | trx_isolation_level | trx_unique_checks | trx_foreign_key_checks | trx_last_foreign_key_error | trx_adaptive_hash_latched | trx_adaptive_hash_timeout | trx_is_read_only | trx_autocommit_non_locking |
------------ ----------- --------------------- ----------------------- ------------------ ------------ --------------------- ----------- --------------------- ------------------- ------------------- ------------------ ----------------------- ----------------- ------------------- ------------------------- --------------------- ------------------- ------------------------ ---------------------------- --------------------------- --------------------------- ------------------ ----------------------------
| 1703298045 | running | 2022-10-12 06:55:48 | null | null | 5004 | 43 | null | null | 0 | 2 | 3 | 1136 | 1 | 5001 | 0 | read committed | 1 | 1 | null | 0 | 0 | 0 | 0 |
------------ ----------- --------------------- ----------------------- ------------------ ------------ --------------------- ----------- --------------------- ------------------- ------------------- ------------------ ----------------------- ----------------- ------------------- ------------------------- --------------------- ------------------- ------------------------ ---------------------------- --------------------------- --------------------------- ------------------ ----------------------------
1 row in set (0.00 sec)
3.3 查看该线程最后执行语句
mysql> select a.sql_text, c.id, d.trx_started from performance_schema.events_statements_current a join performance_schema.threads b on a.thread_id = b.thread_id join information_schema.processlist c on b.processlist_id = c.id join information_schema.innodb_trx d on c.id = d.trx_mysql_thread_id where c.id = 43 order by d.trx_started\g
*************************** 1. row ***************************
sql_text: begin
id: 43
trx_started: 2022-10-12 06:55:48
1 row in set (0.00 sec)
3.4 错误日志
看报错,是有锁等待超时。查看错误日志:
2022-10-12t06:58:30.764087 08:00 48 [error] slave sql for channel '': worker thread retried transaction 10 time(s) in vain, giving up. consider raising the value of the slave_transaction_retries variable. error_code: 1205
2022-10-12t06:58:30.764099 08:00 48 [error] slave sql for channel '': worker 6 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672261' at master log mysql_bin.007009, end_log_pos 1029272183; lock wait timeout exceeded; try restarting transaction, error_code: 1205
2022-10-12t06:58:30.764111 08:00 44 [warning] slave sql for channel '': worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007009, end_log_pos 1028024606, error_code: 1205
2022-10-12t06:58:30.764145 08:00 44 [error] slave sql for channel '': worker thread retried transaction 10 time(s) in vain, giving up. consider raising the value of the slave_transaction_retries variable. error_code: 1205
2022-10-12t06:58:30.764156 08:00 44 [error] slave sql for channel '': worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606; lock wait timeout exceeded; try restarting transaction, error_code: 1205
2022-10-12t06:58:30.764609 08:00 42 [error] error running query, slave sql thread aborted. fix the problem, and restart the slave sql thread with "slave start". we stopped at log 'mysql_bin.007009' position 1026664226
可以看到2022-10-12 06:58:30报错,slave sql线程挂起([error] slave sql for channel '': worker thread retried transaction 10 time(s) in vain, giving up)。
下面是报错之前的信息。
2022-10-12t06:20:16.870943 08:00 42 [note] multi-threaded slave: coordinator has waited 3299801 times hitting slave_pending_jobs_size_max; current event size = 28148.
2022-10-12t06:20:17.415877 08:00 42 [note] multi-threaded slave: coordinator has waited 3299811 times hitting slave_pending_jobs_size_max; current event size = 17784.
2022-10-12t06:20:17.890645 08:00 42 [note] multi-threaded slave: coordinator has waited 3299821 times hitting slave_pending_jobs_size_max; current event size = 11503.
2022-10-12t06:20:18.434491 08:00 42 [note] multi-threaded slave: coordinator has waited 3299831 times hitting slave_pending_jobs_size_max; current event size = 28913.
2022-10-12t06:20:19.986829 08:00 42 [note] multi-threaded slave: coordinator has waited 3299841 times hitting slave_pending_jobs_size_max; current event size = 28142.
2022-10-12t06:20:20.481470 08:00 42 [note] multi-threaded slave: coordinator has waited 3299851 times hitting slave_pending_jobs_size_max; current event size = 26086.
2022-10-12t06:20:20.786977 08:00 42 [note] multi-threaded slave: coordinator has waited 3299861 times hitting slave_pending_jobs_size_max; current event size = 28296.
2022-10-12t06:20:20.861478 08:00 0 [note] innodb: page_cleaner: 1000ms intended loop took 4015ms. the settings might not be optimal. (flushed=10000 and evicted=0, during the time.)
2022-10-12t06:55:20.090999 08:00 42 [note] multi-threaded slave: coordinator has waited 3426631 times hitting slave_pending_jobs_size_max; current event size = 27986.
2022-10-12t06:55:20.176349 08:00 42 [note] multi-threaded slave: coordinator has waited 3426641 times hitting slave_pending_jobs_size_max; current event size = 25257.
2022-10-12t06:55:20.258600 08:00 42 [note] multi-threaded slave: coordinator has waited 3426651 times hitting slave_pending_jobs_size_max; current event size = 27961.
2022-10-12t06:55:20.381914 08:00 42 [note] multi-threaded slave: coordinator has waited 3426661 times hitting slave_pending_jobs_size_max; current event size = 22941.
2022-10-12t06:55:59.743955 08:00 44 [warning] slave sql for channel '': worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007009, end_log_pos 1028024606, error_code: 1205
2022-10-12t06:55:59.743958 08:00 48 [warning] slave sql for channel '': worker 6 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672261' at master log mysql_bin.007009, end_log_pos 1029272183; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007004, end_log_pos 1029272183, error_code: 1205
2022-10-12t06:56:11.883068 08:00 48 [warning] slave sql for channel '': worker 6 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672261' at master log mysql_bin.007009, end_log_pos 1029272183; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007004, end_log_pos 1029272183, error_code: 1205
2022-10-12t06:56:11.883127 08:00 44 [warning] slave sql for channel '': worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007009, end_log_pos 1028024606, error_code: 1205
2022-10-12t06:56:24.965242 08:00 48 [warning] slave sql for channel '': worker 6 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672261' at master log mysql_bin.007009, end_log_pos 1029272183; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007004, end_log_pos 1029272183, error_code: 1205
2022-10-12t06:56:24.965287 08:00 44 [warning] slave sql for channel '': worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007009, end_log_pos 1028024606, error_code: 1205
2022-10-12t06:56:39.049467 08:00 48 [warning] slave sql for channel '': worker 6 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672261' at master log mysql_bin.007009, end_log_pos 1029272183; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007004, end_log_pos 1029272183, error_code: 1205
2022-10-12t06:56:39.049541 08:00 44 [warning] slave sql for channel '': worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007009, end_log_pos 1028024606, error_code: 1205
2022-10-12t06:56:54.132776 08:00 48 [warning] slave sql for channel '': worker 6 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672261' at master log mysql_bin.007009, end_log_pos 1029272183; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007004, end_log_pos 1029272183, error_code: 1205
2022-10-12t06:56:54.132832 08:00 44 [warning] slave sql for channel '': worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007009, end_log_pos 1028024606, error_code: 1205
2022-10-12t06:57:10.227067 08:00 48 [warning] slave sql for channel '': worker 6 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672261' at master log mysql_bin.007009, end_log_pos 1029272183; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007004, end_log_pos 1029272183, error_code: 1205
2022-10-12t06:57:26.310615 08:00 48 [warning] slave sql for channel '': worker 6 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672261' at master log mysql_bin.007009, end_log_pos 1029272183; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007004, end_log_pos 1029272183, error_code: 1205
2022-10-12t06:57:26.310670 08:00 44 [warning] slave sql for channel '': worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007009, end_log_pos 1028024606, error_code: 1205
2022-10-12t06:57:42.403741 08:00 48 [warning] slave sql for channel '': worker 6 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672261' at master log mysql_bin.007009, end_log_pos 1029272183; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007004, end_log_pos 1029272183, error_code: 1205
2022-10-12t06:57:42.403799 08:00 44 [warning] slave sql for channel '': worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007009, end_log_pos 1028024606, error_code: 1205
2022-10-12t06:57:58.582153 08:00 48 [warning] slave sql for channel '': worker 6 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672261' at master log mysql_bin.007009, end_log_pos 1029272183; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007004, end_log_pos 1029272183, error_code: 1205
2022-10-12t06:57:58.582200 08:00 44 [warning] slave sql for channel '': worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007009, end_log_pos 1028024606, error_code: 1205
2022-10-12t06:58:14.665334 08:00 48 [warning] slave sql for channel '': worker 6 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672261' at master log mysql_bin.007009, end_log_pos 1029272183; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007004, end_log_pos 1029272183, error_code: 1205
2022-10-12t06:58:14.665413 08:00 44 [warning] slave sql for channel '': worker 2 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257' at master log mysql_bin.007009, end_log_pos 1028024606; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007009, end_log_pos 1028024606, error_code: 1205
2022-10-12t06:58:30.764049 08:00 48 [warning] slave sql for channel '': worker 6 failed executing transaction 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672261' at master log mysql_bin.007009, end_log_pos 1029272183; could not execute write_rows event on table test.t1; lock wait timeout exceeded; try restarting transaction, error_code: 1205; handler error ha_err_lock_wait_timeout; the event's master log mysql_bin.007004, end_log_pos 1029272183, error_code: 1205
3.5 解析主库binlog
根据报错的事务id,去binlog里面查。
主库:mysqlbinlog --base64-output=decode-rows -v mysql_bin.007009 |grep -b 20 -a 10000000 566672257 > 7009_1.sql
# at 1027686158
#221012 6:25:45 server id 9218 end_log_pos 1027686223 crc32 0x1d830f9a gtid last_committed=444 sequence_number=446 rbr_only=yes
/*!50718 set transaction isolation level read committed*//*!*/;
set @@session.gtid_next= 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257'/*!*/;
# at 1027686223
#221012 6:25:45 server id 9218 end_log_pos 1027686304 crc32 0x90dc9476 query thread_id=29311920 exec_time=0 error_code=0
set timestamp=1665527145/*!*/;
begin
/*!*/;
# at 1027686304
# at 1027860550
#221012 6:25:45 server id 9218 end_log_pos 1027860625 crc32 0x95107af1 table_map: `test`.`t1` mapped to number 7187
# at 1027860625
#221012 6:25:45 server id 9218 end_log_pos 1027868820 crc32 0xad3c9abc write_rows: table id 7187
# at 1027868820
#221012 6:25:45 server id 9218 end_log_pos 1027877022 crc32 0x00ede7d7 write_rows: table id 7187
# at 1027877022
#221012 6:25:45 server id 9218 end_log_pos 1027885215 crc32 0x08a47400 write_rows: table id 7187
# at 1027885215
#221012 6:25:45 server id 9218 end_log_pos 1027893429 crc32 0x77c4df5d write_rows: table id 7187
# at 1027893429
#221012 6:25:45 server id 9218 end_log_pos 1027901621 crc32 0x0c8f9049 write_rows: table id 7187
.......................................................
........................省略n条........................
.......................................................
# at 1028008214
#221012 6:25:45 server id 9218 end_log_pos 1028016400 crc32 0xb91812ad write_rows: table id 7187
# at 1028016400
#221012 6:25:45 server id 9218 end_log_pos 1028024606 crc32 0xad6cb550 write_rows: table id 7187
# at 1028024606
#221012 6:25:45 server id 9218 end_log_pos 1028026822 crc32 0x06dbbcbb write_rows: table id 7187 flags: stmt_end_f
### insert into `test`.`t1`
### set
### @1=88206936
### @2=15455906
### @3='145300'
### @4=1
### @5='2022-10-12 00:00:00'
.......................................................
........................省略n条........................
.......................................................
### insert into `test`.`t1`
### set
### @1=88211935
### @2=4312695
### @3='141165'
### @4=1
### @5='2022-10-12 00:00:00'
# at 1028026822
#221012 6:25:45 server id 9218 end_log_pos 1028026853 crc32 0x6143fd8c xid = 12669228146
commit/*!*/;
可以看到报错对应的aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257事务,为插入操作,插入了多条。
上面加粗下划线的position:1028024606为从库sql线程报错的位点,也是插入的最后,主库commit成功了。
4 原因
结合上面的thead_id=43查到的正在运行的事务信息,最后执行的语句为begin。考虑是从库执行该事务时,因为insert锁等待超过,导致事务失败。
登录主从库,查询test.t1表数据,从库确实确实该事务插入的60多万行数据。
主库:
mysql> select count(*) from test.t1 where update_time='2022-10-12';
----------
| count(*) |
----------
| 728490 |
----------
1 row in set (0.22 sec)
从库:
mysql> select count(*) from test.t1 where update_time='2022-10-12';
----------
| count(*) |
----------
| 95000 |
----------
1 row in set (0.02 sec)
5 m6米乐安卓版下载的解决方案
5.1 kill
首先kill 43这个会话,但是好几个小时后一直显示状态为killed。
5.2 重启
最后重启mysql实例解决。下面为重启过程中的日志信息
2022-10-12t15:43:43.087642 08:00 0 [note] innodb: log scan progressed past the checkpoint lsn 4545891666024
2022-10-12t15:43:43.087679 08:00 0 [note] innodb: doing recovery: scanned up to log sequence number 4545891666033
2022-10-12t15:43:43.087686 08:00 0 [note] innodb: database was not shutdown normally!
2022-10-12t15:43:43.087691 08:00 0 [note] innodb: starting crash recovery.
2022-10-12t15:43:43.973948 08:00 0 [note] innodb: transaction 1703298045 was in the xa prepared state.
2022-10-12t15:43:44.027245 08:00 0 [note] innodb: transaction 1703298045 was in the xa prepared state.
2022-10-12t15:43:44.052875 08:00 0 [note] innodb: 1 transaction(s) which must be rolled back or cleaned up in total 0 row operations to undo
2022-10-12t15:43:44.052890 08:00 0 [note] innodb: trx id counter is 1703548160
2022-10-12t15:43:44.110239 08:00 0 [note] innodb: last mysql binlog file position 0 59767338, file name mysql_bin.007004
2022-10-12t15:43:48.822730 08:00 0 [note] innodb: starting in background the rollback of uncommitted transactions
2022-10-12t15:43:48.822772 08:00 0 [note] innodb: rollback of non-prepared transactions completed
2022-10-12t15:43:48.855681 08:00 0 [note] innodb: removed temporary tablespace data file: "ibtmp1"
2022-10-12t15:43:48.855708 08:00 0 [note] innodb: creating shared tablespace for temporary tables
2022-10-12t15:43:48.855751 08:00 0 [note] innodb: setting file './ibtmp1' size to 12 mb. physically writing the file full; please wait ...
2022-10-12t15:43:48.927293 08:00 0 [note] innodb: file './ibtmp1' size is now 12 mb.
2022-10-12t15:43:48.928003 08:00 0 [note] innodb: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2022-10-12t15:43:48.928024 08:00 0 [note] innodb: 32 non-redo rollback segment(s) are active.
2022-10-12t15:43:48.979258 08:00 0 [note] innodb: 5.7.22 started; log sequence number 4545891666033
221012 15:43:49 server_audit: mariadb audit plugin version 1.4.4 started.
2022-10-12t15:43:49.031365 08:00 0 [note] semi-sync replication enabled on the master.
2022-10-12t15:43:49.124967 08:00 0 [note] innodb: 1 transactions in prepared state after recovery
2022-10-12t15:43:49.752538 08:00 0 [note] slave: mts group recovery relay log info group_master_log_name mysql_bin.007009, event_master_log_pos 1027345463.
2022-10-12t15:43:49.753026 08:00 0 [note] slave: mts group recovery relay log info group_master_log_name mysql_bin.007009, event_master_log_pos 1027686158.
2022-10-12t15:43:49.753052 08:00 0 [warning] recovery from master pos 1026664226 and file mysql_bin.007009 for channel ''. previous relay log pos and relay log file had been setto 1026664439, /data/mysql/mysql57_3306/relaylog/relay.007809 respectively.
2022-10-12t15:43:49.800123 08:00 0 [note] event scheduler: loaded 0 events
2022-10-12t15:43:49.800315 08:00 0 [note] /usr/local/mysql57/sbin/mysqld: ready for connections.
version: '5.7.22-log' socket: '/data/mysql/mysql57_3306/socketdir/mysql.sock' port: 3306 mysql community server (gpl)
2022-10-12t15:44:12.006048 08:00 15 [note] slave i/o thread: start semi-sync replication to master 'repl_user@172.16.9.218:3306' in log 'mysql_bin.007009' at position 1026664226
2022-10-12t15:44:12.007062 08:00 15 [warning] storing mysql user name or password information in the master info repository is not secure and is therefore not recommended. please consider using the user and password connection options for start slave; see the 'start slave syntax' in the mysql manual for more information.s
transaction 1703298045 was in the xa prepared state 显示1703298045 这个xa事务进行了恢复。和上面3.2步骤查到的一致。
5.3 解析从库binlog
从库:mysqlbinlog --base64-output=decode-rows -v mysql_bin.007005 |grep -b 20 -a 50 566672257 |more
/*!50530 set @@session.pseudo_slave_mode=1*/;
/*!50003 set @old_completion_type=@@completion_type,completion_type=0*/;
delimiter /*!*/;
# at 4
#221012 15:43:49 server id 9219 end_log_pos 123 crc32 0x238d52e8 start: binlog v 4, server v 5.7.22-log created 221012 15:43:49 at startup
# warning: this binlog is either in use or was not closed properly.
rollback/*!*/;
# at 123
#221012 15:43:49 server id 9219 end_log_pos 234 crc32 0xd11388da previous-gtids
# 5cdb505c-1cbc-11ea-98f6-00163e0f2394:1-10,
# aeef80c3-1cba-11ea-b233-00163e0ab1ca:1-566672256
# at 234
#221012 6:25:45 server id 9218 end_log_pos 299 crc32 0x3543e56f gtid last_committed=0 sequence_number=1 rbr_only=yes
/*!50718 set transaction isolation level read committed*//*!*/;
set @@session.gtid_next= 'aeef80c3-1cba-11ea-b233-00163e0ab1ca:566672257'/*!*/;
# at 299
#221012 6:25:45 server id 9218 end_log_pos 362 crc32 0xfaf82f74 query thread_id=29311920 exec_time=33513 error_code=0
set timestamp=1665527145/*!*/;
set @@session.pseudo_thread_id=29311920/*!*/;
set @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
set @@session.sql_mode=524288/*!*/;
set @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\c utf8mb4 *//*!*/;
set @@session.character_set_client=45,@@session.collation_connection=45,@@session.collation_server=45/*!*/;
set @@session.lc_time_names=0/*!*/;
set @@session.collation_database=default/*!*/;
begin
/*!*/;
# at 362
# at 174608
#221012 6:25:45 server id 9218 end_log_pos 174683 crc32 0x34735ed6 table_map: `test`.`t1` mapped to number 315
# at 174683
#221012 6:25:45 server id 9218 end_log_pos 182878 crc32 0xf01e4c33 write_rows: table id 315
# at 182878
#221012 6:25:45 server id 9218 end_log_pos 191080 crc32 0x36c5eb3e write_rows: table id 315
# at 191080
#221012 6:25:45 server id 9218 end_log_pos 199273 crc32 0xd6d9106c write_rows: table id 315
# at 199273
#221012 6:25:45 server id 9218 end_log_pos 207487 crc32 0x263e09a4 write_rows: table id 315
.......................................................
........................省略n条........................
.......................................................
6 补充
从库相关参数:
mysql> show variables like '%innodb_rollback_on_timeout%';
---------------------------- -------
| variable_name | value |
---------------------------- -------
| innodb_rollback_on_timeout | off |
---------------------------- -------
1 row in set (0.00 sec)
mysql> show variables like '%slave_transaction_retries%';
--------------------------- -------
| variable_name | value |
--------------------------- -------
| slave_transaction_retries | 10 |
--------------------------- -------
1 row in set (0.00 sec)
mysql> show variables like '%pending%';
----------------------------- ----------
| variable_name | value |
----------------------------- ----------
| slave_pending_jobs_size_max | 16777216 |
----------------------------- ----------
1 row in set (0.00 sec)
主库参数:
mysql> show variables like 'max_allowed_packet%';
-------------------- ----------
| variable_name | value |
-------------------- ----------
| max_allowed_packet | 67108864 |
-------------------- ----------
1 row in set (0.00 sec)
看m6米乐安卓版下载官网说法,从库的参数slave_pending_jobs_size_max要比主库的max_allowed_packet参数大才对。
后面如果再出现,会试一下。