Amazon Aurora Multi-Masterが東京リージョンにやってきました!

2020.05.16

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは!家トレにハマりまくってる恩塚です。

こちらの記事で紹介されているAmazon Aurora Multi-Masterが東京リージョンでも使えるようになりました!

【新サービス】Amazon Aurora Multi-Masterが一般公開になりました

Multi-Masterってなんぞ?

Auroraでマスターをマルチにすることができます。つまり書き込みできるインスタンスが複数になります。

Single-Masterの構成(マスターが1つとリードレプリカが1つ以上)と比較してみると次にあげるようなことが構築次第で実現できます。

  • 書き込み性能の向上
  • AZ障害などでマスターが1つ停止してもアプリケーション側でリトライするようにしておくとダウンタイム0
  • アクセスするデータによってDBインスタンスを固定する(シャーディング)
  • データを意識せずにDBインスタンスに跨ってリクエストを分散させる(ロードバランス)

(引用元)Amazon Aurora マルチマスタークラスターが東京リージョンに対応しました

やってみた

東京リージョンで作成してみるだけですがやってみます。

RDSのメニューからデータベースの作成を開きます。

以下の画像のように設定していきます。(他の項目は任意)

しばらく待つと立ち上がりました!

2つのインスタンスが起動したのでどちらでも書き込みできるか試してみます。

1台目のインスタンスでログインします。

$ mysql -uadmin -pmypassword -h multi-master-instance-1.xxxxxxxx.ap-northeast-1.rds.amazonaws.com
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 113
Server version: 5.6.10 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

テーブルを作成して適当なデータを入れます。

MySQL [(none)]> create database testdb;
Query OK, 1 row affected (0.46 sec)

MySQL [(none)]> use testdb;
Database changed

MySQL [testdb]> create table sample_table (
-> col1 int not null primary key,
-> col2 varchar(1024),
-> col3 date);
Query OK, 0 rows affected (0.91 sec)

MySQL [testdb]> insert into sample_table (col1, col2, col3)
-> values (1, 'from db1', now());
Query OK, 1 row affected, 1 warning (0.02 sec)

MySQL [testdb]> commit;
Query OK, 0 rows affected (0.00 sec)

MySQL [testdb]> select * from sample_table;
+------+----------+------------+
| col1 | col2 | col3 |
+------+----------+------------+
| 1 | from db1 | 2020-05-16 |
+------+----------+------------+
1 row in set (0.00 sec)

2台目にもログインします。

$ mysql -uadmin -pmypassword -h multi-master-instance-1-ap-northeast-1c.xxxxxxxx.ap-northeast-1.rds.amazonaws.com
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 101
Server version: 5.6.10 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

こちらからもデータを書き込みます!

MySQL [(none)]> use testdb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MySQL [testdb]> insert into sample_table (col1, col2, col3)
-> values (2, 'from db2', now());
Query OK, 1 row affected, 1 warning (0.01 sec)

MySQL [testdb]> commit;
Query OK, 0 rows affected (0.00 sec)

MySQL [testdb]> select * from sample_table;
+------+----------+------------+
| col1 | col2 | col3 |
+------+----------+------------+
| 1 | from db1 | 2020-05-16 |
| 2 | from db2 | 2020-05-16 |
+------+----------+------------+
2 rows in set (0.00 sec)

どちらからも書き込めました!

まとめ

Multi-Masterを使った検証が捗りそうです!