Percona XtraDB Cluster 5.7 event是否重复执行?

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介:

最近的某个业务系统即将由单点转入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 |
+---------------------+

--添加event
mysql> CREATE EVENT test_event
ON SCHEDULE AT '2018-04-27 18:05:00' 
ON COMPLETION PRESERVE
DO CALL inst_rows ;

mysql> select name,status from mysql.`event` where db='tempdb';
+------------+---------+
| name      | status  |
+------------+---------+
| test_event | ENABLED |
+------------+---------+

#####2、其他节点观察event
mysql> 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: Yes

mysql> 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_DISABLED
mysql> 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。也就是在哪个节点上创建将被所在节点调度。

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
SQL 监控 关系型数据库
Mysql主从同步报错解决:Error executing row event: Table zabbix.history-..
Mysql主从同步报错解决:Error executing row event: Table zabbix.history-..
306 0
|
缓存 前端开发 关系型数据库
DB galera cluster 全部停止后再次启动
环境:centos6.8 mysql5.7.25
85 0
|
SQL NoSQL 安全
Percona 8.0.30中"show engine innodb status"导致coredump排查及分析
Percona 8.0.30中"show engine innodb status"导致coredump排查及分析
|
存储 SQL 设计模式
【MySQL技术内幕】7.2.3-purge和group commit
【MySQL技术内幕】7.2.3-purge和group commit
125 0
|
SQL Oracle 关系型数据库
xDB Replication Server - PostgreSQL, Oracle, SQL Server, PPAS 全量、增量(redo log based, or trigger based)同步(支持single-master, mult-master同步, 支持DDL)
xDB Replication Server - PostgreSQL, Oracle, SQL Server, PPAS 全量、增量(redo log based, or trigger based)同步(支持single-master, mult-master同步, 支持DDL)
933 0
|
监控 关系型数据库 MySQL