MySQL Proxy meets: binlogs - sneak peek II

April 18, 2009

The slides are written, uploaded and the code snippets work. I’m ready to present.

One of the topics will be merging binlogs which is what multi-master replication is all about on the low level. A common example is sharding where you have several masters which share the same table-structures, but store the data independently. This is great for scaling out, but tricky if you have to run a query over the full dataset.

The logfiles look like:

$ mysqlbinlog binlog-merge-1.log -s
SET TIMESTAMP=1240066015/*!*/;
INSERT INTO tbl VALUES ( 1 )
/*!*/;
SET TIMESTAMP=1240066017/*!*/;
INSERT INTO tbl VALUES ( 3 )
/*!*/;
# End of log file
ROLLBACK /* added by mysqlbinlog */;

and

$ mysqlbinlog binlog-merge-2.log -s
SET TIMESTAMP=1240066016/*!*/;
INSERT INTO tbl VALUES ( 2 )
/*!*/;
SET TIMESTAMP=1240066018/*!*/;
INSERT INTO tbl VALUES ( 4 )
/*!*/;
# End of log file
ROLLBACK /* added by mysqlbinlog */;

As the two binlogs are independent and can’t contain collisions we can just merge the two binlogs based on the timestamp:

$ mysqlbinlog binlog-merged.log -s
SET TIMESTAMP=1240066015/*!*/;
INSERT INTO tbl VALUES ( 1 )
/*!*/;
SET TIMESTAMP=1240066016/*!*/;
INSERT INTO tbl VALUES ( 2 )
/*!*/;
SET TIMESTAMP=1240066017/*!*/;
INSERT INTO tbl VALUES ( 3 )
/*!*/;
SET TIMESTAMP=1240066018/*!*/;
INSERT INTO tbl VALUES ( 4 )
/*!*/;
# End of log file
ROLLBACK /* added by mysqlbinlog */;

In my session I’ll show you what is going in the background to merge any number of binlogs into one binlog. It is less than 50 lines of lua-code.

Just add a network-interface to it and another problem to make MySQL “sharding-complete” is solved.

mysql-proxy

Comments

Enable javascript to load comments.