<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        GTIDsinMySQL5.6:Newreplicationprotocol;newwaystobr_MySQL

        來源:懂視網(wǎng) 責編:小采 時間:2020-11-09 19:16:02
        文檔

        GTIDsinMySQL5.6:Newreplicationprotocol;newwaystobr_MySQL

        GTIDsinMySQL5.6:Newreplicationprotocol;newwaystobr_MySQL:One of the MySQL 5.6 features many people are interested in is Global Transactions IDs (GTIDs). This is for a good reason: Reconnecting a slave to a new master has always been a challenge while it is so trivial when GTIDs are enabled. Howev
        推薦度:
        導讀GTIDsinMySQL5.6:Newreplicationprotocol;newwaystobr_MySQL:One of the MySQL 5.6 features many people are interested in is Global Transactions IDs (GTIDs). This is for a good reason: Reconnecting a slave to a new master has always been a challenge while it is so trivial when GTIDs are enabled. Howev
        One of the MySQL 5.6 features many people are interested in is Global Transactions IDs (GTIDs). This is for a good reason: Reconnecting a slave to a new master has always been a challenge while it is so trivial when GTIDs are enabled. However, using GTIDs is not only about replacing good old binlog file/position with unique identifiers, it is also using a new replication protocol. And if you are not aware of it, it can bite.

        Replication protocols: old vs new

        The old protocol is pretty straightforward: the slave connects to a given binary log file at a specific offset, and the master sends all the transactions from there.

        The new protocol is slightly different: the slave first sends the range of GTIDs it has executed, and then the master sends every missing transaction. It also guarantees that a transaction with a given GTID can only be executed once on a specific slave.

        In practice, does it change anything? Well, it may change a lot of things. Imagine the following situation: you want to start replicating from trx 4, but trx 2 is missing on the slave for some reason.

        new_protocol

        With the old replication protocol, trx 2 will never be executed while with the new replication protocol, itWILLbe executed automatically.

        Here are 2 common situations where you can see the new replication protocol in action.

        Skipping transactions

        It is well known that the good oldSET GLOBAL sql_slave_skip_counter = Nis no longer supported when you want to skip a transaction and GTIDs are enabled. Instead, to skip the transaction withGTID XXX:N, you have toinject an empty transaction:

        mysql> SET gtid_next = 'XXX:N';mysql> BEGIN; COMMIT;mysql> SET gtid_next = 'AUTOMATIC';

        mysql>SETgtid_next='XXX:N';

        mysql>BEGIN;COMMIT;

        mysql>SETgtid_next='AUTOMATIC';

        Why can’t we usesql_slave_skip_counter? Because of the new replication protocol!

        Imagine that we have 3 servers like the picture below:

        new_protocol2

        Let’s assume thatsql_slave_skip_counteris allowed and has been used on S2 to skip trx 2. What happens if you make S2 a slave of S1?

        Both servers will exchange the range of executed GTIDs, and S1 will realize that it has to send trx 2 to S2. Two options then:

      1. If trx 2 is still in the binary logs of S1, it will be sent to S2, and the transaction is no longer skipped.
      2. If trx 2 no longer exists in the binary logs of S1, you will get a replication error.
      3. This is clearly not safe, that’s whysql_slave_skip_counteris not allowed with GTIDs. The only safe option to skip a transaction is to execute a fake transaction instead of the real one.

        Errant transactions

        If you execute a transaction locally on a slave (called errant transaction in the MySQL documentation), what will happen if you promote this slave to be the new master?

        With the old replication protocol, basically nothing (to be accurate, data will be inconsistent between the new master and its slaves, but that can probably be fixed later).

        With the new protocol, the errant transaction will be identified as missing everywhere and will be automatically executed on failover, which has the potential to break replication.

        Let’s say you have a master (M), and 2 slaves (S1 and S2). Here are 2 simple scenarios where reconnecting slaves to the new master will fail (with different replication errors):

        # Scenario 1

        # S1mysql> CREATE DATABASE mydb;# Mmysql> CREATE DATABASE IF NOT EXISTS mydb;# Thanks to 'IF NOT EXITS', replication doesn't break on S1. Now move S2 to S1:# S2mysql> STOP SLAVE; CHANGE MASTER TO MASTER_HOST='S1'; START SLAVE;# This creates a conflict with existing data!mysql> SHOW SLAVE STATUS/G[...]Last_SQL_Errno: 1007 Last_SQL_Error: Error 'Can't create database 'mydb'; database exists' on query. Default database: 'mydb'. Query: 'CREATE DATABASE mydb'[...]
        # S1

        mysql>CREATEDATABASEmydb;

        # M

        mysql>CREATEDATABASEIFNOTEXISTSmydb;

        # Thanks to 'IF NOT EXITS', replication doesn't break on S1. Now move S2 to S1:

        # S2

        mysql>STOPSLAVE;CHANGEMASTERTOMASTER_HOST='S1';STARTSLAVE;

        # This creates a conflict with existing data!

        mysql>SHOWSLAVESTATUS/G

        [...]

        Last_SQL_Errno:1007

        Last_SQL_Error:Error'Can'tcreatedatabase'mydb';databaseexists' on query. Default database: 'mydb'. Query: 'CREATEDATABASEmydb'

        [...]

        # Scenario 2

        # S1mysql> CREATE DATABASE mydb;# Now, we'll remove this transaction from the binary logs# S1mysql> FLUSH LOGS;mysql> PURGE BINARY LOGS TO 'mysql-bin.000008';# Mmysql> CREATE DATABASE IF NOT EXISTS mydb;# S2mysql> STOP SLAVE; CHANGE MASTER TO MASTER_HOST='S1'; START SLAVE;# The missing transaction is no longer available in the master's binary logs!mysql> SHOW SLAVE STATUS/G[...]Last_IO_Errno: 1236Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'The slave is connecting using CHANGE MASTER TO MASTER_AUTO_POSITION = 1, but the master has purged binary logs containing GTIDs that the slave requires.'[...]
        # S1

        mysql>CREATEDATABASEmydb;

        # Now, we'll remove this transaction from the binary logs

        # S1

        mysql>FLUSHLOGS;

        mysql>PURGEBINARYLOGSTO'mysql-bin.000008';

        # M

        mysql>CREATEDATABASEIFNOTEXISTSmydb;

        # S2

        mysql>STOPSLAVE;CHANGEMASTERTOMASTER_HOST='S1';STARTSLAVE;

        # The missing transaction is no longer available in the master's binary logs!

        mysql>SHOWSLAVESTATUS/G

        [...]

        Last_IO_Errno:1236

        Last_IO_Error:Gotfatalerror1236frommasterwhenreadingdatafrombinarylog:'The slave is connecting using CHANGE MASTER TO MASTER_AUTO_POSITION = 1, but the master has purged binary logs containing GTIDs that the slave requires.'

        [...]

        As you can understand, errant transactions should be avoided with GTID-based replication. If you need to run a local transaction, your best option is to disable binary logging for that specific statement:

        mysql> SET SQL_LOG_BIN = 0;mysql> # Run local transaction

        mysql>SETSQL_LOG_BIN=0;

        mysql># Run local transaction

        Conclusion

        GTIDs are a great step forward in the way we are able to reconnect replicas to other servers. But they also come with new operational challenges. If you plan to use GTIDs, make sure you correctly understand the new replication protocol, otherwise you may end up breaking replication in new and unexpected ways.

        I’ll do more exploration about errant transactions in a future post.

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        GTIDsinMySQL5.6:Newreplicationprotocol;newwaystobr_MySQL

        GTIDsinMySQL5.6:Newreplicationprotocol;newwaystobr_MySQL:One of the MySQL 5.6 features many people are interested in is Global Transactions IDs (GTIDs). This is for a good reason: Reconnecting a slave to a new master has always been a challenge while it is so trivial when GTIDs are enabled. Howev
        推薦度:
        標簽: new to mysql
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 久久久久国产亚洲AV麻豆| 日韩免费一区二区三区| 浮力影院亚洲国产第一页| 亚洲精品无码专区久久| 成人免费毛片内射美女-百度| 久久久久亚洲Av无码专| 99久久免费看国产精品| 亚洲精品456在线播放| 亚洲免费一级视频| 麻豆va在线精品免费播放| 国产无遮挡又黄又爽免费视频| 亚洲人成色在线观看| 国产成人一区二区三区免费视频| 久久精品熟女亚洲av麻豆| 拔擦拔擦8x华人免费久久| 思思久久99热免费精品6| 精品亚洲一区二区三区在线播放| 9久热这里只有精品免费| 亚洲国产精品VA在线看黑人| 最近最好最新2019中文字幕免费| 亚洲国产日产无码精品| 成人免费视频小说| 日韩在线观看免费| 亚洲va久久久噜噜噜久久狠狠 | 又爽又高潮的BB视频免费看| 色屁屁在线观看视频免费| 在线亚洲午夜理论AV大片| 久久国产色AV免费观看| 亚洲色无码国产精品网站可下载| 四虎影视永久免费观看| 久久九九全国免费| 国产亚洲精品影视在线| 亚洲精品无码AV中文字幕电影网站| 成人A片产无码免费视频在线观看 成人电影在线免费观看 | 国产成人免费高清激情明星| 亚洲色无码国产精品网站可下载| 又粗又大又猛又爽免费视频| 国产好大好硬好爽免费不卡| 最新亚洲春色Av无码专区| 国产亚洲精品高清在线| 成人无码区免费A片视频WWW|