My previous writings were mostly teoretical, so I wanted to give a more practical example, showing the actual state of the current code. I also wanted to show how I have tried to make the feature fit well into the existing replication features, without requiring the user to enable lots of options or understand lots of restrictions before being able to use it.
So let us start! We will build the code from
which at the time of writing is at revision
First, we start a master server on port 3310 and put a bit of data into it:
server1> use test; server1> create table t1 (a int primary key, b int) engine=innodb; server1> insert into t1 values (1,1); server1> insert into t1 values (2,1); server1> insert into t1 values (3,1);
To provision a slave, we take a mysqldump:
bash$ mysqldump --master-data=2 --single-transaction -uroot test > /tmp/dump.sql
Note that with
we obtain the exact binlog position corresponding to the data in
the dump. Since MariaDB 5.3, this is completely non-blocking
on the server (it does not do
FLUSH TABLES WITH READ
bash$ grep "CHANGE MASTER" /tmp/dump.sql -- CHANGE MASTER TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=910;
Meanwhile, the master server has a couple more transactions:
server1> insert into t1 values (4,2); server1> insert into t1 values (5,2);
Now let us start up the slave server on port 3311, load the dump, and start replicating from the master:
bash$ mysql -uroot test < /tmp/dump.sql server2> change master to master_host='127.0.0.1', master_port=3310, master_user='root', master_log_file='master-bin.000001', master_log_pos=910; server2> start slave; server2> select * from t1; +---+------+ | a | b | +---+------+ | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 2 | | 5 | 2 | +---+------+ 5 rows in set (0.00 sec)
So slave is up to date. In addition, when the slave connects to the master, it downloads the current GTID replication state, so everything is now ready for using global transaction ID. Let us promote the slave as the new master, and then later make the old master a slave of the new master. So stop the slave thread on the old slave, and run another transaction to simulate it being the new master:
server2> stop slave; server2> insert into t1 values (6,3);
Finally, let us attach the old master as a slave using global transaction ID:
server1> change master to master_host='127.0.0.1', master_port=3311, master_user='root', master_gtid_pos=auto; server1> start slave; server1> select * from t1; +---+------+ | a | b | +---+------+ | 1 | 1 | | 2 | 1 | | 3 | 1 | | 4 | 2 | | 5 | 2 | | 6 | 3 | +---+------+ 6 rows in set (0.01 sec)
Old master is now running as slave and is up-to-date with the new master.
So that is it! A short post from me for once, but that is the
whole point. Replication with MariaDB Global Transaction ID works
much as it always did. The only new thing here is when we issue
CHANGE MASTER to make the old master a slave of
the new master. We do not have to manually try to compute or
guess the correct binlog position on the new master, we can just
MASTER_GTID_POS=AUTO and the servers figure
out the rest for themselves.
I hope I managed to show more concretely my ideas with MariaDB Global Transaction ID. Comments and questions are most welcome, as always. Everything above is actual commands that work on the current code on Launchpad. Everything else may or may not work yet, as this is work in progress, just so you know!