版本信息:
MariaDB [information_schema]> select * from GLOBAL_status where variable_name in ('wsrep_provider_name','wsrep_provider_version') union all select * from GLOBAL_VARIABLES where variable_name in ('version','innodb_version') order by 1;
+------------------------+-----------------------+
| VARIABLE_NAME | VARIABLE_VALUE |
+------------------------+-----------------------+
| INNODB_VERSION | 5.6.39-83.1 |
| VERSION | 10.0.35-MariaDB-wsrep |
| WSREP_PROVIDER_NAME | Galera |
| WSREP_PROVIDER_VERSION | 25.3.23(r3789) |
+------------------------+-----------------------+
Mariadb Galera Cluster中DDL是件非常危险的事情,总结如下:
- DDL 会导致与DDL相关表的事务产生死锁ERROR 1213 (40001)。
- DDL 未结束前,所有与DDL表相关的事务不能提交。
- DDL 一旦开始,便不能人工退出(除非kill掉mysql实例).
推荐在Mariadb Galera Cluster做DDL的工具就是大名鼎鼎的pt-online-schema-change。它虽然不能解决Mariadb Galera Cluster中DDL死锁的问题。
但可以解决以下两个问题:
1.DDL不会阻塞后续事务的提交。
2.可以随时终止pt-online-schema-change的运行。
因此推荐用pt-online-schema-change在Mariadb Galera Cluster中做DDL.以降低对业务的影响和原生DDL不能人工终止的风险。
示例如下:
pt-online-schema-change --alter="modify c3 varchar(20) " --no-check-replication-filters --recursion-method=none --user=mgc --host=192.168.0.100 --port=3336 --password=123 D=test,t=mgc --execute
No slaves found. See --recursion-method if host test43 has slaves.
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.
Operation, tries, wait:
copy_rows, 10, 0.25
create_triggers, 10, 1
drop_triggers, 10, 1
swap_tables, 10, 1
update_foreign_keys, 10, 1
Altering `test`.`mgc`...
Creating new table...
Created new table test._mgc_new OK.
Altering new table...
Altered `test`.`_mgc_new` OK.
2018-05-25T21:21:50 Creating triggers...
2018-05-25T21:21:50 Created triggers OK.
2018-05-25T21:21:50 Copying approximately 10301256 rows...
Copying `test`.`mgc`: 37% 00:49 remain
Copying `test`.`mgc`: 74% 00:20 remain
2018-05-25T21:23:11 Copied rows OK.
2018-05-25T21:23:11 Swapping tables...
2018-05-25T21:23:11 Swapped original and new tables OK.
2018-05-25T21:23:11 Dropping old table...
2018-05-25T21:23:12 Dropped old table `test`.`_mgc_old` OK.
2018-05-25T21:23:12 Dropping triggers...
2018-05-25T21:23:12 Dropped triggers OK.
Successfully altered `test`.`mgc`.