從庫宕機引發的主鍵衝突

剛剛接到報警短信,從庫宕機,馬上通知機房重啓,在檢查MySQL時,發現同步掛了,報主鍵衝突,詢問開發是不是有往裏面寫數據,回答沒有。


這就奇怪了,怎麼會無緣無故報錯呢?在檢查了my.cnf配置文件,發現有個參數沒有配置:

innodb_overwrite_relay_log_info = 1


當從庫宕機後,重新開啓主從複製同步,它可以重新執行已提交事務,這樣就會造成同步失敗,而這個參數就會避免這個問題的出現。


當開啓了這個參數後

....
+ InnoDB: Warning: innodb_overwrite_relay_log_info is enabled. Updates of other storage engines may have problem of consistency.
+ InnoDB: relay-log.info is detected.
+ InnoDB: relay log: position 429, file name ./gauntlet3-relay-bin.000111
+ InnoDB: master log: position 280, file name gauntlet3-bin.000015
....
  InnoDB: Starting crash recovery.
....
  InnoDB: Apply batch completed
+ InnoDB: In a MySQL replication slave the last master binlog file
+ InnoDB: position 0 468, file name gauntlet3-bin.000015
+ InnoDB: and relay log file
+ InnoDB: position 0 617, file name ./gauntlet3-relay-bin.000111
  090205 17:41:31 InnoDB Plugin 1.0.2-3 started; log sequence number 57933
+ InnoDB: relay-log.info have been overwritten.
....
  090205 17:41:31 [Note] Slave SQL thread initialized, starting replication in log ``gauntlet3-bin.000015`` at position 468, relay log ``./gauntlet3-relay-bin.000111`` position: 617


已經執行完的Position點:

master log: position 280, file name gauntlet3-bin.000015

在恢復時它內部會檢測到280這個點已經執行完畢,從下一個點468開始同步,並且重寫relay.info文件,確保了主從同步正確。


建議在從庫上添加,如果是官方MySQL,參數是relay_log_recovery=1


具體請參考:http://www.percona.com/doc/percona-server/5.5/reliability/crash_resistant_replication.html



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章