当前位置:Gxlcms > 数据库问题 > MySQL 5.7最新版本的2个bug

MySQL 5.7最新版本的2个bug

时间:2021-07-01 10:21:17 帮助过:8人阅读

--oltp-read-only=off --init-rng=on --num-threads=16 --max-requests=0 --oltp-dist-type=uniform --max-time=1800 --mysql-user=root --mysql-socket=/data/mysql/3306/mysqltmp/mysql.sock --mysql-password=123 --db-driver=mysql --mysql-table-engine=innodb --oltp-test-mode=complex prepare

普通复制:

mysql> show variables like %parallel%;
+------------------------+----------+
| Variable_name          | Value    |
+------------------------+----------+
| slave_parallel_type    | DATABASE |
| slave_parallel_workers | 0        |
+------------------------+----------+
2 rows in set (0.00 sec)

mysql> 

多线程复制:

mysql> show variables like %parallel%;
+------------------------+---------------+
| Variable_name          | Value         |
+------------------------+---------------+
| slave_parallel_type    | LOGICAL_CLOCK |
| slave_parallel_workers | 8             |
+------------------------+---------------+
2 rows in set (0.02 sec)

准备查看复制延时脚本:

for i in {1..1000};
do
    (
        mysql -uroot -p123 -h 192.168.0.20 -e "SHOW SLAVE STATUS\G" | grep "Seconds_Behind_Master" | awk {print "slave_1_not-multi-threaded-repl: " $2} &
        sleep 0.1 ;
        mysql -uroot -p123 -h 192.168.0.30 -e "SHOW SLAVE STATUS\G" | grep "Seconds_Behind_Master" | awk {print "slave_2_multi-threaded-repl: " $2} &
    );
    sleep 1;
done

让这个脚本跑起来,然后在主库删除数据,看复制延时的情况。然后在主库删除数据:

delete from sbtest where id>100;

运行脚本,查看复制延时情况,输出如下,可以看到开启了多线程复制的Seconds_Behind_Master一直为0,不会变化,而普通复制则显示延时了。

[root@dbserver-yayun-04 ~]# sh a.sh 
mysql: [Warning] Using a password on the command line interface can be insecure.
slave_1_not-multi-threaded-repl: 103
mysql: [Warning] Using a password on the command line interface can be insecure.
slave_2_multi-threaded-repl: 0
mysql: [Warning] Using a password on the command line interface can be insecure.
slave_1_not-multi-threaded-repl: 104
mysql: [Warning] Using a password on the command line interface can be insecure.
slave_2_multi-threaded-repl: 0
mysql: [Warning] Using a password on the command line interface can be insecure.
slave_1_not-multi-threaded-repl: 105
mysql: [Warning] Using a password on the command line interface can be insecure.
slave_2_multi-threaded-repl: 0
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
slave_1_not-multi-threaded-repl: 106
slave_2_multi-threaded-repl: 0

Percona给的解决方法是:

SELECT PROCESSLIST_TIME FROM performance_schema.threads WHERE NAME = thread/sql/slave_worker AND (PROCESSLIST_STATE IS NULL  or PROCESSLIST_STATE != Waiting for an event from Coordinator) ORDER BY PROCESSLIST_TIME DESC LIMIT 1;


下面进行super_read_only开启以后触发bug的复现:

1. 其中一个从库设置gtid_executed_compression_period=1,用来控制每执行多少个事务,对此表进行压缩,默认值为1000

2. super_read_only开启,超级用户都无法更改从库的数据。

3. 关闭log_slave_updates,如果开启,gtid_executed表不会实时变更,也不会压缩。(percona博客中开启了log_slave_updates也触发了bug,我认为是博客中有错误)

mysql> show variables like %gtid_ex%;
+----------------------------------+-------+
| Variable_name                    | Value |
+----------------------------------+-------+
| gtid_executed_compression_period | 1     |
+----------------------------------+-------+
1 row in set (0.01 sec)

mysql> show variables like %log_slave_updates%;
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| log_slave_updates | OFF   |
+-------------------+-------+
1 row in set (0.00 sec)

mysql> show variables like %super%;
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| super_read_only | ON    |
+-----------------+-------+
1 row in set (0.00 sec)

mysql> 

下面在主库运行sysbench进行压测,产生事务。

sysbench --test=oltp --oltp-table-size=100000 --oltp-read-only=off --init-rng=on --num-threads=16 --max-requests=0 --oltp-dist-type=uniform --max-time=1800 --mysql-user=root --mysql-socket=/data/mysql/3306/mysqltmp/mysql.sock --mysql-password=123 --db-driver=mysql --mysql-table-engine=innodb --oltp-test-mode=complex run

查看从库:

mysql> select count(*) from gtid_executed;
+----------+
| count(*) |
+----------+
|       93 |
+----------+
1 row in set (0.44 sec)

mysql> select count(*) from gtid_executed;
+----------+
| count(*) |
+----------+
|      113 |
+----------+
1 row in set (0.66 sec)

mysql> 

可以发现并没有压缩,一直在增加。
执行show engine innodb status可以看到有线程在压缩表的,但是没成功,在回滚

---TRANSACTION 10909611, ACTIVE 2 sec rollback
mysql tables in use 1, locked 1
ROLLING BACK 4 lock struct(s), heap size 1136, 316 row lock(s)
MySQL thread id 1, OS thread handle 140435435284224, query id 0 Compressing gtid_executed table

查看INNODB_TRX表,也能发现有事务在回滚。

mysql> select trx_id,trx_state,trx_operation_state,trx_isolation_level from information_schema.INNODB_TRX;
+-----------------+--------------+---------------------+---------------------+
| trx_id          | trx_state    | trx_operation_state | trx_isolation_level |
+-----------------+--------------+---------------------+---------------------+
| 10919604        | ROLLING BACK | rollback            | REPEATABLE READ     |
| 421910840085200 | RUNNING      | starting index read | REPEATABLE READ     |
+-----------------+--------------+---------------------+---------------------+
2 rows in set (0.00 sec)

看见现在表已经有很多记录了:

mysql> select count(*) from gtid_executed;
+----------+
| count(*) |
+----------+
|     2448 |
+----------+
1 row in set (0.00 sec)

mysql> 

关闭super_read_only

mysql> set global super_read_only=0;
Query OK, 0 rows affected (0.00 sec)

mysql> select count(*) from gtid_executed;
+----------+
| count(*) |
+----------+
|        2 |
+----------+
1 row in set (0.07 sec)

mysql> select count(*) from gtid_executed;
+----------+
| count(*) |
+----------+
|        2 |
+----------+
1 row in set (0.00 sec)

mysql> 

马上恢复正常了。

 

参考文章:

https://www.percona.com/blog/2017/02/08/mysql-super_read_only-bugs/
https://www.percona.com/blog/2017/01/27/wrong-seconds_behind_master-with-slave_parallel_workers-0/
http://keithlan.github.io/2017/02/15/gtid_practice/?utm_source=tuicool&utm_medium=referral

 

MySQL 5.7最新版本的2个bug

标签:int   nbsp   lin   back   关闭   update   date   init   ade   

人气教程排行