I'm preparing the code for my MySQLConf 2010 session "MySQL Proxy meets: Memcache" where I'll present how to replicate from MySQL to memcache by using the MySQL Proxy.

Part of it will be using the semi-sync replication support for MySQL 5.5 to implement a synchronous MySQL-to-Memcache replication. All I need is the network protocol definition for semi-sync ...

The semi-sync replication is a implemented as replication plugin and lives in:

plugins/semisync/

The master sends a binlog event with a indication that it wants to get a reply for it. Compare these two events:

[0000]  28 00 00 01|00|00 00 00 00 04 01 00 00 00 27 00  (.............'.
[0010]  00 00 00 00 00 00 20 00 14 01 00 00 00 00 00 00  ...... .........
[0020]  6c 6f 63 61 6c 2e 30 30 30 30 30 31              local.000001

... and now with semi-sync:

[0000]  2a 00 00 01|00|ef 00|00 00 00 00 04 01 00 00 00  *...............
[0010]  27 00 00 00 00 00 00 00 20 00 14 01 00 00 00 00  '....... .......
[0020]  00 00 6c 6f 63 61 6c 2e 30 30 30 30 30 31        ..local.000001

The 0xef is the semi-sync magic and the 0x00 it follows is the semi-sync flag. As it is 0, the master doesn't expect us to ACK it.

If the slave side is asked to ACK a command it sends back:

/* The layout of a semisync slave reply packet:
   1 byte for the magic num
   8 bytes for the binlog positon
   n bytes for the binlog filename, terminated with a '\0'
*/
#define REPLY_MAGIC_NUM_LEN 1
#define REPLY_BINLOG_POS_LEN 8
#define REPLY_BINLOG_NAME_LEN (FN_REFLEN + 1)
#define REPLY_MAGIC_NUM_OFFSET 0
#define REPLY_BINLOG_POS_OFFSET (REPLY_MAGIC_NUM_OFFSET + REPLY_MAGIC_NUM_LEN)
#define REPLY_BINLOG_NAME_OFFSET (REPLY_BINLOG_POS_OFFSET + REPLY_BINLOG_POS_LEN)

Beware, the binlog filename is 255 chars max: http://bugs.mysql.com/bug.php?id=52748

The master will wait until a slave sent a ACK to its event before it commits the transaction.

[0000]  15 00 00 00|ef|fe 03 00 00 00 00 00 00|6c 6f 63  .............loc
[0010]  61 6c 2e 30 30 30 30 30 32                       al.000002

Import is that you send the packet-id 0x00. Otherwise the master will ignore the packet. The master will send a OK packet as response to your ACK:

[0000]  07 00 00 01|00 00 00 02 00 00 00

Comments

Enable javascript to load comments.