mysql The difference between semi synchronous replication and lossless semi synchronous replication ：
Lossless replication is actually right semi sync Added rpl_semi_sync_master_wait_point Parameters , To control the way in which the master database submits the transaction before returning to the session transaction in semi synchronous mode .rpl_semi_sync_master_wait_point This parameter has two values ：AFTER_COMMIT and AFTER_SYNC
The first value is ：AFTER_COMMIT（5.6 The default value is ）
master Write each transaction to binlog（sync_binlog=1）, Pass on to slave Refresh to disk (sync_relay=1), At the same time, the main library commits transactions .master wait for slave Feedback received relay log, Only received ACK after master Only then commit OK The results are fed back to the client .
Second value ：AFTER_SYNC（5.7 The default value is , but 5.6 There's no such pattern in ）
master Write each transaction to binlog , Pass on to slave Refresh to disk (relay log).master wait for slave Feedback received relay log Of ack after , Then commit the transaction and return commit OK Result to client . Even if the main library crash, All transactions that have been committed on the main database can be synchronized to slave Of relay log in .
Semi synchronous replication versus lossless replication
1) ACK At different times
- Semi synchronous replication in InnoDB Layer of Commit Log Wait for ACK, There is a risk of data loss in master-slave switching .
- Lossless replication in MySQL Server Layer of Write binlog Wait for ACK, There is a risk of data becoming more and more when switching between master and slave .
2) Master slave data consistency
- Semi synchronous replication means in Master Node , The modification of the database by the just submitted thing , It's visible to other things . therefore , If you are waiting Slave ACK When crash 了 , Then there will be illusions about other things , Data loss .
- Lossless replication in write binlog When it's done, transmit binlog, But not yet commit log, It means that the current thing changes the database , Other things are also invisible . therefore , There's no magic reading , Risk of data loss .
therefore 5.7 The introduction of lossless replication （after_sync） Pattern , The main benefit is to solve after_commit As a result of master crash After the data loss problem , Therefore, in the introduction of after_sync After the model , All submitted data has been copied , Data consistency will be improved in the event of a failure .