版本信息:
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`.