dshimizu/blog

アルファ版

MySQL InnoDB Clusterのクラスタ名が変わってしまったのでメタデータを直接更新して復活させた

肝心の「何故こうなったのか」の原因は判明していないけど、MICの検証をしていて、クラスタを止めたり疑似障害を起こしたりしていりしていた時の事。 MySQL Shellを使ってメタデータからクラスタをを取得しようとしたときに以下のようなエラーが出るようになってしまいました。

mysql-js> shell.connect('192.168.***.***:3306')
Please provide the password for 'icroot@192.168.***.***:3306':
Creating a Session to 'icroot@192.168.***.***::3306'
Your MySQL connection id is 45
No default schema selected; type \use  to set one.

mysql-js> var cluster = dba.getCluster('devCluster');
Dba.getCluster: Dba.getCluster: Unable to get cluster. The instance '192.168.***.***:3306' may belong to a different ReplicaSet as the one registered in the Metadata since the value of 'group_replication_group_name' does not match the one registered in the ReplicaSet's Metadata: possible split-brain scenario. Please connect to another member of the ReplicaSet to get the Cluster. (RuntimeError)

エラー内容と対応策

環境

対応

エラーメッセージの通りで replication_group_name の値が、設定ファイル内の loose-group_replication_group_name にセットしてある値とは別のものに変わってしまっているようでした。

root@mysql1[mysql_innodb_cluster_metadata] > select * from replicasets;
+---------------+------------+-----------------+---------------+-----------------+--------+--------------------------------------------------------------------------+-------------+
| replicaset_id | cluster_id | replicaset_type | topology_type | replicaset_name | active | attributes                                                               | description |
+---------------+------------+-----------------+---------------+-----------------+--------+--------------------------------------------------------------------------+-------------+
|             1 |          1 | gr              | pm            | default         |      1 | {"group_replication_group_name": "86cecd19-****-4295-8da3-************"} | NULL        |
+---------------+------------+-----------------+---------------+-----------------+--------+--------------------------------------------------------------------------+-------------+
1 row in set (0.00 sec)

/etc/mysql/mysql.conf.d/mysqld.cnf内のloose-group_replication_group_nameの値

loose-group_replication_group_name = "59ab44ec-****-48cf-ad33-************"

start group_replicationは実行できるものの、このままではMySQL Shellからクラスタの管理ができないので、手動でメタデータを更新する対応を取りました。

root@mysql1[mysql_innodb_cluster_metadata] > UPDATE mysql_innodb_cluster_metadata.replicasets SET attributes='{"group_replication_group_name": "59ab44ec-****-48cf-ad33-************"}';
Query OK, 1 row affected (0.03 sec)

root@mysql1[mysql_innodb_cluster_metadata] > select * from replicasets;
+---------------+------------+-----------------+---------------+-----------------+--------+--------------------------------------------------------------------------+-------------+
| replicaset_id | cluster_id | replicaset_type | topology_type | replicaset_name | active | attributes                                                               | description |
+---------------+------------+-----------------+---------------+-----------------+--------+--------------------------------------------------------------------------+-------------+
|             1 |          1 | gr              | pm            | default         |      1 | {"group_replication_group_name": "59ab44ec-****-48cf-ad33-************"} | NULL        |
+---------------+------------+-----------------+---------------+-----------------+--------+--------------------------------------------------------------------------+-------------+

再度MySQL Shellを使ってクラスタ情報を取得します。

mysql-js> var cluster = dba.getCluster('devCluster');

取得できました。 クラスタのステータスを確認してみます。

mysql-js> cluster.status();
{
    "clusterName": "ClusterDev",
    "defaultReplicaSet": {
        "name": "default",
        "primary": "192.168.***.***:3306",
        "status": "OK",
        "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
        "topology": {
            "192.168.***.***:3306": {
                "address": "192.168.***.***:3306",
                "mode": "R/O",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            },
            "192.168.***.***:3306": {
                "address": "192.168.***.***:3306",
                "mode": "R/O",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            },
            "192.168.34.77:3306": {
                "address": "192.168.***.***:3306",
                "mode": "R/W",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            }
        }
    }
}

表示されました。 ざっと見たところ正常に動作しているようです。

まとめ

何故かMySQL InnoDB Clusterのメタデータに保存されているクラスタ名が、設定ファイルの値と変わってしまう事象が発生してしまったので、その復旧について書きました。 復旧の仕方がこれで正しいのかわかりませんが… 何故変わってしまったのか原因がわかったら別途書こうと思います。