InnoDB – ColumnStore レプリケーション

MariaDB Platform X4 (MariaDB Enterprise Server 10.4) では 高機能 DB Proxy である MariaDB MaxScale を介して InnoDB テーブルから ColumnStore テーブルへのレプリケーションが可能となっております。
今回はその設定方法について解説致します。

テスト環境

今回は MaxScale 1 ノード,Enterprise Server 1ノード構成でテストを実施しました。

OS: CentOS 7.7.1908

Instance name Software IP Address
es104 Enterprise Server 10.4.11-5 192.168.2.104
mxs MaxScale 2.4.6 192.168.2.24

Vagrant / VMware Workstation Pro(もしくは VirtualBox) / Ansible を用いてデプロイ/プロビジョニング可能な Vagrantfile, Ansible Playbook を以下の GitHub レポジトリで公開しております。

https://github.com/goto-satoru/vagrant-mariadb-platform-x4-htap

MariaDB Enterprise Server 10.4.11-5 / ColumnStore 1.4.2 インストール

シングルノード構成の MariaDB Enterprise Server 10.4.11-5 / ColumnStore 1.4.2 のインストール手順は過去の投稿で解説しておりますので,こちらを参照の上 Enterprise Server 10.4 / ColumnStore 1.4 のインストールを行います。

なお,Enterprise Server のダウンロードには Customer Download Token が必要となり,MariaDB Platform のサブスクリプション契約が必要とされます。

MaxScale インストール/設定

MariaDB Enterprise Server, MaxScale yum レポジトリ設定後,以下のコマンドで MaxScale をインストールします。

yum install maxscale

MaxScale の設定ファイル,/etc/maxscle.cnf は以下のように設定します。

[maxscale]
threads=auto
# log_info cause performance degradation !!!
#log_info=1
#log_notice=1

[replication-filter]
type         = filter
module       = binlogfilter
match        = /orders/
exclude      = /norepl.*/
rewrite_src  = test_idb
rewrite_dest = test_cs

[replication-router]
type     = service
router   = readconnroute
servers  = server1
user     = maxscale
password = P@ssw0rd
filters  = replication-filter

[replication-listener]
type     = listener
service  = replication-router
protocol = MariaDBClient
port     = 3309
#-----------------------------------
[base-router]
type     = service
router   = readconnroute
servers  = server1
user     = maxscale
password = P@ssw0rd

[base-listener]
type     = listener
service  = base-router
protocol = MariaDBClient
port     = 3306
#-----------------------------------
[server1]
type     = server
address  = 192.168.2.104
port     = 3306
protocol = MariaDBBackend

[server-monitor]
type             = monitor
module           = mariadbmon
servers          = server1
monitor_interval = 1000ms
user             = maxscale
password         = P@ssw0rd

replication-filter / replication-router / replication-listener は InnoDB テーブル(データベース)を ColumnStore テーブルにレプリケーションするためのもので,base-router / base-listener はアプリケーションからの接続用です。

ここで,レプリケーション・フィルタは

[replication-filter]
type         = filter
module       = binlogfilter
match        = /orders/
exclude      = /norepl.*/
rewrite_src  = test_idb
rewrite_dest = test_cs

のように設定されていますので,test_idb データベースの orders テーブルから test_cs.orders テーブルにレプリケーションします。exclude パラメータに /norepl.*/ が設定されていますので,テーブル名が norepl で始まる テーブルはレプリケーションされません。

設定後,MaxScale を起動します。

systemctl enable maxscale
systemctl start maxscale

MariaDB Enterprise Server 設定

es104 上で /etc/my.cnf.d/server.cnf 等,/etc/my.cnf.d/ に置かれる設定ファイルを以下のように設定します(拡張子: .cnf )。

[mariadb]
log_error

log_bin                       = mariadb-bin
replicate_same_server_id      = 1
log_slave_updates             = OFF
binlog_format                 = STATEMENT
columnstore_replication_slave = ON

現状,実装上の制限により binlog_format = STATEMENT である必要があります。

MaxScale 用に maxscale, レプリケーション用に repl, アプリケーションからの接続用に db_user というユーザを作成します。

CREATE USER maxscale@192.168.2.24 IDENTIFIED BY 'P@ssw0rd';
GRANT SELECT ON mysql.db            TO maxscale@192.168.2.24;
GRANT SELECT ON mysql.roles_mapping TO maxscale@192.168.2.24;
GRANT SELECT ON mysql.tables_priv   TO maxscale@192.168.2.24;
GRANT SELECT ON mysql.user          TO maxscale@192.168.2.24;
GRANT SHOW DATABASES ON *.*         TO maxscale@192.168.2.24;

GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO repl@'%' IDENTIFIED BY 'P@ssw0rd';

GRANT ALL ON *.* TO db_user@'%' IDENTIFEDY BY 'P@ssw0rd';

SHOW GRANTS FOR repl@'%';
SHOW GRANTS FOR maxscale@192.168.2.24;

MariaDB Enterprise Server を起動します。

systemctl restart mariadb

以下の SQL 文を実行,レプリケーションを設定/開始します。

STOP SLAVE;
CHANGE MASTER TO
   MASTER_USER='repl',
   MASTER_HOST='192.168.2.24',
   MASTER_PORT=3309,
   MASTER_PASSWORD='P@ssw0rd',
   MASTER_USE_GTID=current_pos;
START SLAVE;
# mariadb
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 28
Server version: 10.4.11-5-MariaDB-enterprise-log MariaDB Enterprise Server

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

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

MariaDB [(none)]> STOP SLAVE;
Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> CHANGE MASTER TO
    ->    MASTER_USER='repl',
    ->    MASTER_HOST='192.168.2.24',
    ->    MASTER_PORT=3309,
    ->    MASTER_PASSWORD='P@ssw0rd',
    ->    MASTER_USE_GTID=current_pos;
START SLAVE;
Query OK, 0 rows affected (0.003 sec)

MariaDB [(none)]> START SLAVE;
Query OK, 0 rows affected (0.004 sec)

レプリケーション設定確認

es104(Enterprise Server) 上で SHOW SLAVE STATUS \G を実行し,以下のような出力が得られるか確認します。

MariaDB [(none)]> SHOW SLAVE STATUS \G
*************************** 1. row ***************************
                Slave_IO_State: Waiting for master to send event
                   Master_Host: 192.168.2.24
                   Master_User: repl
                   Master_Port: 3309
                 Connect_Retry: 60
               Master_Log_File: mariadb-bin.000009
           Read_Master_Log_Pos: 344
                Relay_Log_File: es104-relay-bin.000002
                 Relay_Log_Pos: 645
         Relay_Master_Log_File: mariadb-bin.000009
              Slave_IO_Running: Yes
             Slave_SQL_Running: Yes
...中略...
       Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
              Slave_DDL_Groups: 0
Slave_Non_Transactional_Groups: 0
    Slave_Transactional_Groups: 0

mxs(MaxScale) 上で maxctrl list servers / maxctrl list services を実行し,以下と同等の出力が得られるか確認します。

$ maxctrl list servers
┌─────────┬───────────────┬──────┬─────────────┬───────────────────────────────────────────┬─────────┐
│ Server  │ Address       │ Port │ Connections │ State                                     │ GTID    │
├─────────┼───────────────┼──────┼─────────────┼───────────────────────────────────────────┼─────────┤
│ server1 │ 192.168.2.104 │ 3306 │ 1           │ Master, Slave of External Server, Running │ 0-1-158 │
└─────────┴───────────────┴──────┴─────────────┴───────────────────────────────────────────┴─────────┘
$ maxctrl list services
┌────────────────────┬───────────────┬─────────────┬───────────────────┬─────────┐
│ Service            │ Router        │ Connections │ Total Connections │ Servers │
├────────────────────┼───────────────┼─────────────┼───────────────────┼─────────┤
│ replication-router │ readconnroute │ 1           │ 1                 │ server1 │
├────────────────────┼───────────────┼─────────────┼───────────────────┼─────────┤
│ base-router        │ readconnroute │ 0           │ 0                 │ server1 │
└────────────────────┴───────────────┴─────────────┴───────────────────┴─────────┘

テスト

以下の SQL 文を es104 ノード上で実行し,データベース/テーブル作成,データ INSERT を行います。

CREATE DATABASE IF NOT EXISTS test_cs;
CREATE DATABASE IF NOT EXISTS test_idb;

CREATE TABLE IF NOT EXISTS test_idb.orders (
  id INT PRIMARY KEY,
  given_name VARCHAR(20),
  family_name VARCHAR(20),
  email VARCHAR(50),
  ip_address VARCHAR(20)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS test_cs.orders (
  id INT,
  given_name VARCHAR(20),
  family_name VARCHAR(20),
  email VARCHAR(50),
  ip_address VARCHAR(20)
) ENGINE=ColumnStore;

INSERT INTO test_idb.orders
(id, given_name, family_name, email, ip_address)
VALUES
 (1,"Abrahan","Eva","aeva0@deviantart.com","157.53.91.56"),
 (2,"Nickey","Croisier","ncroisier1@vkontakte.ru","196.25.72.85"),
 (3,"Alix","Le Port","aleport2@cpanel.net","62.107.59.133");

SELECT 文で InnoDBテーブル(test_idb), ColumnStoreテーブル(test_cs)双方に同じデータがあるか確認します。

InnoDBテーブル:

MariaDB [(none)]> SELECT * FROM test_idb.orders;
+----+------------+-------------+-------------------------+---------------+
| id | given_name | family_name | email                   | ip_address    |
+----+------------+-------------+-------------------------+---------------+
|  1 | Abrahan    | Eva         | aeva0@deviantart.com    | 157.53.91.56  |
|  2 | Nickey     | Croisier    | ncroisier1@vkontakte.ru | 196.25.72.85  |
|  3 | Alix       | Le Port     | aleport2@cpanel.net     | 62.107.59.133 |
+----+------------+-------------+-------------------------+---------------+

ColumnStoreテーブル:

MariaDB [(none)]> SELECT * FROM test_cs.orders;
+------+------------+-------------+-------------------------+---------------+
| id   | given_name | family_name | email                   | ip_address    |
+------+------------+-------------+-------------------------+---------------+
|    1 | Abrahan    | Eva         | aeva0@deviantart.com    | 157.53.91.56  |
|    2 | Nickey     | Croisier    | ncroisier1@vkontakte.ru | 196.25.72.85  |
|    3 | Alix       | Le Port     | aleport2@cpanel.net     | 62.107.59.133 |
+------+------------+-------------+-------------------------+---------------+

正常にテーブル間のレプリケーションが行われていることが確認できました。

まとめ

今回は MariaDB Enterprise Server 上の InnoDB テーブル / ColumnStore テーブル間で MaxScale を用いてレプリケーションを行う方法について解説させて頂きました。

なお,MariaDB MaxScale は BSL(Business Source License) というライセンスが適用されております。プロダクション環境でバックエンドの MariaDB インスタンスが 3 以上の場合は Platform X4 サブスクリプションを購入頂く必要がございますので,留意願います。