Introduction MySQL achieves high availability of the storage system through replication. Currently, MySQL supports the following replication methods:
This article mainly discusses MySQL semisynchronous replication. The basic process of semi-synchronous replication The implementation of MySQL semisynchronous replication is based on MySQL asynchronous replication. MySQL supports two slightly different kinds of semisynchronous replication: AFTER_SYNC and AFTER_COMMIT (controlled by rpl_semi_sync_master_wait_wait_point). When semi-synchronous replication is enabled, the Master will wait for the Slave's response or timeout before returning. When the slave times out, semisynchronous replication degenerates into asynchronous replication. This is also a problem with MySQL semi-synchronous replication. This article does not discuss the situation where Salve times out (does not discuss asynchronous replication). Basic process of semi-synchronous replication AFTER_SYNC mode The AFTER_SYNC mode is a semi-synchronous replication mode supported by MySQL 5.7, and is also the default semi-synchronous replication mode of MySQL 5.7:
Basic process of semi-synchronous replication AFTER_COMMIT mode MySQL 5.5 and 5.6 semisynchronous replication only supports AFTER_COMMIT:
Summary of AFTER_SYNC and AFTER_COMMIT AFTER_SYNC: After the log is copied to the Slave, the Master commits again. AFTER_COMMIT: After the Master commits, the log is copied to the Slave. Analysis of abnormal situations in AFTER_SYNC mode Abnormal situation 1: After the master goes down, the master-slave switch occurs. The master executes transaction T. Before flushing the binlog of transaction T to the hard disk, the master crashes. The slave is upgraded to the master. After the master is restarted, crash recovery will roll back transaction T. The primary and backup data are consistent. The master executes transaction T. After flushing the binlog of transaction T to the hard disk and before receiving the ACK from the slave, the master crashes (there is a pending log). The slave is upgraded to the master. 2.1 The slave has not received the binlog of transaction T. After the master restarts, crash recovery will directly submit the pending log. The primary and backup data are inconsistent. 2.2 The slave has received the binlog of transaction T. The primary and backup data are consistent. Abnormal situation 2: After the master crashes, the host is not switched. Just consider 2.1 in exception case 1. After the master is restarted, the pendinglog is submitted directly. At this time, the master and slave data are inconsistent: The slave connects to the master and obtains the binlog of transaction T through asynchronous replication. The primary and backup data are consistent. From the simple analysis of the above abnormal situation, we know that semi-synchronous replication needs to handle the special situation that the master crashes and restarts and there is a pending log (a binlog that the slave has not responded to). For the situation where the master fails and the master-slave switch is not performed: After crash recovery, the master waits for slave connections and replicates until at least one slave has replicated the binlog of all committed transactions. (SHOW MASTER STATUS on master and SELECT master_pos_wait() on slave). For the situation where the master fails and the master-slave switch is performed: After the old master is restarted, the pendinglog is rolled back during crash recovery. (Manually truncate the uncopied part of the master's binlog?) think Why after the master restarts, during the crash recovery process, does it directly commit pendinglog instead of retrying to request the slave's response? MySQL's asynchronous replication and semi-synchronous replication are both triggered by the slave, and the slave actively connects to the master to synchronize binlog. No master-slave switch occurs, and after the machine restarts, it is impossible to know which machine is the slave. Summarize MySQL semi-synchronous replication has the following problems:
Because MySQL has these problems in the consistency of master and standby data, which affects the 7*24 high-availability services of Internet businesses, major companies have launched their own "patches": Tencent's TDSQL, WeChat's PhxSQL, Alibaba's AliSQL, and NetEase's InnoSQL. MySQL officially launched a new replication mode in MySQL 5.7 - MySQL Group Replication. References Discussion on Data Consistency of MySQL Semi-Synchronous Replication MySQL High Availability Solutions Loss-less Semi-Synchronous Replication on MySQL 5.7.2 Enhanced semisync replication You may also be interested in:
|
<<: Detailed tutorial on installing PHP and Nginx on Centos7
>>: Vue implements sample code to disable browser from remembering password function
Table of contents 1. Page Rendering 2. Switch tag...
1. Mycat application scenarios Mycat has been dev...
Get the mongo image sudo docker pull mongo Run th...
This article example shares the specific code of ...
Previously, the images we used were all pulled fr...
The task of concurrency control in a database man...
Upgrade process: Original system: CentOS7.3 [root...
The front-end development department is growing, ...
Remote connection to MySQL fails, there may be th...
Since my development environment is to install Ce...
mysqldump tool backup Back up the entire database...
Table of contents 1. Project folder structure 1. ...
First download the compressed version of mysql, t...
Cookie It is a standard way to save the state of ...
Error scenario Use the mysql command in cmd to ad...