Mysql 5.7 Gtid內部學習(七) 總結binlog_gtid_simple_recovery引數帶來的影響

gaopengtttt發表於2017-12-18

簡書地址:
http://www.jianshu.com/p/c9888d6447c8

想了想還是專門開了一節來總結這個問題
5.7.6以下中預設

  • simplified_binlog_gtid_recovery=flase

5.7.6以上中預設

  • binlog_gtid_simple_recovery=true

預設值就是最合理的設定。
因為引數名更改了所以下面統稱simple_recovery來代替。

一、Gtid關閉


  • simple_recovery=flase

5.7.6以下:這種方式一定得到正確的Gtid集合

  • 重啟Mysql需要掃描全部的binlog來獲得正確的Gtid集合
  • purge binlog或者超過引數expire_logs_days引數設定不觸發全binlog掃描,由上層函式控制。因為不支援線上的Gtid更改。

5.7.6以上:這種方式一定得到正確的Gtid集合

  • 重啟Mysql掃描全部的binlog。
  • purge binlog或者超過引數expire_logs_days引數設定觸發全binlog掃描。

  • simple_recovery=true

5.7.6以下:這種情況可能得不到正確的Gtid集合

  • 重啟Mysql不掃描全部的binlog,只掃描第一個和最後一個binlog。
  • purge binlog或者超過引數expire_logs_days引數設定不觸發全binlog掃描,由上層函式控制。

5.7.6以上:由於有每個binlog都有Previous gtid Event的支援能夠得到正確的Gtid集合。

  • 重啟Mysql不掃描全部的binlog,只掃描第一個和最後一個binlog。
  • purge binlog或者超過引數expire_logs_days引數設定不觸發全binlog掃描,只掃描第一個和最後一個binlog。

二、Gtid開啟


  • simple_recovery=flase

5.7.6以下:這種方式一定得到正確的Gtid集合。

  • 重啟Mysql不掃描全部的binlog,如果是中途開啟GTID,重啟任然需要掃描多個binlog因為需要找到Previous gtid Event。
  • purge binlog或者超過引數expire_logs_days引數設定不觸發全binlog掃描,如果是中途開啟GTID重啟,任然需要掃描多個binlog因為需要找到Previous gtid Event。

5.7.6以上:這種方式一定得到正確的Gtid集合

  • 重啟Mysql不掃秒全部的binlog,如果是中途開啟GTID重啟任然需要掃描多個binlog因為需要找到Gtid event。
  • purge binlog或者超過引數expire_logs_days引數設定不觸發全binlog掃描,如果是中途開啟GTID重啟任然需要掃描多個binlog因為需要找到Gtid event。

  • simple_recovery=true

5.7.6以下:這種情況可能得不到正確的Gtid集合

  • 重啟Mysql不掃描全部的binlog,只掃描第一個和最後一個binlog。
  • purge binlog或者超過引數expire_logs_days引數設定不掃描全部binlog,只掃描第一個和最後一個binlog。

5.7.6以上:由於有每個binlog都有Previous gtid Event的支援能夠得到正確的Gtid集合。

  • 重啟Mysql不掃描全部的binlog,只掃描第一個和最後一個binlog。
  • purge binlog或者超過引數expire_logs_days引數設定不觸發全binlog掃描,只掃描第一個和最後一個binlog。

三、本節總結

  • 5.7.6以下保持預設設定simplified_binlog_gtid_recovery=flase,但是這會導致過多的binlog掃描,況且5.6沒有mysql.gtid_executed的支援,從庫必須開啟log_slave_updates,這會帶來效能影響。所以還是少用Gtid。
  • 5.7.6以上由於對每個binlog都有Previous gtid Event的支援binlog_gtid_simple_recovery=true是合理的設定,binlog掃描非常的快因為只是第一個和最後一個binlog檔案而已。

可以看到Gtid也越來越成熟了。這部分的邏輯在函MYSQL_BIN_LOG::init_gtid_sets中前文已經提到過,這裡就不看程式碼了。

此外在5.7的官方文件中對binlog_gtid_simple_recovery=true 有如下警告的描述:

If this option is enabled, gtid_executed and gtid_purged may be
initialized incorrectly in the following situations:
? The newest binary log was generated by MySQL 5.7.5 or older, and
gtid_mode was ON for some binary logs but OFF for the newest binary log.
? A SET GTID_PURGED statement was issued on a MySQL version
prior to 5.7.7, and the binary log that was active at the time of the SET
GTID_PURGED has not yet been purged.
If an incorrect GTID set is computed in either situation, it will remain incorrect
even if the server is later restarted, regardless of the value of this option. 

如果將引數設定為true可能在老版本中得不到正確的Gtid集合,也是前面討論的。

學習完本節至少能夠學習到:

  • binlog_gtid_simple_recovery/simplified_binlog_gtid_recovery是如何影響binlog檔案的掃描的的
  • 5.7.6以下應該如何設定
  • 5.7.6以上應該如何設定

作者微信:


微信.jpg

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7728585/viewspace-2148840/,如需轉載,請註明出處,否則將追究法律責任。

相關文章