LoginSignup
0
0

More than 1 year has passed since last update.

Testlink DB (MySQL) のレプリケーション。ただし、普通にやると失敗する

Last updated at Posted at 2023-03-24

システムダウンに備えて Testlinkのデータベースをレプリケーション

Master での作業

  • レプリケーション用のユーザーを作成しておきます
  • my.ini [mysqld] に追記します。
my.ini
server-id=783
log_bin=mysql-bin
log_error=mysql-bin.err
expire_logs_days=7
binlog_do_db=testlink

DB の Flush

MariaDB [(none)]> flush tables with read lock;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> show master status;
+------------------+----------+------------------------+------------------+
| File             | Position | Binlog_Do_DB           | Binlog_Ignore_DB |
+------------------+----------+------------------------+------------------+
| mysql-bin.000005 |      758 | testlink               |                  |
+------------------+----------+------------------------+------------------+

DB Backup

C:\xampp\mysql\bin>mysqldump --single-transaction -u root -p testlink > d:\backup\testlink.db
Enter password: ****

テーブルのアンロック

MariaDB [(none)]> unlock tables;

Slave での作業

スレーブ側 phpMyAdmin config.inc.php で下記の設定を行う。
$cfg['AllowArbitraryServer'] = true

my.ini [mysqld] に追加

my.ini
server-id=908
log_bin=mysql-bin
read_only

DB Restore

# mysql -u root -p testlink < D:\Backup\testlink.db
Enter password: ****

レプリケーション設定コマンド(SQL)

CHANGE MASTER TO 
MASTER_HOST='172.100.100.100',
MASTER_USER='replica',
MASTER_PASSWORD='xxxxxx',
MASTER_LOG_FILE='mysql-bin.000005', 
MASTER_LOG_POS=758; 

レプリケーション開始

START SLAVE;

結果

SQL> show slave status\G

でエラーなし、レプリケーション開始できたように見える。
その後、マスター側 Testlink にログインし、更新をかけたところスレーブには反映されておらず、レプリケーションがストップしている。

SQL> show slave status\G で確認するとエラーになっている。

Last_Errno: 1062
Last_Error: Error 'Duplicate entry '308215' for key 'PRIMARY'' on query. Default database: 'testlink'. Query: '/* Class:tlEvent - Method: writeToDB */ INSERT INTO events (transaction_id,log_level,description,source,fired_at,object_id,object_type,activity) VALUES (0,2,'E_WARNING\nfopen(D:\\xampp\\htdocs\\testlink\\logsuserlog0.log): failed to open stream: No such file or directory - in C:\\xampp\\htdocs\\testlink\\lib\\functions\\logger.class.php - Line 1132','GUI',1678773894,0,NULL,'PHP')'
                 Skip_Counter: 0

Event Table の Duplicate Key エラー
PRIMARY KEY が重複している様子…

原因

Event Table にはログイン情報等のイベントが記録される。データ更新の確認のため、Slave 側の Testlink にログインしていたため、イベントログが書き込まれ、イベントIDがマスター側から送られてきたものと重複したためエラーになったと思われます。

ログインするだけで Event Table に書き込みが発生します。

ログイン情報は、Event Table と Transaction table に書き込まれます。
どちらも ID Field が PRIMARY Key に設定されています。

対処1

  • Slave 側の Testlink には一切触れない(ログインしない)
    ただし、これでは Slave側で参照もなにも出来ないので使い勝手が悪い

対処2

  • Testlink DB の Table: event & transaction の PRIMARY Key を通常の重複を許す Index に変えてしまう
  • transaction table もログイン・イベント関連情報の記録に使われていて、トランザクションが入っているのではない
  • Slave の Testlink にログインすると重複レコードが出来てしまうが...
  • Testlink のイベント管理で、「イベントの消去」を行うと、event & Transaction Table が消去されるので、Testlinkとしての機能には影響はなさそう
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0