1 主备切换的判断标准
TDSQL 集群中在主库异常的情况下,会自动触发主备库的切换,实际上这里是有一个心跳在后台一直运行的。
agent进程每隔1s会向DB插入一条心跳数据来探测DB是否正常存活,比如:
replace into SysDB.StatusTableForHb set tid=’7f3ac4ff9700’,ts =from_unixtime(1544778177),ip=’100.71.78.29’,port=4022
当心跳插入执行时间超过10s会返回超时错误,也算作插入失败。
这里要注意心跳插入不受主备强同步的影响。
当agent持续20s向DB插入心跳失败会触发主备切换,这里这里的切换不一定成功。
[dave@www.cndba.cn ~]# mysql -htdsql1 -udave -pdave -P15001
Welcome to the MariaDB monitor. Commands end with ; or /g.
Your MySQL connection id is 2339
Server version: 5.7.33-V2.0R681D005-v17-20210125-2105-log Source di stribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others .
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
MySQL [(none)]> show databases;
+---------------------+
| Database |
+---------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| sysdb |
| tdsqlpcloud |
| tdsqlpcloud_monitor |
+---------------------+
7 rows in set (0.00 sec)
MySQL [(none)]> use sysdb
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [sysdb]> show tables;
+------------------------+
| Tables_in_sysdb |
+------------------------+
| statustable |
| statustableforhb |
| usercheck_meta_history |
+------------------------+
3 rows in set (0.00 sec)
MySQL [sysdb]> select * from statustableforhb;
+--------------+-------------+------+---------------------+
| tid | ip | port | ts |
+--------------+-------------+------+---------------------+
| 7f1d4dffb700 | 10.206.0.7 | 4001 | 2021-08-19 14:11:41 |
| 7f1d4effd700 | 10.206.0.7 | 4001 | 2021-08-19 14:11:42 |
| 7f1d4ffff700 | 10.206.0.7 | 4001 | 2021-08-19 14:11:40 |
| 7fa26a7fc700 | 10.206.0.13 | 4001 | 2021-08-19 13:11:42 |
| 7fa26b7fe700 | 10.206.0.13 | 4001 | 2021-08-19 13:11:40 |
| 7fa27d7fa700 | 10.206.0.13 | 4001 | 2021-08-19 13:11:41 |
| 7fe67cff9700 | 10.206.0.7 | 4001 | 2021-08-20 19:38:06 |
| 7fe67dffb700 | 10.206.0.7 | 4001 | 2021-08-20 19:38:04 |
| 7fe67e7fc700 | 10.206.0.7 | 4001 | 2021-08-20 19:38:05 |
+--------------+-------------+------+---------------------+
9 rows in set (0.00 sec)
MySQL [sysdb]>
2 触发主备切换的常见因素
上面提到的心跳只是判断标准,导致心跳异常的,主要有如下几个因素:
- DB意外重启
- 内核BUG引起系统hang住等
- 磁盘故障,文件系统故障等
- 资源竞争引起agent心跳写入超时, 这里的竞争包括:
- IO 100%
- Innodb并发线程池耗尽
- Binlog写入竞争
版权声明:本文为博主原创文章,未经博主允许不得转载。