MySQL 5.7半同步复制after sync和after commit详解【转】
如果你的生产库开启了半同步复制,那么对数据的一致性会要求较高,但在MySQL5.5/5.6里,会存在数据不一致的风险。有这么一个场景,客户端提交了一个事务,master把binlog发送给slave,在发送的期间,网络出现波动,此时Binlog Dump线程发送就会卡住,要等待slave把binlog写到本地的relay-log里,然后给master一个反馈,等待的时间以rpl_semi_sync_master_timeout参数为准,默认为10秒。在这等待的10秒钟里,在其他会话里,查看刚才的事务是可以看见的,此时一旦master发生宕机,由于binlog没有发送给slave,前端app切到slave查看,就会发现刚才已提交的事务不见了。
为了解决这种问题,MySQL5.7
改善了半同步复制这个缺陷。通过rpl_semi_sync_master_wait_point这个参数加以控制,默认是AFTER_SYNC,官方推荐用这个,它的工作原理是:master把binlog发送给slave,只有在slave把binlog写到本地的relay-log里,才提交到存储引擎层,然后把请求返回给客户端,客户端才可以看见刚才提交的事务。如果slave未保存到本地的relay-log里,客户端是看不见刚才的事务的,这样就不会造成上述那个场景发生。另一个值是AFTER_COMMIT,这个值是采用老式的MySQL5.5/5.6半同步复制工作。
AFTER_SYNC (the default): The master writes each transaction to its
binary log and the slave, and syncs the binary log to disk. The master
waits for slave acknowledgment of transaction receipt after the sync.
Upon receiving acknowledgment, the master commits the transaction to the
storage engine and returns a result to the client, which then can
proceed.
主库把每一个事务写到二进制日志并保存磁盘上,且发送给从库。主库在等待从库写到自己的relay-log里确认信息。在接到确认信息后,主数据库把事务写到存储引擎里并把相应结果反馈给客户端,客户端将在那时进行处理。
AFTER_COMMIT: The master writes each transaction to its binary log and
the slave, syncs the binary log, and commits the transaction to the
storage engine. The master waits for slave acknowledgment of transaction
receipt after the commit. Upon receiving acknowledgment, the master
returns a result to the client, which then can proceed.
主库把每一个事务写到二进制日志并保存磁盘上,且发送给从库,并把事务写到存储引擎里。主库在等待从库写到自己的relay-log里确认信息。在接到确认信息后,主库把相应结果反馈给客户端,客户端将在那时进行处理。
The replication characteristics of these settings differ as follows:
这两个参数不同之处在于:
With AFTER_SYNC, all clients see the committed transaction at the same
time: After it has been acknowledged by the slave and committed to the
storage engine on the master.。Thus, all clients see the same data on the
master.
在设置为AFTER_SYNC参数,所有的客户端可以同时看到提交的数据:在得到从库写到自己的relay-log里的确认信息后,并把事务写到存储引擎里。这样,所有的客户端都可以在主库上看到同样的数据。
In the event of master failure, all transactions committed on the master
have been replicated to the slave (saved to its relay log). A crash of
the master and failover to the slave is lossless because the slave is up
to date.
主库报错,所有已经写到从库的事务都已经保存到了relay log里。主库的崩溃,HA切换到从库,不会带来任何损失,因为从库的relay-log的数据是最新的。
With AFTER_COMMIT, the client issuing the transaction gets a return
status only after the server commits to the storage engine and receives
slave acknowledgment. After the commit and before slave acknowledgment,
other clients can see the committed transaction before the committing
client.
在设置为AFTER_COMMIT 参数,发起事务的客户端仅在服务器向存储引擎写入数据并接受从库得到确认之后才返回状态。在写入数据后和得到从库确认之前,其他的客户端可以看到在这一事务。
If something goes wrong such that the slave does not process the
transaction, then in the event of a master crash and failover to the
slave, it is possible that such clients will see a loss of data relative
to what they saw on the master.
如果出现了某种错误,比如说从库的sql_thread线程没有执行,那么主库崩溃和故障转移给从服务器的前提下,有可能这个客户端会丢失那些他们曾经在主库上看到的信息。
转自
http://blog.itpub.net/15498/viewspace-2140966/
MySQL 5.7半同步复制after sync和after commit详解【转】的更多相关文章
- mysql主从之半同步复制和lossless无损复制
一 MySQL 的三种复制方式 1.1 简介 asynchronous 异步复制 fully synchronous 全同步复制 Semisynchronous 半同步复制 从MySQL5.5 开始, ...
- mysql配置为半同步复制
mysql 半同步插件是由谷歌提供,具体位置/usr/local/mysql/lib/plugin/下,一个是 master用的 semisync_master.so,一个是 slave 用的 sem ...
- mysql基础之mysql主从架构半同步复制
一.概念 1.异步复制(Asynchronous replication) MySQL默认的复制即是异步的,主库在执行完客户端提交的事务后会立即将结果返给给客户端,并不关心从库是否已经接收并处理,这样 ...
- Mysql主从复制、半同步复制、并行复制
MySQL之间数据复制的基础是二进制日志文件(binary log file).一台MySQL数据库一旦启用二进制日志后,其作为master,它的数据库中所有操作都会以"事件"的方 ...
- MySQL主从复制、半同步复制和主主复制
同步,异步,半同步复制的比较: 同步复制:Master提交事务,直到事务在所有的Slave都已提交,此时才会返回客户端,事务执行完毕.缺点:完成一个事务可能会有很大的延迟. 异步复制:当Slave准备 ...
- mysql配置完半同步复制之后报错[ERROR] The server quit without updating PID file
修改配置,MySQL启动报:[ERROR] The server quit without updating PID file [root@localhost mysql]# /etc/init.d/ ...
- MySQL主从复制、半同步复制和主主复制概述
http://www.cnblogs.com/zping/p/5275531.html
- Mysql半同步复制模式说明及配置示例 - 运维小结
MySQL主从复制包括异步模式.半同步模式.GTID模式以及多源复制模式,默认是异步模式 (如之前详细介绍的mysql主从复制).所谓异步模式指的是MySQL 主服务器上I/O thread 线程将二 ...
- mysql半同步复制跟无损半同步区别
mysql半同步复制跟无损半同步复制的区别: 无损复制其实就是对semi sync增加了rpl_semi_sync_master_wait_point参数,来控制半同步模式下主库在返回给会话事务成功之 ...
随机推荐
- java中new两个对象,在堆中开辟几个对象空间
内存堆中有两个对象,两个对象里都有独立的变量.p1 p2指向的不是同一个内存空间. 也可以这样描述引用p1,p2指向两个不同的对象.
- Getting logback and slf4j to work in JBoss AS 7
As usual, it has to do with classloading and that JBoss internally also uses slf4j and logback. As e ...
- Linux使用技巧(一):vim中选中多行、复制和粘贴
一.选中多行: 使用命令vim打开文件,移动光标至所选行的开头,按v进入视图,键盘上按向下键,选中所需行即可. 二.复制与粘贴 三种方法: 1)在上文第一部分的基础上,按y,然后移动光标至所需粘贴处, ...
- Android O新特性和行为变更总结zz
https://mp.weixin.qq.com/s/Ezfm-Xaz3fzsaSm0TU5LMw Android O 行为变更https://developer.android.google.cn/ ...
- bzoj2758【scoi2012】Blinker的的噩梦
题目描述 一天Blinker醒来,发现自己成为了一个二维世界的点,而且被标记上了一个奇怪的值. 这个世界是由N个边界互不相交(且不相切)的图形组成,这里图形仅包括圆和凸多边形.每个图形还有一个权值.每 ...
- bzoj2441【中山市选】小W的问题
题目描述 有一天,小W找了一个笛卡尔坐标系,并在上面选取了N个整点.他发现通过这些整点能够画出很多个“W”出来.具体来说,对于五个不同的点(x1, y1), (x2, y2), (x3, y3), ( ...
- 卡特兰数Catalan——定义、公式、模型总结
推荐:卡特兰数总结 定义: f(i)表示,从(0,0)出发,到(i,i),每次只能向上或者向右走,并且不越过红线的方案数. 这个图片的点上的数字,其实告诉我们f[i],就可以根据这个n方dp得到. 其 ...
- Lnmp上安装Yaf学习(二)
上一节主要实践了在Lnmp上安装Yaf扩展,那么这一节将测试 Yaf 的一个简单demo的运行. 一.通过Lnmp 创建 vhost 文件 [root@localhost yaf-3.0.6]# ln ...
- R安装时出现辑程包不存在,解决方法
R > -------------------------------------------------[解决方案]1.使用命令单独安装caret,安装的时间很长.install.packag ...
- 【Asp.net入门3-01】使用jQuery-创建示例项目
过去,浏览器除了显示HTML外,很少具有其他功能.因此,早期的Web应用程序需要依赖服务 器端代码来响应用户交互并执行数据操作.Web应用程序的交互依赖HTML表单元素和浏览器向服务 器发送数据的功能 ...