Maxscale is an excellent Proxy from Mariadb Corporation, which providing the High Availability, Realtime RW split with replication Glaera cluster Amazon RDS Amazon Aurora, binlog streaming and many more advanced features, here in this blog we will discuss one such feature,
In this blog post, i am going to share my recent activity with Maxscale. We had to help one of our client to archive only the DML ( CREATE & INSERT ) data into archive server from specific table.
Problem Statement –
Our client is having only one standalone ( Master ) setup and a Archive server , they need to archive one table,Archive server should receive all the Queries as in Production Server at same time, the table should be applied only with INSERT & UPDATE statements on Archive Server. All other SQL statements has to be filtered out.
How to achieve this ? Is that possible ?
Yes, we can achieve this via the Maxscale 2.1 MQ & Tee filters(mirror).
Architecture –
Client will be connected with Maxscale, the Tee filter will be pipe all the connection from Master (standalone) to Archive via MQ filter. The MQ filter match the mentioned string & allow the needed SQL statements to archive Server.
The queries routed to the archive servers are also transformed into a canonical format and sent to a RabbitMQ broker for analysis.
Below, i am sharing my testing environment results & steps as well.
Requirements for Testing –
Mariadb Servers ( 2 )
Production Server – 192.168.33.16
Archive Server – 192.168.33.17
Maxscale & Rabbit MQ Server
Proxy Server – 192.168.33.13
Steps & Results –
MariaDB Server Installation –
I had installed the MariaDB Server on both production & archive environment using MariDB repository.
Now, we have installed all the needed things. Finally, we need to configure the Maxscale configuration file, Below is the set of configurations need for smooth process.
Note – Make sure to create the users with needed privileges for Maxscale access on both production & archive Env. Refer the MariaDB official page here for user administration.
Now, feel free we have done with the configurations.
[root@mydbopslabs13 vagrant]# maxadmin
MaxScale> list servers
Servers.
-------------------+-----------------+-------+-------------+--------------------
Server | Address | Port | Connections | Status
-------------------+-----------------+-------+-------------+--------------------
production | 192.168.33.16 | 3306 | 0 | Running
archive | 192.168.33.17 | 3306 | 0 | Running
-------------------+-----------------+-------+-------------+-------------------
Journey to testing phase –
From configuration file, i have just configured the match filter with CREATE & INSERT Statements.
match=match=\(insert\)\|\(create\)
So, it should allow the CREATE & INSERT statements to the archive & production as well. Remaining all will be affect only production Server.
In Maxscale host, i am creating the database and table with production listener port ( 4000 ).
Here archive_labs is the user, which i have created for Maxscale connection.
In production host,
[root@mydbopslabs16 vagrant]# hostname -I
192.168.33.16
[root@mydbopslabs16 vagrant]# mysql -u'archive' -p'archive@123' -e "show schemas like 'data_archivelab'" -s -N
data_archivelab
[root@mydbopslabs16 vagrant]# mysql -u'archive' -p'archive@123' -e "use data_archivelab; show tables" -s -N
archive_test
In archive host,
[root@mydbopslabs17 init.d]# hostname -I
192.168.33.17
[root@mydbopslabs17 init.d]# mysql -u'archive' -p'archive@123' -e "show schemas like 'data_archivelab'" -s -N
data_archivelab
[root@mydbopslabs17 init.d]# mysql -u'archive' -p'archive@123' -e "use data_archivelab; show tables" -s -N
archive_test
Well, seems the DB & Table has been created on both production & archive Servers.Now,
testing with INSERT Statement ,
In Maxscale host,
[root@mydbopslabs13 vagrant]# hostname -I
192.168.33.13
[root@mydbopslabs13 vagrant]# mysql -h192.168.33.13 -uarchive_labs -p'mydbops@123' -P4000 -e "use data_archivelab; insert into archive_test values(1,'MySQL'),(2,'MariaDB'),(3,'Percona'),(4,'Mydbops');"
In Production host,
[root@mydbopslabs16 vagrant]# hostname -I
192.168.33.16
[root@mydbopslabs16 vagrant]# mysql -u'archive' -p'archive@123' -e "use data_archivelab; select * from archive_test" -s -N
1 MySQL
2 MariaDB
3 Percona
4 Mydbops
In archive host,
[root@mydbopslabs17 init.d]# hostname -I
192.168.33.17
[root@mydbopslabs17 init.d]# mysql -u'archive' -p'archive@123' -e "use data_archivelab; select * from archive_test" -s -N
1 MySQL
2 MariaDB
3 Percona
4 Mydbops
Perfect, seems the results illustrate the CREATE & INSERT statements was perfectly updating the records in both production & archive Servers.
Finally, now i am going to delete some records, let see what happen,
In Maxscale host,
[root@mydbopslabs13 vagrant]# hostname -I
192.168.33.13
[root@mydbopslabs13 vagrant]# mysql -h192.168.33.13 -uarchive_labs -p'mydbops@123' -P4000 -e "use data_archivelab; delete from archive_test where id in (1,3);"
[root@mydbopslabs17 init.d]# hostname -I
192.168.33.17
[root@mydbopslabs17 init.d]# mysql -u'archive' -p'archive@123' -e "use data_archivelab; select * from archive_test" -s -N
1 MySQL
2 MariaDB
3 Percona
4 Mydbops
Well, the things are clear now. The DELETE statement is not affecting the archive Env, still it affects the production.
Hope this post will be helpful for understand the Maxscale data archiving process. This architecture can be implement in such a scenario like to save all the data without any delete or any modifications.
This completes the data archiving process with Maxscale, remaining features will be followed up in future blog posts.