博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Percona XtraDB Cluster 5.7 event是否重复执行?
阅读量:6139 次
发布时间:2019-06-21

本文共 5722 字,大约阅读时间需要 19 分钟。

最近的某个业务系统即将由单点转入PXC集群,碰到的问题是mysql单实例上运行的那些event,再转入集群之后,该如何执行呢?带着这个问题,做了个实验,并给出相关结论。如果看官有类似的疑惑不妨往下读。

一、环境描述

# more /etc/redhat-release CentOS Linux release 7.4.1708 (Core) mysql> show variables like 'version';  +---------------+------------------+| Variable_name | Value            |+---------------+------------------+| version      | 5.7.20-18-57-log |+---------------+------------------+mysql> show status like '%wsrep_cluster_size%';+--------------------+-------+| Variable_name      | Value |+--------------------+-------+| wsrep_cluster_size | 3    |+--------------------+-------+

二、PXC环境测试event

测试说明

  该测试在一个节点上创建event,然后观察其他节点上event是否被执行。那如何判断event是在哪个节点上执行的呢?在这里写一个存储过程来调度使用当前实例的ip地址进行往表写入操作。因此如果任意一节点写入,必定包含自身ip。因此,我们调用了美每个实例上的wsrep_node_address这个变量。

1、在其中的一个节点创建event
mysql> show variables like '%wsrep_node_address%';+--------------------+---------------+| Variable_name      | Value        |+--------------------+---------------+| wsrep_node_address | 192.168.1.248 |+--------------------+---------------+--当前节点为1.248,变量event_scheduler处于开启mysql> show variables like '%event_scheduler%';+-----------------+-------+| Variable_name  | Value |+-----------------+-------+| event_scheduler | ON    |+-----------------+-------+--建一个测试库mysql> create database tempdb;--创建过程mysql> delimiter //mysql> CREATE PROCEDURE `inst_rows` ()BEGIN  DECLARE v1  INT DEFAULT 500;  WHILE v1 > 0  DO      SET @ipaddr =            (SELECT VARIABLE_VALUE              FROM `performance_schema`.session_variables              WHERE variable_name = 'wsrep_node_address');      INSERT INTO tempdb.tb_test(ip_addr, ins_time)      VALUES (@ipaddr, now());      SET v1 = v1 - 1;      SELECT sleep(1);  END WHILE;END//mysql> delimiter ;--创建测试表mysql> CREATE TABLE tb_test (  id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,  ip_addr varchar(30) DEFAULT NULL,  ins_time timestamp );mysql> select now();+---------------------+| now()              |+---------------------+| 2018-04-27 17:46:27 |+---------------------+--添加eventmysql> CREATE EVENT test_eventON SCHEDULE AT '2018-04-27 18:05:00' ON COMPLETION PRESERVEDO CALL inst_rows ;mysql> select name,status from mysql.`event` where db='tempdb';+------------+---------+| name      | status  |+------------+---------+| test_event | ENABLED |+------------+---------+#####2、其他节点观察eventmysql> show variables like '%wsrep_node_address%';+--------------------+---------------+| Variable_name      | Value        |+--------------------+---------------+| wsrep_node_address | 192.168.1.249 |+--------------------+---------------+mysql> show variables like '%event_scheduler%';+-----------------+-------+| Variable_name  | Value |+-----------------+-------+| event_scheduler | ON    |+-----------------+-------+--在节点1.248上,event状态为SLAVESIDE_DISABLED,即不会被执行mysql> select name,status from mysql.`event` where db='tempdb';+------------+--------------------+| name      | status            |+------------+--------------------+| test_event | SLAVESIDE_DISABLED |+------------+--------------------+mysql> select "Leshami" Author, "https://blog.csdn.net/leshami",645746311 "WeiXin/QQ";+---------+-------------------------------+-----------+| Author  | https://blog.csdn.net/leshami | WeiXin/QQ |+---------+-------------------------------+-----------+| Leshami | https://blog.csdn.net/leshami | 645746311 |+---------+-------------------------------+-----------+mysql> select now();+---------------------+| now()              |+---------------------+| 2018-04-27 18:07:25 |+---------------------+1 row in set (0.00 sec)mysql> select * from tb_test where ip_addr='192.168.1.249';Empty set (0.00 sec)mysql> select count(*) from tb_test where ip_addr='192.168.1.248';+----------+| count(*) |+----------+|      500 |+----------+

三、主从架构测试event

在mysql当中,系统变量event_scheduler,来自官方的说明,缺省值为OFF。

  This variable indicates the status of the Event Scheduler; possible values are ON, OFF, and DISABLED, with the default being OFF.

如下主从架构mysql> show slave status \G*************************** 1. row ***************************              Slave_IO_State: Waiting for master to send event                  Master_Host: 192.168.1.248                  Master_User: repl                  Master_Port: 3306                Connect_Retry: 60              Master_Log_File: mysqlbin.000011          Read_Master_Log_Pos: 382972              Relay_Log_File: zcd05-relay-bin.000010                Relay_Log_Pos: 383183        Relay_Master_Log_File: mysqlbin.000011            Slave_IO_Running: Yes            Slave_SQL_Running: Yesmysql> show variables like '%report_host%';+---------------+---------------+| Variable_name | Value        |+---------------+---------------+| report_host  | 192.168.1.244 |+---------------+---------------+1 row in set (0.01 sec)mysql> show variables like 'event_scheduler';+-----------------+-------+| Variable_name  | Value |+-----------------+-------+| event_scheduler | OFF  |+-----------------+-------+1 row in set (0.01 sec)--从库节点上的event状态也为SLAVESIDE_DISABLEDmysql> select name,status from mysql.`event` where db='tempdb';+------------+--------------------+| name      | status            |+------------+--------------------+| test_event | SLAVESIDE_DISABLED |+------------+--------------------+1 row in set (0.00 sec)

四、结论

1、The status of the event is set to SLAVESIDE_DISABLED on the slave regardless of the state specified (this does not apply to DROP EVENT).

2、SLAVESIDE_DISABLED indicates that the creation of the event occurred on another MySQL server acting as a replication master and replicated to the current MySQL server which is acting as a slave,but the event is not presently being executed on the slave.
3、在PXC集群中,在任意一个节点上创建的event,在其余节点上event状态将处于SLAVESIDE_DISABLED。也就是在哪个节点上创建将被所在节点调度。

你可能感兴趣的文章
解读自定义UICollectionViewLayout--感动了我自己
查看>>
SqlServer作业指定目标服务器
查看>>
UnrealEngine4.5 BluePrint初始化中遇到编译警告的解决办法
查看>>
User implements HttpSessionBindingListener
查看>>
抽象工厂方法
查看>>
ubuntu apt-get 安装 lnmp
查看>>
焊盘 往同一个方向增加 固定的长度方法 总结
查看>>
eclipse的maven、Scala环境搭建
查看>>
架构师之路(一)- 什么是软件架构
查看>>
jquery的冒泡和默认行为
查看>>
USACO 土地购买
查看>>
【原创】远景能源面试--一面
查看>>
B1010.一元多项式求导(25)
查看>>
10、程序员和编译器之间的关系
查看>>
前端学习之正则表达式
查看>>
配置 RAILS FOR JRUBY1.7.4
查看>>
AndroidStudio中导入SlidingMenu报错解决方案
查看>>
修改GRUB2背景图片
查看>>
Ajax异步
查看>>
好记性不如烂笔杆-android学习笔记<十六> switcher和gallery
查看>>