Bullet:MySQL增强半同步参数rpl_semi_sync_master_wait_point值AFTER_SYNC和AFTER_COMMIT的对比实验
MySQL 5.7.22
启用增强半同步复制
MySQL对该参数值的描述
Semisync can wait for slave ACKs at one of two points,
AFTER_SYNC or AFTER_COMMIT. AFTER_SYNC is the default value.
AFTER_SYNC means that semisynchronous replication waits just after the
binary log file is flushed, but before the engine commits, and so
guarantees that no other sessions can see the data before replicated to
slave. AFTER_COMMIT means that semisynchronous replication waits just
after the engine commits. Other sessions may see the data before it is
replicated, even though the current session is still waiting for the commit
to end successfully.
From: Source Code mysql-5.7.22\plugin\semisync\semisync_master_plugin.cc
Replication: Semisynchronous replication master servers now use a different wait point by default in communicating wih slaves. This is the point at which the master waits for acknowledgment of transaction receipt by a slave before returning a status to the client that committed the transaction. The wait point is controlled by the new rpl_semi_sync_master_wait_point system variable. These values are permitted:
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.
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.
For older versions of MySQL, semisynchronous master behavior is equivalent to a setting of AFTER_COMMIT.
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.
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.
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.
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.
The new wait point is a behavior change, but requires no reconfiguration. The change does introduce a version compatibility constraint because it increments the semisynchronous interface version: Servers for MySQL 5.7.2 and up do not work with semisynchronous replication plugins from older versions, nor do servers from older versions work with semisynchronous replication plugins for MySQL 5.7.2 and up.
From:https://dev.mysql.com/doc/relnotes/mysql/5.7/en/news-5-7-2.html
测试表
Create Table: CREATE TABLE `syk`.`t` (
`t` datetime DEFAULT NULL,
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
insert into syk.t (t,a) values(now(),1);
commit;
准备3个会话窗口,A,B,C
A窗口连接主库,负责更改主库的参数及表更新操作
B窗口负责监视主库数据的变化,执行下述命令
while (true);do
mysql -uroot -pmysql- -e "select now(),t,a from syk.t" -s --skip-column-names >& | grep -v Warning
sleep
done
C窗口负责从库,slave的重启操作,模拟从库的slave停止
AFTER_SYNC
5.7.2及以上默认值
A:
mysql> show variables like '%rpl%point%';
+---------------------------------+------------+
| Variable_name | Value |
+---------------------------------+------------+
| rpl_semi_sync_master_wait_point | AFTER_SYNC |
+---------------------------------+------------+ mysql> show global status like '%rpl%master%status%';
+-----------------------------+-------+
| Variable_name | Value |
+-----------------------------+-------+
| Rpl_semi_sync_master_status | ON |
+-----------------------------+-------+ mysql> select * from syk.t;
+---------------------+------+
| t | a |
+---------------------+------+
| 2018-08-02 14:57:15 | 1 |
+---------------------+------+
B:
此时B窗口一直在查询表数据
C:
停止slave
A:
mysql> update syk.t set t=now() where a=1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0 mysql> commit;
Query OK, 0 rows affected (10.00 sec) mysql> select * from syk.t;
+---------------------+------+
| t | a |
+---------------------+------+
| 2018-08-02 15:21:51 | 1 |
+---------------------+------+
1 row in set (0.00 sec)
A窗口的commit延迟了10秒才提交成功。受rpl_semi_sync_master_timeout参数影响,默认100000毫秒,即10秒。
B:
2018-08-02 15:21:50 2018-08-02 14:57:15 1
2018-08-02 15:21:51 2018-08-02 14:57:15 1 <=========
2018-08-02 15:21:52 2018-08-02 14:57:15 1
2018-08-02 15:21:53 2018-08-02 14:57:15 1
2018-08-02 15:21:54 2018-08-02 14:57:15 1
2018-08-02 15:21:55 2018-08-02 14:57:15 1
2018-08-02 15:21:56 2018-08-02 14:57:15 1
2018-08-02 15:21:57 2018-08-02 14:57:15 1
2018-08-02 15:21:58 2018-08-02 14:57:15 1
2018-08-02 15:21:59 2018-08-02 14:57:15 1
2018-08-02 15:22:00 2018-08-02 14:57:15 1
2018-08-02 15:22:01 2018-08-02 14:57:15 1
2018-08-02 15:22:02 2018-08-02 14:57:15 1
2018-08-02 15:22:03 2018-08-02 14:57:15 1
2018-08-02 15:22:04 2018-08-02 14:57:15 1
2018-08-02 15:22:05 2018-08-02 15:21:51 1 <=========
可以看到,主库的其他会话需要等待提交显示OK之后,才能看得到。
AFTER_COMMIT
5.7.2之前(不含5.7.2)的版本,的版本默认行为
A:
set global rpl_semi_sync_master_wait_point=AFTER_COMMIT;
C:
重启slave
A:
mysql> show variables like '%rpl%point%';
+---------------------------------+--------------+
| Variable_name | Value |
+---------------------------------+--------------+
| rpl_semi_sync_master_wait_point | AFTER_COMMIT |
+---------------------------------+--------------+
1 row in set (0.00 sec) mysql> show global status like '%rpl%master%status%';
+-----------------------------+-------+
| Variable_name | Value |
+-----------------------------+-------+
| Rpl_semi_sync_master_status | ON |
+-----------------------------+-------+
1 row in set (0.00 sec) mysql> select * from syk.t;
+---------------------+------+
| t | a |
+---------------------+------+
| 2018-08-02 15:21:51 | 1 |
+---------------------+------+
1 row in set (0.00 sec)
B:
此时B窗口一直在查询表数据
C:
停止slave
A:
mysql> update syk.t set t=now() where a=1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0 mysql> commit;
Query OK, 0 rows affected (10.01 sec) mysql> select * from syk.t;
+---------------------+------+
| t | a |
+---------------------+------+
| 2018-08-02 15:38:42 | 1 |
+---------------------+------+
1 row in set (0.00 sec)
A窗口的commit同样延迟了10秒才提交成功。受rpl_semi_sync_master_timeout参数影响,默认100000毫秒,即10秒。
B:
2018-08-02 15:38:41 2018-08-02 15:21:51 1
2018-08-02 15:38:42 2018-08-02 15:21:51 1
2018-08-02 15:38:43 2018-08-02 15:38:42 1 <=========
2018-08-02 15:38:44 2018-08-02 15:38:42 1
2018-08-02 15:38:45 2018-08-02 15:38:42 1
2018-08-02 15:38:46 2018-08-02 15:38:42 1
2018-08-02 15:38:47 2018-08-02 15:38:42 1
2018-08-02 15:38:48 2018-08-02 15:38:42 1
2018-08-02 15:38:49 2018-08-02 15:38:42 1
2018-08-02 15:38:50 2018-08-02 15:38:42 1
2018-08-02 15:38:51 2018-08-02 15:38:42 1
2018-08-02 15:38:52 2018-08-02 15:38:42 1
2018-08-02 15:38:53 2018-08-02 15:38:42 1
2018-08-02 15:38:54 2018-08-02 15:38:42 1
2018-08-02 15:38:55 2018-08-02 15:38:42 1
2018-08-02 15:38:56 2018-08-02 15:38:42 1
虽然A的提交延迟了10秒,但其他会话已经看到已经提交的数据。
总结:
实验的对比,可以发现与源码中的描述是一致的。
AFTER_SYNC意味着半同步复制,在binary log被flush之后,在存储引擎commit前进入等待,这可以保证数据在被复制到从库前不被其他会话可见;
AFTER_COMMIT意味着半同步复制在存储引擎commit之后进入等待,尽管发起commit的会话还未收到commit成功的提示,其他的会话已经可以看到commit后的数据。
rpl_semi_sync_master_wait_point,该参数也正如其字面意思,master在哪个点开始等待。
Bullet:MySQL增强半同步参数rpl_semi_sync_master_wait_point值AFTER_SYNC和AFTER_COMMIT的对比实验的更多相关文章
- MySQL增强半同步的搭建实验,和一些参数的个人理解
关于参数理解,已补充实验,可以查看: rpl_semi_sync_master_wait_no_slave 参数研究实验 环境信息 role ip port hostname master 192.1 ...
- MySQL增强半同步几个重要参数搭配的测试
Preface Semi-synchronous replication is supported since MySQL 5.5 and then enhanced graduall ...
- MySQL 5.7 新特性之增强半同步复制
1. 背景介绍 半同步复制 普通的replication,即mysql的异步复制,依靠mysql二进制日志也即binary log进行数据复制.比如两台机器,一台主机(master),另外一台是从机( ...
- MySQL 5.7的复制架构,在有异步复制、半同步、增强半同步、MGR等的生产中,该如何选择?
一.生产环境中: 几种复制场景都有存在的价值.下面分别描述一下: 从成熟度上来选择,推荐:异步复制(GTID+ROW) 从数据安全及更高性能上选择:增强半同步 (在这个结构下也可以把innodb_fl ...
- PostgreSQL的同步级别与MySQL的半同步after_sync比较
MySQL的半同步中通过binlog进行流复制,同步级别和PostgreSQL对比可以发现: PostgreSQL MySQL off local ...
- MySQL的半同步是什么?
前言 年后在进行腾讯二面的时候,写完算法的后问的第一个问题就是,MySQL的半同步是什么?我当时直接懵了,我以为是问的MySQL的两阶段提交的问题呢?结果确认了一下后不是两阶段提交,然后面试官看我连问 ...
- (MHA+MYSQL-5.7增强半同步)高可用架构设计与实现
架构使用mysql5.7版本基于GTD增强半同步并行复制配置 reploication 一主两从,使用MHA套件管理整个复制架构,实现故障自动切换高可用 优势: ...
- mysql的半同步复制
1. binlog dump线程何时向从库发送binlog mysql在server层进行了组提交之后,为了提高并行度,将提交阶段分为了 flush sync commit三个阶段,根据sync_bi ...
- MySQL主从复制半同步复制原理及搭建
在MySQL5.5之前的版本中,MySQL的复制是异步复制,主库和从库的数据之间存在一定的延迟,比如网络故障等各种原因,这样子容易存在隐患就是:当在主库写入一个事务成功后并提交了,但是由于从库延迟没有 ...
随机推荐
- UI:沙盒
IOS平台下,沙盒的本质就是一个文件夹 每一款IOS应用安装在手机上都会自动的生成一个文件夹.之所以叫沙盒,就是因为这个文件夹是每次运行随机产生的文件夹.沙盒文件夹是独立的,每个应用之间不能互相访问. ...
- 本地通信实例(AF_UNIX) (转载)
转自:http://www.groad.net/bbs/thread-1709-1-1.html 程序说明: 程序里包含服务端和客户端两个程序,它们之间使用 AF_UNIX 实现本机数据流通信.使用 ...
- linux中的C里面使用pthread_mutex_t锁(转载)
转自:http://blog.csdn.net/w397090770/article/details/7264315 linux下为了多线程同步,通常用到锁的概念. posix下抽象了一个锁类型的结构 ...
- bzoj 4481: [Jsoi2015]非诚勿扰【期望+树状数组】
首先很容易计算对于一个如意郎君列表里有x个男性的女性,编号排第i位的男性被选的概率是 \[ p*(1-p)^{i-1}+p*(1-p)^{i-1+n}+p*(1-p)^{i-1+n}+- \] \[ ...
- bzoj 1610: [Usaco2008 Feb]Line连线游戏【瞎搞】
阴沟翻船.jpg 居然忘了除0的情况 枚举两两之间的线,把斜率装起来排个序去个重就好了 真是水的一晚上呢 #include<iostream> #include<cstdio> ...
- CentOS中设置Windows共享文件夹
在CentOS中设置Samba可实现和Windows共享文件夹.常见的需求:1)用户能够在Windows机器上通过共享文件夹访问远程Linux服务器上自己的主目录:2)用户能够在Windows机器上访 ...
- 移动游戏By HYJ
暴力求SG函数即可,记忆化贼方便 /*program from Wolfycz*/ #include<cmath> #include<cstdio> #include<c ...
- bnu oj 13288 Bi-shoe and Phi-shoe
题目链接: http://www.bnuoj.com/contest/problem_show.php?pid=13288 题目大意: 给出一个n,然后给出n个幸运数([1,m]中不能被m整除的数的数 ...
- 洛谷 P1430 序列取数
如果按照http://www.cnblogs.com/hehe54321/p/loj-1031.html的$O(n^3)$做法去做的话是会T掉的,但是实际上那个做法有优化的空间. 所有操作可以分解为由 ...
- rabbitmq实践笔记(一):安装、配置与使用初探
引言: 对于一个大型的软件系统来说,会有很多的组件.模块及不同的子系统一起协同工作,模块之间的通信需要一个可靠的通信管道来保证 ,通信管道需要解决解决很多问题,比如: 1)信息的发送者和接收者如何维持 ...