最近線上頻繁的出現(xiàn)slave延時的情況,經(jīng)排查發(fā)現(xiàn)為用戶在刪除數(shù)據(jù)的時候,由于表主鍵的主鍵的缺少,同時刪除條件沒有索引,或或者刪除的條件過濾性極差,導(dǎo)致slave出現(xiàn)hang住,嚴重的影響了生產(chǎn)環(huán)境的穩(wěn)定性,也希望通過這篇博客,來加深主鍵在innodb引擎中的重要性,希望用戶在使用RDS,設(shè)計自己的表的時候,一定要為表加上主鍵,主鍵可以認為是innodb存儲引擎的生命,下面我們就來分析一下這個案例(本案例的生產(chǎn)環(huán)境的binlog為row模式,對于myisam存儲引擎也有同樣的問題):
(1).現(xiàn)象slave:
| mysql> show slave status/G;*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: xxx.xx.xx.xxMaster_User: replicatorMaster_Port: 3006Connect_Retry: 60Master_Log_File: mysql-bin.000006Read_Master_Log_Pos: 47465657Relay_Log_File: slave-relay.100383Relay_Log_Pos: 251Relay_Master_Log_File: mysql-bin.000006Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno: 0Last_Error:Skip_Counter: 0Exec_Master_Log_Pos: 18057461Relay_Log_Space: 29409335Until_Condition: NoneUntil_Log_File:Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master: 1339Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error:Last_SQL_Errno: 0Last_SQL_Error: |
slave的Seconds_Behind_Master一直在增加,slave出現(xiàn)hang住。
(2).解析當前slave執(zhí)行到的位置的binlog:
| mysqlbinlog -vvv /home/mysql/data3006/mysql/mysql-bin.000006 –start-position=18057461 >/tmp/2.log### UPDATE qianyi.dmpush_message_temp### WHERE### @1='fb5c72c9-0ac2-4800-93b2-b94dc9e1dd54′ /* VARSTRING(108) meta=108 nullable=1 is_null=0 */### @2=133 /* LONGINT meta=0 nullable=1 is_null=0 */### @3='20121012220000′ /* VARSTRING(42) meta=42 nullable=1 is_null=0 */### @4='0′ /* VARSTRING(24) meta=24 nullable=1 is_null=0 */ |
(3)分析:
模擬場景:
1.表中無主鍵,全表進行更新:
master:
表結(jié)構(gòu):
CREATE TABLE `dmpush_message_temp` (
`clientid` varchar(36) DEFAULT NULL,
`infoid` bigint(10) DEFAULT NULL,
`endtime` varchar(14) DEFAULT NULL,
`stat` varchar(8) DEFAULT NULL
) ENGINE=innodb DEFAULT CHARSET=utf8;
mysql> update dmpush_message_temp set stat=1 ;
Query OK, 226651 rows affected (1.69 sec)
Rows matched: 226651 Changed: 226651 Warnings: 0
a.binlog中第一個出現(xiàn)的update事務(wù)日志:
mysqlbinlog -vvv /home/mysql/data3006/mysql/mysql-bin.000007 >/tmp/test.log
2281772 ### UPDATE qianyi.dmpush_message_temp
2281773 ### WHERE
2281774 ### @1='fb5c72c9-0ac2-4800-93b2-b94dc9e1dd54′ /* VARSTRING(108) meta=108 nullable=1 is_null=0 */
新聞熱點
疑難解答
圖片精選