mysql关于“异步复制”“同步复制”“半同步复制”“无损复制”的概念与区别
大概意思是说:
异步复制:主把事务写到binlog日志并不管从是否接收或者什么时候接收,commit之后,不会与
从发生ack之类的交互。
同步复制:当主提交一个事务,在主向前端返回一个commit成功的指令前,必须保证所有的从
已经提交了这个事务(所有从不但接收了,还必须apply了该事务日志)
半同步复制(5.7.2版本之前默认且唯一的一个参数值after_commit):主上客户端发出提交指令,
事务提交到了存储引擎后,等待从传递过来ack,再向前端返回成功的状态。与无损复制的区别
就是:如果在主上这个事务已经提交到了存储引擎,而正在等待从的ack过程中---这个时候发生
creash,则主上这个事务其实已经认为commit了,而从还没commit,在切换到从后,就会回滚
最后的这个事务,这个时候主从的时候其实就不一致了)
无损复制(5.7.2版本之后一个参数值after_sync):主上客户端发出提交指令,事务写入到了binlog,
传递到了从(事务写入到了relay.log且flush to disk中持久化到了磁盘的relay.log中 )然 后从给主
反馈一个ack,master才会把事务提交到存储引擎且返回到client一个commit成功的指令。
以下是官方文档解析:
In addition to the built-in asynchronous replication, MySQL 5.7 supports an interface to
semisynchronous replication that is implemented by plugins. This section discusses what
semisynchronous replication is and how it works. The following sections cover the
administrative interface to semisynchronous replication and how to install, configure, and
monitor it.
(异步复制)
MySQL replication by default is asynchronous. The master writes events to its binary log but
does not know whether or when a slave has retrieved and processed them. With
asynchronous replication, if the master crashes, transactions that it has committed might not
have been transmitted to any slave.
Consequently, failover from master to slave in this case may result in failover to a server that is
missing transactions relative to the master.
Semisynchronous replication can be used as an alternative to asynchronous replication:
• 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
评论4