Bug #102647 | Replica sql_thread getting stuck due to MASTER_DELAY | ||
---|---|---|---|
Submitted: | 18 Feb 2021 16:33 | Modified: | 23 Jan 5:29 |
Reporter: | Alok Pathak | Email Updates: | |
Status: | Won't fix | Impact on me: | |
Category: | MySQL Server: Replication | Severity: | S3 (Non-critical) |
Version: | 5.7, 5.7.33 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[18 Feb 2021 16:33]
Alok Pathak
[19 Feb 2021 7:34]
Venkatesh Prasad Venugopal
Problem ------- The replication applier thread in a multi-threaded replica can randomly get stuck in Waiting until MASTER_DELAY seconds after master executed event and doesn't apply any transaction for a long time when the replica is configured with MASTER_DELAY. Background ---------- After the bugfix of BUG#17326020, when the receiver thread reconnects to its source using GTID auto positioning while in the middle of a transaction, it leaves the partial transaction on the relaylog as is and will fully retrieve the same transaction again. While doing so, the receiver thread, as per GTID auto-position protocol will write master's FORMAT_DESCRIPTION_EVENT with log_pos != 0 into the relay log after each (re)connection. This FORMAT_DESCRIPTION_EVENT shall look like below in the relay log. ===BEGIN=== # at 4 #210215 16:18:05 server id 1 end_log_pos 123 CRC32 0x1120fc25 Start: binlog v 4, server v 5.7.32-35-debug-log created 210215 16:18:05 # This Format_description_event appears in a relay log and was generated by the slave thread. # at 123 #210215 16:18:05 server id 1 end_log_pos 154 CRC32 0xa29c149c Previous-GTIDs # [empty] # at 154 #700101 5:30:00 server id 1111 end_log_pos 0 CRC32 0x93c56c74 Rotate to mysql-bin.000001 pos: 4 # at 201 #210215 14:19:18 server id 1111 end_log_pos 123 CRC32 0x25802c3f Start: binlog v 4, server v 5.7.32-35-debug-log created 210215 14:19:18 at startup ROLLBACK/*!*/; BINLOG ' jjUqYA9XBAAAdwAAAHsAAAAAAAQANS43LjMyLTM1LWRlYnVnLWxvZwAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAACONSpgEzgNAAgAEgAEBAQEEgAAXwAEGggAAAAICAgCAAAACgoKKioAEjQA AT8sgCU= '/*!*/; # at 320 #210215 16:18:05 server id 0 end_log_pos 367 CRC32 0xdd12fd05 Rotate to mysql-bin.000001 pos: 154 # at 367 ===BEGIN=== When the applier thread starts applying the FORMAT_DESCRIPTION_EVENT (at position 201), it checks if it is in the middle of a group. If it is, it will queue to the current worker a QUERY(ROLLBACK) event to make the worker gracefully finish its work before starting to apply the new (complete) copy of the group, and only after that it will let the MTS coordinator to apply the ROTATE_LOG_EVENT (at position 320) in synchronous mode. Analysis -------- In our tests, it was observed that the replication applier thread got stuck when it was applying the Query_log_event (ROLLBACK) as part of handling the partial relay log event. On further investigation, it was found that the Query_log_event (for BEGIN/ROLLBACK) created by the applier thread had the current time as its timestamp. As a result, the delay function `slave_sleep()` slept for MASTER_DELAY seconds since the event timestamp was less than the evaluated current timestamp. Suggested Fix ------------- Make the BEGIN/ROLLBACK query to execute with same timestamp as that of the master's FORMAT_DESCRIPTION_EVENT in `coord_handle_partial_binlogged_transaction()` function.
[19 Feb 2021 7:35]
Venkatesh Prasad Venugopal
Patch based on 5.7.33 (*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.
Contribution: 0001-Bug-102647-Replica-sql_thread-getting-stuck-due-to-M.patch (text/x-patch), 14.31 KiB.
[19 Feb 2021 7:48]
Venkatesh Prasad Venugopal
Steps to Reproduce: Using mysqld debug binary, start two 5.7.33 GTID enabled servers using MTR ./mtr --suite=rpl --start --mem --mysqld=--gtid-mode=on --mysqld=--enforce-gtid-consistency=on --mysqld=--log-slave-updates --mysqld=--slave-parallel-workers=4 Replica: CHANGE MASTER TO master_host='127.0.0.1', master_port=13000, master_user='root', master_auto_position=1; CHANGE MASTER TO MASTER_DELAY=50; SET GLOBAL DEBUG='d,stop_io_after_reading_gtid_log_event'; START SLAVE; Source: CREATE TABLE t1(i INT) ENGINE=InnoDB; As soon as you execute the above CREATE TABLE query, we can see that the receiver thread on the replica server goes down and the applier thread starts executing the event and shall wait for 50 seconds. Once SQL thread reaches back to "Slave has read all relay log; waiting for more updates" state, now execute START SLAVE IO_THREAD on the replica server. mysql> start slave io_thread; select sleep(1); show slave status\G Query OK, 0 rows affected (0.00 sec) +----------+ | sleep(1) | +----------+ | 0 | +----------+ 1 row in set (1.00 sec) *************************** 1. row *************************** Slave_IO_State: Master_Host: 127.0.0.1 Master_User: root Master_Port: 13000 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 394 Relay_Log_File: slave-relay-bin.000014 Relay_Log_Pos: 454 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: No Slave_SQL_Running: Yes ... Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 329 Relay_Log_Space: 1091 ... Seconds_Behind_Master: 3280 ... Master_Server_Id: 1111 Master_UUID: b04f1158-6f6a-11eb-9d24-74d83e29c093 Master_Info_File: mysql.slave_master_info SQL_Delay: 50 SQL_Remaining_Delay: 29 Slave_SQL_Running_State: Waiting until MASTER_DELAY seconds after master executed event Master_Retry_Count: 10 ... Retrieved_Gtid_Set: b04f1158-6f6a-11eb-9d24-74d83e29c093:1 Executed_Gtid_Set: b04f1158-6f6a-11eb-9d24-74d83e29c093:1 Auto_Position: 1 ... 1 row in set (0.00 sec) We can now see that the SQL thread enters wait every time we execute START SLAVE IO_THREAD.
[19 Feb 2021 13:25]
MySQL Verification Team
Thank you Venu, Alok for the test case and report. Verified as described with 5.7.33 build. regards, Umesh
[22 Feb 2021 18:57]
OCA Admin
Contribution submitted via Github - Bug #102647: Replica sql_thread getting stuck due to MASTER_DELAY (*) Contribution by Venkatesh Prasad Venugopal (Github venkatesh-prasad-v, mysql-server/pull/325#issuecomment-781891530): I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.
Contribution: git_patch_576255657.txt (text/plain), 14.30 KiB.
[13 Jul 2023 4:32]
Venkatesh Prasad Venugopal
Hi! Any updates on this? -- Venkatesh Venugopal
[6 Oct 2023 7:42]
MySQL Verification Team
Did this affect 8.0 ?
[18 Dec 2023 6:24]
MySQL Verification Team
Hello Venu, Sorry for my late response here. We(including your former colleague Justin) tried to reproduce the issue using your test case to see if this issue affects current GA 8.0.35 but not seeing any issues i.e SQL thread shows "Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates". Could you please confirm once from your end as well? Thank you. regards, Umesh
[22 Jan 7:53]
MySQL Verification Team
Hello Venu, Just following up. Could you please confirm if you are seeing the issue on 8.0 as well? Thank you. regards, Umesh
[22 Jan 11:35]
Venkatesh Prasad Venugopal
Hi Umesh, I confirm that this bug exists only in 5.7 and was not reproducible in 8.0. IIRC, this got fixed by one of the worklogs related to including granular timestamps in binlog. -- Venu
[22 Jan 12:39]
MySQL Verification Team
Thank you so much, Venu for the confirmation. regards, Umesh
[23 Jan 5:29]
MySQL Verification Team
Hello Alok, Venu, Thank you Venu for the confirmation. Since 5.7 is EOL, we won't be fixing this in 5.7. Closing this report for now(as reported problem not seen on 8.0). Thank you both of you for all the help. regards, Umesh