Binlog Server at Facebook - 0
Binlog Server at Facebook - 0
Binlog Server at Facebook - 0
Santosh Banda
Teng Li
Database Engineering Team, Facebook, Inc.
Agenda
1 Motivation
2 Use cases
3 Design
4 Operational Commands
Binlog Storage at Facebook
………….
Binlogs Binlogs
ER_MASTER_HAS_PURGED
GTID_PURGED GTID_EXECUTED
_REQUIRED_GTIDS
uuid: 1-1000 uuid: 1-500
ER_MASTER_HAS_PURGED
GTID_PURGED Let’s fetch binary logs
_REQUIRED_GTIDS
uuid: 1-1000
Automation tools/
Change Master To / MySQLBinlog
MySQL slave
Binlog Server
Let’s fetch old binary
Binlog data stream logs
Serves Binlogs Using MySQL Protocol
Motivation
▪ Unified solution for binlog retrieve and replay
Facebook MaxScale
ReplicaSet.1 ReplicaSet.2
Copy
db1 db3
db2 db4
Online Shard Migration
▪ Copies the database using MysqlDump
ReplicaSet.2
ReplicaSet.1 Dump and load
db2_copy
db1
db3
db2
db4
Online Shard Migration
▪ Replay the binlogs using mysqlbinlog from ReplicaSet.1
ReplicaSet.2
ReplicaSet.1
Replay binlogs
db2_copy
db1
db3
db2
db4
Online Shard Migration
▪ Copy time is greater than local binlog retention time
▪ Retry
ReplicaSet.2
ReplicaSet.1 ER_MASTER_HAS_PURGED
_REQUIRED_GTIDS
db2_copy
db1
db3
db2
db4
Online Shard Migration
▪ Retry OLM
ReplicaSet.2
ReplicaSet.1 1. Dump and Load
2. Replay binlog
db2_copy
db1
db3
db2
db4
Online Shard Migration
▪ Retry… Retry…
▪ Failure !! Reach on-call
ReplicaSet.2
ReplicaSet.1 ER_MASTER_HAS_PURGED
_REQUIRED_GTIDS
db2_copy
db1
db3
db2
db4
Online Shard Migration
▪ Replay using binlog server.
▪ Copy time doesn’t affect migration
ReplicaSet.2
Success
Binlog Server db2
db3
db4
Creating New Replicas
▪ Replay using Binlog Server. Switch back to actual MySQL master
▪ No retries !!
Binlog Server
…… Success New
……
MySQL Slave
Switch to
MySQL
Binlog Server in Failover
▪ Binlog server used as semi-sync log tailers
MySQL master
Binlog Server
A
Semi-sync tailer
Dead master
Binlog Server
A
Semi-sync tailer
Dead master
Binlog Server
A
Semi-sync tailer
Dead master
Binlog Server
A
Dead master
Binlog Server
A
CHANGE MASTER
MySQL master
Binlog Server
C
Semi-sync tailer
MySQL slave
Binlog Server
B
Binlog Server in Failover
▪ Recover dead master
MySQL master
Binlog Server
C
Semi-sync tailer
Command
Binlog
Responses MySQL Parser Query Results
Event
Packets
MySQL Replication
Handler Query Processor
MySQL Parser
Command
Responses MySQL Parser Query Results
Command
Binlog
Responses MySQL Parser Query Results
Event
Packets
MySQL Replication
Handler Query Processor
▪ Log-tailer mode
▪ Backing up each MySQL instance’s binlogs as a semi-sync tailer
▪ Serving log-tailer’s binlogs as a master
Binlog Server Design
Components in HDFS mode
▪ Binlog reader/sender from HDFS
▪ A customized HDFS version of “binlog dump thread”
▪ HDFS binlog locator
▪ Uses info stored in locator DB for each replicaset
▪ HDFS binlog paths
▪ Previous GTID sets of each binlog
▪ Locates the list of required HDFS binlogs
▪ With a given GTID set
Binlog Server Design
Binlog Server in HDFS mode
Replicaset 12345
slave status:
Error Msg:
Replication
Master has
Master Greatly purged the
Lagged Slave required
binary logs
Binlog Server Design
Binlog Server in HDFS mode
Replicaset 12345
Binlog Reader/Sender
(1) change master to Binlog Server;
start slave; Greatly
Binlog Locator Lagged Slave
Binlog Server
Binlog Server Design
Binlog Server in HDFS mode
Replicaset 12345
Replicaset 12345
Binlog Reader/Sender
HDFS
Cluster (3) Read the binlogs on HDFS and
prepare binlog packet streams Binlog Locator
Binlog Server
Binlog Server Design
Binlog Server in HDFS mode
Replicaset 12345
Greatly
Binlog Locator Lagged Slave
Binlog Server
Binlog Server Design
Components in Log-tailer mode
▪ Binlog writer with acknowledgment capability
▪ Connecting to the MySQL as a semi-sync slave
▪ Writing binlogs to the Disk
▪ Acknowledge the MySQL when requested by the master
▪ Binlog reader/sender from Disk
▪ A customized version of “binlog dump thread”
Binlog Server Design
Binlog Server in Log-tailer mode
To be
promoted
Local Disk when
master dies
▪ Log-tailer mode
binlog_server>show master status\G
*************************** 1. row ***************************
File: binary-logs-3306.007965
Position: 13366
Executed_Gtid_Set: 49f5e0ca-80d2-4616-be83-d1aeb5e973bc:1-902909,
73707584-d9d1-49f1-b2bf-0ffb5e603b2d:1-81669
Operational commands
Show Slave Status in Log-tailer mode
binlog_server> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: HOSTNAME
Master_Port: PORT
Connect_Retry: 0
Master_Log_File: binary-logs-xxxxxx.007964
Read_Master_Log_Pos: 97115
Binlog_File: binary-logs-xxxxxx.007964
Binlog_Pos: 97115
Last_IO_Errno: 0
Master_Server_Id: 3695980966
Executed_Gtid_Set: ea4a5e01-b3e4-4273-a25e-88d06db8d1a5:1-902842,
b29a87bd-d60b-4455-9ab8-90d7b720f169:1-81669
Mysql_Replicaset: REPLICA_SET_NAME
Replicaset_Tier_Version: VERSION_NUM
Semisync_Slave: Yes
Operational commands
Show Master Logs in Log-tailer mode
binlog_server> show master logs; binlog_server> show master logs with gtid\G
……
Operational commands
Purging Logs in Log-tailer mode
binlog_server> show master logs;
+-------------------------+-----------+
| Log_name | File_size |
+-------------------------+-----------+
| binary-logs-3306.007962 | 124002 |
| binary-logs-3306.007963 | 131261 |
| binary-logs-3306.007964 | 15707 |
+-------------------------+-----------+
……
……
Questions?