インデックス再構築ってレプリケーションされる?
結論としては
されます!
いやぁ、正直不安だったんですよね。
定義が変わるわけじゃないし、データが飛ぶわけじゃない。
でも、奥野さんのこの記事にもある通り、ALTER TABLEではテーブルコピーしてるわけだからレプリケーションされるんじゃないかなあ?
でもでも、もしかするとMySQLだからそんなのは無視するかも…。
色々考えて、まあやってみるのが早いだろうと。
やったこと
- レプリケーション環境を構築し、
- マスターでALTER TABLE xxx ENGINE INNODB;実行
- マスターの
show master status
のPosition
とスレーブのshow slave status
のRead_Master_Log_Pos
が同じ数字に更新されていることを確認。
1. レプリケーション環境を構築
dockerで構築しました。
2. マスターでALTER TABLE xxx ENGINE INNODB;実行
mysql> show master status; +----------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +----------------+----------+--------------+------------------+-------------------+ | bin-log.000005 | 624 | | | | +----------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE `aaa` ( -> `id` int(11) NOT NULL, -> `a` varchar(10) DEFAULT NULL, -> `b` char(10) DEFAULT NULL, -> `c` text DEFAULT NULL -> ) ENGINE=InnoDB; Query OK, 0 rows affected (0.30 sec) mysql> show master status; +----------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +----------------+----------+--------------+------------------+-------------------+ | bin-log.000005 | 913 | | | | +----------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> alter table aaa engine innodb; Query OK, 0 rows affected (0.40 sec) レコード数: 0 重複数: 0 警告: 0 mysql> show master status; +----------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +----------------+----------+--------------+------------------+-------------------+ | bin-log.000005 | 1081 | | | | +----------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)
- マスターの
show master status
のPosition
とスレーブのshow slave status
のRead_Master_Log_Pos
が同じ数字に更新されていることを確認。
mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 172.26.0.2 Master_User: repl Master_Port: 3306 Connect_Retry: 10 Master_Log_File: bin-log.000005 Read_Master_Log_Pos: 624 Relay_Log_File: 119e0e1d724f-relay-bin-master1.000002 Relay_Log_Pos: 318 Relay_Master_Log_File: bin-log.000005 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 624 Relay_Log_Space: 540 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 Master_UUID: e89799bb-512f-11e9-b0d6-0242ac1a0003 Master_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: master1 --- テーブル作成後 mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 172.26.0.2 Master_User: repl Master_Port: 3306 Connect_Retry: 10 Master_Log_File: bin-log.000005 Read_Master_Log_Pos: 913 Relay_Log_File: 119e0e1d724f-relay-bin-master1.000002 Relay_Log_Pos: 607 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 913 Relay_Log_Space: 829 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 Master_UUID: e89799bb-512f-11e9-b0d6-0242ac1a0003 Master_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: master1 Master_TLS_Version: --- ALTER TABLE xxx ENGINE INNODB;実行後 mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 172.26.0.2 Master_User: repl Master_Port: 3306 Connect_Retry: 10 Master_Log_File: bin-log.000005 Read_Master_Log_Pos: 1081 Relay_Log_File: 119e0e1d724f-relay-bin-master1.000002 Relay_Log_Pos: 775 Relay_Master_Log_File: bin-log.000005 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 Master_UUID: e89799bb-512f-11e9-b0d6-0242ac1a0003 Master_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite_DB: Channel_Name: master1 Master_TLS_Version:
普通にCREATE TABLE して数値が変わったように、ALTER TABLE xxx ENGINE INNODBでも数値が変わっているのが確認できました。
binlogも確認したけど普通に alter table aaa engine innodb;
書かれてたし。
この数値が変わらなかったら(スレーブまたはマスターとスレーブ両方で動いてなかったら)全インスタンスにALTER TABLE xxx ENGINE INNODB実行する予定でしたが、どうやら大丈夫そう。
もし「いや、違うぜ!」ってご意見あれば、教えてください m( )m