MySQL 5.6 5.7半同步的区别
2,264 total views, 3 views today
MySQL 5.6 主库执行事务后先提交,然后等待至少一个从库确认events写入到relay log并刷入到磁盘。但是,如果从库events并没有写成功,主库提交的事务并不回滚,主从不能保证一致性,此时主库比从库数据新。
MySQL 5.7 主库执行事务,要等待至少一个从库确认events写入relay log并刷入到磁盘后,再提交。这样就确保了主库、从库数据的一致性。因此,5.7的半同步也称为增强半同步(loose-less semi-sync replication)。
但是也有漏洞,比如从库commit成功,返回ACK给主库后,主库提交之前,主库宕机,此时从库数据反而比主库新。
MySQL 5.7
A slave indicates whether it is semisynchronous-capable when it connects to the master.
If semisynchronous replication is enabled on the master side and there is at least one semisynchronous slave, a thread that performs a transaction commit on the master blocks and waits until at least one semisynchronous slave acknowledges that it has received all events for the transaction, or until a timeout occurs.
The slave acknowledges receipt of a transaction’s events only after the events have been written to its relay log and flushed to disk.
If a timeout occurs without any slave having acknowledged the transaction, the master reverts to asynchronous replication. When at least one semisynchronous slave catches up, the master returns to semisynchronous replication.
Semisynchronous replication must be enabled on both the master and slave sides. If semisynchronous replication is disabled on the master, or enabled on the master but on no slaves, the master uses asynchronous replication.
MySQL 5.6
A slave indicates whether it is semisynchronous-capable when it connects to the master.
If semisynchronous replication is enabled on the master side and there is at least one semisynchronous slave, a thread that performs a transaction commit on the master blocks after the commit is done and waits until at least one semisynchronous slave acknowledges that it has received all events for the transaction, or until a timeout occurs.
The slave acknowledges receipt of a transaction’s events only after the events have been written to its relay log and flushed to disk.
If a timeout occurs without any slave having acknowledged the transaction, the master reverts to asynchronous replication. When at least one semisynchronous slave catches up, the master returns to semisynchronous replication.
Semisynchronous replication must be enabled on both the master and slave sides. If semisynchronous replication is disabled on the master, or enabled on the master but on no slaves, the master uses asynchronous replication.