SlideShare a Scribd company logo
Riding the Binlog:
an in Deep Dissection
of the Replication Stream
Jean-François Gagné
jeanfrancois DOT gagne AT booking.com
Presented at Percona Live Amsterdam 2015
Booking.com
1
Booking.com’
● Based in Amsterdam since 1996
● Online Hotel and Accommodation Agent:
● 170 offices worldwide
● +795.000 properties in 221 countries
● 42 languages (website and customer service)
● Part of the Priceline Group
● And we use MySQL:
● Thousands (1000s) of servers, ~85% replicating
● >110 masters: ~25 >50 slaves & ~8 >100 slaves
2
Riding the Binlog: Replication
● One master / one or more slaves
● The master records all writes in a journal: the binary logs
● Each slave:
● Downloads the journal and saves it locally (IO thread): relay logs
● Executes the relay logs on the local database (SQL thread)
● Could produce binary logs to be itself a master (log-slave-updates)
● Understood replication features:
● Asynchronous
● Single threaded
3
Riding the Binlog: Replication’
+---+
| A |
+---+
|
+------+------+---------------+
| | | |
+---+ +---+ +---+ +---+
| B | | C | | D | | E |
+---+ +---+ +---+ +---+
|
+------+------+
| | |
+---+ +---+ +---+
| F | | G | | H |
+---+ +---+ +---+
4
Riding the Binlog: Replication’’
● More understood binlog/replication features:
● Master side binary log filtering
● Binlog_Do_DB / Binlog_Ignore_DB
(avoid those in favor of slave side filtering)
● sql_log_bin
● Slave side filtering:
● Replicate_Do_DB / Replicate_Ignore_DB
● Replicate_Do_Table / Replicate_Ignore_Table
● Replicate_Wild_Do_Table / Replicate_Wild_Ignore_Table
● Circular replication
● New innovations in replication land:
● Global Transaction Identifiers (GTIDs)
● Multi-Source and Multi-Threaded Replication (many types)
● Binlog Servers 5
Riding: the Binary Logs (on master)
> ls –l # Dots (.) in the file sizes are added for readability.
[...]
-rw-rw---- 1 mysql mysql 537.362.886 Sep 13 10:19 binlog.000878
-rw-rw---- 1 mysql mysql 537.341.120 Sep 13 10:22 binlog.000879
-rw-rw---- 1 mysql mysql 6431.760.382 Sep 13 11:13 binlog.000880
-rw-rw---- 1 mysql mysql 537.394.773 Sep 13 11:26 binlog.000881
-rw-rw---- 1 mysql mysql 537.288.989 Sep 13 11:29 binlog.000882
-rw-rw---- 1 mysql mysql 111.419.262 Sep 13 11:30 binlog.000883
-rw-rw---- 1 mysql mysql 10.411.193 Sep 13 11:30 binlog.000884
-rw-rw---- 1 mysql mysql 537.271.616 Sep 13 11:34 binlog.000885
-rw-rw---- 1 mysql mysql 537.290.232 Sep 13 11:38 binlog.000886
[...]
● Let’s use mysqlbinlog to see what is in those files.
6
Riding: the Binary Logs’
mysql plams <<< "CREATE TABLE test1 (
my_pk BIGINT AUTO_INCREMENT,
my_bigint BIGINT DEFAULT NULL,
my_datetime DATETIME DEFAULT NULL,
PRIMARY KEY(my_pk));"
# at 217
#150919 12:04:27 server id 1 end_log_pos 428 CRC32 0xebef2e40
Query thread_id=3100 exec_time=0 error_code=0
use `plams`
SET TIMESTAMP=1442657067
CREATE TABLE test1 ( my_pk BIGINT AUTO_INCREMENT, my_bigint
BIGINT DEFAULT NULL, my_datetime DATETIME DEFAULT NULL,
PRIMARY KEY(my_pk))
7
Riding: the Binary Logs’’
mysql plams <<< "INSERT INTO test1(my_pk) VALUES (1);"
# (Omitting “SET TIMESTAMP=...”.)
# at 428
#150919 12:04:30 server id 1 end_log_pos 509 ... Query ...
BEGIN
# at 509
#150919 12:04:30 server id 1 end_log_pos 620 ... Query ...
INSERT INTO test1(my_pk) VALUES (1)
# at 620
#150919 12:04:30 server id 1 end_log_pos 651 ... Xid = ...
COMMIT
8
Riding: the Binary Logs’’’
# PK (auto_increment) not specified.
mysql plams <<< "INSERT INTO test1(my_bigint, my_datetime) 
VALUES (floor(1024*1024*rand()), now());"
# (Omitting BEGIN/COMMIT.)
# at 740 / # at 772 / # at 811
#150919 12:04:38 server id 1 end_log_pos 772 ... Intvar
SET INSERT_ID=2
#150919 12:04:38 server id 1 end_log_pos 811 ... Rand
SET @@RAND_SEED1=80977572, @@RAND_SEED2=154388004
#150919 12:04:38 server id 1 end_log_pos 976 ... Query ...
SET TIMESTAMP=1442657078
INSERT INTO test1(my_bigint, my_datetime) VALUES
(floor(1024*1024*rand()), now())
9
Riding: the Binary Logs’’’ ’
mysql plams <<< "
BEGIN;
INSERT INTO test1(my_datetime) VALUES (now());
SELECT sleep(5);
INSERT INTO test1(my_datetime) VALUES (now());
COMMIT;" &
mysql plams <<< "
SELECT sleep(1);
INSERT INTO test1(my_datetime) VALUES (now());"
10
Riding: the Binary Logs’’’ ’’
# (Omitting BEGIN/COMMIT/“SET TIMESTAMP=...”.)
# at 1096 / # at 1128 / SET INSERT_ID=4
#150919 12:05:00 server id 1 end_log_pos 1257 ... Query ...
INSERT INTO test1(my_datetime) VALUES (now())
# at 1377 / # at 1409 / SET INSERT_ID=3
#150919 12:04:58 server id 1 end_log_pos 1538 ... Query ...
INSERT INTO test1(my_datetime) VALUES (now())
# at 1538 / # at 1570 / SET INSERT_ID=5
#150919 12:05:03 server id 1 end_log_pos 1699 ... Query ...
INSERT INTO test1(my_datetime) VALUES (now())
11
Riding: the Binary Logs’’’ ’’’
mysql plams <<< "SET binlog_format = ROW;
INSERT INTO test1(my_datetime) VALUES (now());"
# (Omitting BEGIN/COMMIT.)
# at 1811
#... Table_map: `plams`.`test1` mapped to number 143
# at 1863
#... Write_rows: table id 143 flags: STMT_END_F
BINLOG '
VTP9VRMBAAAANAAAAEcHAAAAAI8AAAAAAAEABXBsYW1zAAV0ZXN0MQADCAgSAQAGVr3KSw==
VTP9VR4BAAAAMQAAAHgHAAAAAI8AAAAAAAEAAgAD//oGAAAAAAAAAJmXJsFJmHAAYw==
12
Riding: the Binary Logs’’’ ’’’
# mysqlbinlog -v
# (Omitting BEGIN/COMMIT.)
# at 1811
#... Table_map: `plams`.`test1` mapped to number 143
# at 1863
#... Write_rows: table id 143 flags: STMT_END_F
BINLOG '
VTP9VRMBAAAANAAAAEcHAAAAAI8AAAAAAAEABXBsYW1zAAV0ZXN0MQADCAgSAQAGVr3KSw==
VTP9VR4BAAAAMQAAAHgHAAAAAI8AAAAAAAEAAgAD//oGAAAAAAAAAJmXJsFJmHAAYw==
### INSERT INTO `plams`.`test1`
### SET
### @1=6
### @2=NULL
### @3='2015-09-19 12:05:09'
13
Riding: the Binary Logs’’’ ’’’
# mysqlbinlog -vv
# (Omitting BEGIN/COMMIT.)
# at 1811
#... Table_map: `plams`.`test1` mapped to number 143
# at 1863
#... Write_rows: table id 143 flags: STMT_END_F
BINLOG '
VTP9VRMBAAAANAAAAEcHAAAAAI8AAAAAAAEABXBsYW1zAAV0ZXN0MQADCAgSAQAGVr3KSw==
VTP9VR4BAAAAMQAAAHgHAAAAAI8AAAAAAAEAAgAD//oGAAAAAAAAAJmXJsFJmHAAYw==
### INSERT INTO `plams`.`test1`
### SET
### @1=6 /* LONGINT meta=0 nullable=0 is_null=0 */
### @2=NULL /* LONGINT meta=0 nullable=1 is_null=1 */
### @3='2015-09-19 12:05:09' /* DATETIME(0) meta=0 nullable=1 is_null=0 */
14
Riding: the Binary Logs’’’ ’’’ ’
● Binary Logs: Journal for MySQL Replication
● Files with a basename and 6 digit index
● Stream of transactions in commit order
● A transaction is never split in 2 binlog files
● But a transaction is split in many events
● Want to know more:
● Read the documentation
● Or source dive: sql/log_event.{h,cc}
15
Riding: some Event Types
sql/log_event.h
enum Log_event_type {
UNKNOWN_EVENT= 0,
QUERY_EVENT= 2,
STOP_EVENT= 3,
ROTATE_EVENT= 4,
INTVAR_EVENT= 5,
LOAD_EVENT= 6,
CREATE_FILE_EVENT= 8,
APPEND_BLOCK_EVENT= 9,
EXEC_LOAD_EVENT= 10,
DELETE_FILE_EVENT= 11,
NEW_LOAD_EVENT= 12,
RAND_EVENT= 13,
USER_VAR_EVENT= 14,
16
FORMAT_DESCRIPTION_EVENT= 15,
XID_EVENT= 16,
TABLE_MAP_EVENT = 19,
INCIDENT_EVENT= 26,
HEARTBEAT_LOG_EVENT= 27,
IGNORABLE_LOG_EVENT= 28,
ROWS_QUERY_LOG_EVENT= 29,
WRITE_ROWS_EVENT = 30,
UPDATE_ROWS_EVENT = 31,
DELETE_ROWS_EVENT = 32,
GTID_LOG_EVENT= 33,
ANONYMOUS_GTID_LOG_EVENT= 34,
PREVIOUS_GTIDS_LOG_EVENT= 35,
Riding: the Binlogs on Slaves
+---+ +---+
| M | --> | S |
+---+ +---+
● Depends on log-slave-updates (lsu):
● If lsu disabled: no trx from the master in the binlogs of the slave
● else: SQL Thread logs its transactions
● binlogs on a slave != binlogs on the master:
● FLUSH BINARY LOGS
● Restart of mysqld on the master or slave
● RESET MASTER on slave
● Different binlog filenames on master and slave
● …
17
Riding: the Binlogs on Slaves’
● Binlogs on the master:
-rw-rw---- 1 mysql mysql 40720631 Sep 19 13:16 binlog.000001
-rw-rw---- 1 mysql mysql 16777476 Sep 19 13:17 binlog.000002
-rw-rw---- 1 mysql mysql 16777476 Sep 19 13:18 binlog.000003
-rw-rw---- 1 mysql mysql 10124412 Sep 19 13:18 binlog.000004
-rw-rw---- 1 mysql mysql 8388820 Sep 19 13:18 binlog.000005
-rw-rw---- 1 mysql mysql 8388820 Sep 19 13:19 binlog.000006
-rw-rw---- 1 mysql mysql 6964108 Sep 19 13:19 binlog.000007
[...]
● And on a slave:
-rw-rw---- 1 mysql mysql 67109007 Sep 19 13:21 binlog.000001
-rw-rw---- 1 mysql mysql 67108948 Sep 19 13:22 binlog.000002
-rw-rw---- 1 mysql mysql 52518911 Sep 19 13:22 binlog.000003
-rw-rw---- 1 mysql mysql 45279097 Sep 19 13:30 binlog.000004
 The content of the binary logs on slaves is (hopefully)
the same as on the master, but the transport is different.
18
Riding: the Binlogs on Slaves’’
● Depends on slave-local transactions (and lsu):
● If lsu disabled: the slave behaves like a master
● The slave has its own transaction/binlog stream
● This stream is independent from the master stream (lsu disabled)
● else: local trx UNION master trx (multiplexing)
● The slave transaction stream merges with the master stream
● Those might be independent, or might depend on each other
+---+ +---+
WRITES --> | M | --> | S |
+---+ +---+
^
|
+--- WRITES
19
Riding: the Binlogs on Slaves’’’
● If lsu enabled, also depends on replication filters:
● If no filter: binlogs on slave contain local and master trx
● else: depends of MySQL 5.6 GTIDs:
● Without 5.6 GTIDs, filtered transaction are skipped (exclusion)
● With 5.6 GTIDs: an empty transaction is logged (mutation)
(Transactions can be filtered fully or partially : also mutation)
+---+ +---+
| M | --> | S |
+---+ +---+
20
Riding: the Binlogs on Slaves’’’ ’
● Circular-replication (needs log-slave-updates):
● Combination of slave local transactions and filters
● local trx UNION (master trx SUB “same server_id” trx)
(multiplexing with exclusion)
+---+ +---+
| M1| ----> | M2|
+---+ +---+
^ |
| +---+ |
+-- | M3| <-+
+---+
21
Riding: the Binlogs on Slaves’’’ ’’
● Depends on Multi-Source Replication:
● If lsu disabled: only slave local transactions
● else: local trx UNION M1 trx UNION M2 trx … (multiplexing)
(Identically configured slave might multiplex in different ways)
(Filters can be added to multi-source  mutation)
+---+ +---+
| M1| | M2|
+---+ +---+
| |
+---+-----+ +-----+---+
| | | |
+---+ +-+------+ | +---+
| S1| | +----|-+-+ | S2|
+---+ | | | | +---+
+---+ +---+
| X1| | X2|
+---+ +---+
22
Riding: the Binlogs on Slaves’’’ ’’’
● Depends on Multi-Threaded Replication (MySQL 5.6 schema based):
● If lsu disabled: only slave local transactions
● else: reordering of transactions (morphing)
● On the master, some transactions in 3 schemas (A, B, C):
● Order in the Binary Logs: A1, A2, B1, B2, C1, A3, C2, B3, C3
● On the slave, transactions in different schema run in //:
“A1,A2,A3” in // with “B1,B2,B3” in // with “C1,C2,C3”
● One possible order: A1, B1, C1, A2, B2, C2, A3, B3, C3
● Another: A1, C1, A2, C2, A3, C3, B1, B2, B3 (if B1 is big)
● Many others…
23
Riding: the Binlogs on Slaves’’’ ’’’ ’
● Depends on MySQL 5.7 Logical Clock Parallel Replication:
● If lsu disabled: only slave local transactions
● else if slave_preserve_commit_order = OFF (default):
reordering of transactions (morphing)
● else (slave_preserve_commit_order = ON)
modification of parallelism information (still morphing)
24
Riding: the Binlogs on Slaves’’’ ’’’ ’’
● Four transactions on X and Y:
+---+
| X |
+---+
|
V
+---+
| Y |
+---+
 Transaction order in the binary logs of Y:
(without slave_preserve_commit_order)
 T3, T4, T2, T1
25
On Y:
----Time---->
B-------C
B-----C
B---C
B----C
On X:
----Time---->
T1 B-------C
T2 B-----C
T3 B---C
T4 B----C
On Y
(with slave_preserve_commit_order):
----Time---->
B-------C
B-----. C
B---. . C
B---- . C
Riding: the Binlogs on Slaves’’’ ’’’ ’’’
● Four other transactions on X and Y:
+---+
| X |
+---+
|
V
+---+
| Y |
+---+
|
V
+---+
| Z |
+---+
 IM (Y) might stall the parallel replication pipeline
 Replicating with IM will slow down parallel replication
26
On Y:
----Time---->
B---C
B---C
B-------C
B-------C
On Z:
----Time--------->
B---C
B---C
B-------C
B-------C
On X:
----Time---->
T1 B---C
T2 B---C
T3 B-------C
T4 B-------C
Riding: the Binlogs on Slaves’’’ ’’’ ’’’ ’
● Let’s try to summarise:
● Multiplexing:
● Local transactions + log-slave-updates
● Circular Replication (needs log-slave-updates)
● Multi-Source + log-slave-updates
● Morphing:
● All types of Multi-Threaded replication + log-slave-updates
● Mutation:
● Filters + MySQL 5.6 GTIDs + log-slave-updates
● See the pattern…
● log-slave-updates
27
Riding the Binlog: why lsu ?
● Lsu is needed for:
● master promotion with GTIDs
● fan-out
● circular replication
● external trigger
● converting SBR to RBR
● new version/feature testing
● multiplexing with a side effect
28
Riding the Binlog: lsu with GTIDs
● After the failure of M, new master promotion needs
levelling the remaining slaves
+---+
| M |
+---+
| bl_M
+-------+-------+
| | |
+---+ +---+ +---+
| S1| | S2| | S3|
+---+ +---+ +---+
bl_S1 bl_S2 bl_S3
29
● If S2 is the most up to date slave:
● bl_S2 will be used to level S1 and S3
● Ok if bl_S2 is a different transport of bl_M
● Ok-ish if bl_S2 is a simple morphing of bl_M
● NOT-Ok if bl_S2 is a mutation of bl_M
 If you must replicate using lsu
put Intermediate Master between
the master and mutation (filtering) slave
(or you might loose those slave during promotion)
 Or use Binlog Servers
Riding the Binlog: lsu for Fan-Out
● Remote site or too many slaves: needs a fan-out solution
+---+
| M |
+---+
|
+-- ... --+
| |
+---+ +---+
| M1| | Mx|
+---+ +---+
| |
+-- ... +-- ... --+
| | |
+---+ +---+ +---+
| S1| | Z1| | Zi|
+---+ +---+ +---+
30
● Intermediate Masters slow down replication
(including parallel replication)
● Their failure needs to be managed
● Rogue transactions need to be managed
● And we still have the risks/problems
associated with morphing and mutations
 IMs come with many drawbacks
 Avoiding them might be better
 Binlog Servers allow that
Riding the Binlog: Circular Replication
● Circular replication is a form of multiplexing
+---+ +---+
| M1| ----> | M2|
+---+ +---+
^ |
| +---+ |
+-- | M3| <-+
+---+
● But Multi-Source replication is also multiplexing
 Replace Circular replication by Multi-Source
● High Availability is tricky
● But it was not simple either with Circular Replication
● And it is very simple with Binlog Servers
31
Riding the Binlog: Circular Replication’
32
● Replace the following:
+---+ +---+
|S11| <---+ +---+ +---+ +---> |S21|
+---+ +- | M1| ----> | M2| -+ +---+
+---+ | +-+-+ +-+-+ | +---+
|S12| <-+ ^ | +-> |S22|
+---+ | | +---+ | | +---+
+---+ | +-- | M3| <-+ | +---+
|S13| <--+ +-+-+ +--> |S23|
+---+ | +---+
/------+------
+---+ V +---+
|S31| +---+ |S33|
+---+ |S32| +---+
+---+
Riding the Binlog: Circular Replication’’
33
● By this:
+---+ +---+ +---+
| M1| | M2| | M3|
+---+ +---+ +---+
V^^ |^^ |^^
+------+----+||-----|+|-----|+|----+------+
| | || V | | | | |
|+-----|+----+|-----+-|-----|-+----|+-----|+
|| || | | V || ||
||+----||+----+-------+-----+------||+----||+
VVV VVV VVV VVV
+---+ +---+ +---+ +---+
| S1| | S2| ... |...| | Sn|
+---+ +---+ +---+ +---+
Riding the Binlog: Binlog Server
● Binlog Server (BLS): is a daemon that:
● Downloads the binary logs from the master
● Saves them identically as on the master
● Serves them to slaves
● A or X are the same for B and C:
● By design, the binary logs served by A and X are the same
34
+---+ / 
| A | ---> / X 
+---+ -----
| |
+---+ +---+
| B | | C |
+---+ +---+
Riding the Binlog: BLS – Fan-out
● Replace Intermediate Master by Binlog Servers:
+---+
| M |
+---+
|
+----------------+------ ... ------+
| | |
/  /  / 
/ I1 / I2 / Im
----- ----- -----
| | |
+------+ ... +--- ... +--- ... ---+
| | | | |
+---+ +---+ +---+ +---+ +---+
| S1| | S2| | Si| | Sj| | Sn|
+---+ +---+ +---+ +---+ +---+
● If BLS fails, repoint slaves to other BLSs (easy by design)
35
Riding the Binlog: BLS – HA
● Distributed Binlog Serving Service (DBSS):
+---+
| M |
+---+
|
+----+----------------------------------------------------+
| |
+----+-------+-----------+-------+-----------+-------+----+
| | | | | |
+---+ +---+ +---+ +---+ +---+ +---+
| S1|...| Sn| | T1|...| Tm| | U1|...| Uo|
+---+ +---+ +---+ +---+ +---+ +---+
36
Riding the Binlog: BLS – HA’
● Zoom in DBSS:
|
+----|---------------------------------------------------------+
| | |
| +----------------------+---------------------+ |
| | | | |
| /  /  /  |
| / --->/  / --->/  / --->/  |
| ----- /  ----- /  ----- /  |
| | ----- | ----- | ----- |
+----|-------|--------------|-------|-------------|-------|----+
| | | | | |
37
Riding the Binlog: BLS – HA’’
38
--/- +---+
| X | | T1|
-/-- +---+
|
+------------------------+--------------------------------+
| |
+----+-------+-----------+-------+-----------+-------+----+
| | | | | |
+---+ +---+ +---+ +---+ +---+ +---+
| S1|...| Sn| | T2|...| Tm| | U1|...| Uo|
+---+ +---+ +---+ +---+ +---+ +---+
Riding the Binlog: why lsu ?’
● Lsu is needed for:
● master promotion with GTIDs: use with care or Binlog Servers
● fan-out: Binlog Servers
● circular replication: replaced by Multi-Source + Binlog Servers
● external trigger
● converting SBR to RBR
● new version/feature testing
● multiplexing with a side effect
39
Riding the Binlog: external trigger
● If we need to trigger an event after commit on a slave,
log-slave-updates is a good solution
+---+
| M |
+---+
| bl_M
|
+---+
| S |
+---+
bl_S
|
+-> Memcache
40
● An example is cache invalidation
● But morphing and mutation is still there
● Remember above when tempted to use
the slave binlogs for other use-cases (HA)
● Cache invalidation does not need full binlogs
 A custom binary log format dedicated to that
might be useful
Riding the Binlog: SBR to RBR
● When a master is SBR and you need Row-Based Events
● log-slave-updates is currently your only solution
● But consuming Row-Based Events on a slave introduces
morphing, mutation and a single point of failure
● Also, migrating from SBR to RBR is complex
● Wouldn’t it be great if:
● the master logs in both SBR and RBR format,
● And each slave chooses to follow the SBR or RBR stream.
 I suggest a new binary log format: multiplexed
● (with the corresponding configuration on slaves)
41
Riding the Binlog: why lsu ?’’
● Lsu is needed for:
● master promotion with GTIDs: use with care or Binlog Servers
● fan-out: Binlog Server
● circular replication: replaced by Multi-Source + Binlog Servers
● external trigger (cache invalidation): OK
● converting SBR to RBR: new binary log format
● new version/feature testing
● multiplexing with a side effect
42
Riding the Binlog: why lsu ?’’
● Lsu is needed for:
● master promotion with GTIDs: use with care or Binlog Servers
● fan-out: Binlog Server
● circular replication: replaced by Multi-Source + Binlog Servers
● external trigger (cache invalidation): OK
● converting SBR to RBR: new binary log format
● new version/feature testing: ok, not really production
● multiplexing with a side effect
43
Riding the Binlog: why lsu ?’’’
● Lsu is needed for:
● master promotion with GTIDs: use with care or Binlog Servers
● fan-out: Binlog Server
● circular replication: replaced by Multi-Source + Binlog Servers
● external trigger (cache invalidation): OK
● converting SBR to RBR: new binary log format
● new version/feature testing: ok, not really production
● multiplexing with a side effect:
very complex use-case, not covered in the talk
44
Riding the Binlog: Conclusion
● The Binary logs are a stream of transactions
● Enabling log-slave-updates makes this stream evolves
● Those evolutions are complex
● Tips to manage those evolutions in combination with HA:
● A filtering slave should replicate through an intermediate master
● A slave with local transaction should also replicate through an IM
● Avoid using log-slave-updates for replication (use Binlog Servers)
● Learn more tomorrow: Binlog Server at Booking.com
● Wed. 23 September, 2:10PM - 3:00PM @ Matterhorn 1
● https://www.percona.com/live/europe-amsterdam-
2015/sessions/binlog-servers-bookingcom
45
Riding: the Binlog Function on Slaves
46
Relay Logs
Binary Logs
Configuration
• filters (empty trx w GTID)
• slave-parallel-workers
• slave-preserve-
commit-order
• binlog_format
Content of the Database
Local Transactions
Relay Logs2 Relay Logs3
Human
• skipping transactions
• modifying configuration
• restarting MySQL
• doing other mistakes
Hardware
• # and speed of CPU
• amount of RAM
• speed of storage
(RAID rebuild ?)
• network (congestion ?)
Load on the system
(virtualisation ?)State of the Buffer Pool log-slave-updates
??? Others ???
Riding: the Binlog Function on Slaves
47
Binary Logs
Local Transactions
Without log-slave-updates
Riding the Binlog: Links
Binlog Servers:
● http://blog.booking.com/mysql_slave_scaling_and_more.html
● http://blog.booking.com/abstracting_binlog_servers_and_mysql_maste
r_promotion_wo_reconfiguring_slaves.html
IM Morphing Loosing Parallelism Information:
● http://blog.booking.com/better_parallel_replication_for_mysql.html
● (http://blog.booking.com/evaluating_mysql_parallel_replication_2-
slave_group_commit.html)
Others
● https://www.percona.com/blog/2009/05/14/why-mysqls-binlog-do-db-
option-is-dangerous/
48
Thanks
Jean-François Gagné
jeanfrancois DOT gagne AT booking.com

More Related Content

PDF
MySQL Parallel Replication: inventory, use-case and limitations
PDF
MySQL Parallel Replication: inventory, use-case and limitations
PDF
MySQL Parallel Replication: inventory, use-cases and limitations
PDF
MySQL/MariaDB Parallel Replication: inventory, use-case and limitations
PDF
MySQL Parallel Replication (LOGICAL_CLOCK): all the 5.7 (and some of the 8.0)...
PDF
MySQL Parallel Replication by Booking.com
PDF
The Full MySQL and MariaDB Parallel Replication Tutorial
PDF
How Booking.com avoids and deals with replication lag
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-cases and limitations
MySQL/MariaDB Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication (LOGICAL_CLOCK): all the 5.7 (and some of the 8.0)...
MySQL Parallel Replication by Booking.com
The Full MySQL and MariaDB Parallel Replication Tutorial
How Booking.com avoids and deals with replication lag

What's hot (20)

PDF
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
PDF
FOSDEM 2012: MySQL synchronous replication in practice with Galera
PDF
MySQL Replication Troubleshooting for Oracle DBAs
PDF
MySQL GTID Concepts, Implementation and troubleshooting
PDF
MySQL Multi-Source Replication for PL2016
PDF
M|18 Under the Hood: Galera Cluster
PDF
FOSDEM 2015: gdb tips and tricks for MySQL DBAs
PDF
MariaDB Server on macOS - FOSDEM 2022 MariaDB Devroom
PDF
NoSQL with MySQL
PDF
The New MariaDB Offering - MariaDB 10, MaxScale and more
PDF
Tracing and profiling my sql (percona live europe 2019) draft_1
PDF
PERFORMANCE_SCHEMA and sys schema
PDF
Gdb basics for my sql db as (percona live europe 2019)
PDF
Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)
PDF
MySQL always-up with Galera Cluster
PDF
HA with Galera
PDF
Using advanced options in MariaDB Connector/J
PDF
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
PDF
MyRocks in MariaDB: why and how
PDF
Managing and Visualizing your Replication Topologies with Orchestrator
Almost Perfect Service Discovery and Failover with ProxySQL and Orchestrator
FOSDEM 2012: MySQL synchronous replication in practice with Galera
MySQL Replication Troubleshooting for Oracle DBAs
MySQL GTID Concepts, Implementation and troubleshooting
MySQL Multi-Source Replication for PL2016
M|18 Under the Hood: Galera Cluster
FOSDEM 2015: gdb tips and tricks for MySQL DBAs
MariaDB Server on macOS - FOSDEM 2022 MariaDB Devroom
NoSQL with MySQL
The New MariaDB Offering - MariaDB 10, MaxScale and more
Tracing and profiling my sql (percona live europe 2019) draft_1
PERFORMANCE_SCHEMA and sys schema
Gdb basics for my sql db as (percona live europe 2019)
Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)
MySQL always-up with Galera Cluster
HA with Galera
Using advanced options in MariaDB Connector/J
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
MyRocks in MariaDB: why and how
Managing and Visualizing your Replication Topologies with Orchestrator
Ad

Similar to Riding the Binlog: an in Deep Dissection of the Replication Stream (20)

PDF
Percona Live 2012PPT: introduction-to-mysql-replication
PPT
MySQL 5.1 Replication
PDF
MySQL Cluster Asynchronous replication (2014)
PDF
Replication features, technologies and 3rd party Extinction
PDF
Undelete (and more) rows from the binary log
PPTX
MySQL Replication Overview -- PHPTek 2016
PDF
MySQL 5.6 Replication Webinar
PDF
Using The Mysql Binary Log As A Change Stream
PDF
MySQL replication best practices 105-232-931
PPTX
Consistency between Engine and Binlog under Reduced Durability
PDF
Best practices for MySQL High Availability
PDF
MySQL Replication Basics -Ohio Linux Fest 2016
PPTX
ConFoo MySQL Replication Evolution : From Simple to Group Replication
PDF
MySQL Time Machine by replicating into HBase - Slides from Percona Live Amste...
PDF
The consequences of sync_binlog != 1
PDF
MySQL Replication Update -- Zendcon 2016
PDF
MySQL 5.5 Replication Enhancements – An Overview (FOSDEM 2011)
PPT
C_mysql-1.ppt
PDF
Pseudo GTID and Easy MySQL Replication Topology Management
PDF
Mysteries of the binary log
Percona Live 2012PPT: introduction-to-mysql-replication
MySQL 5.1 Replication
MySQL Cluster Asynchronous replication (2014)
Replication features, technologies and 3rd party Extinction
Undelete (and more) rows from the binary log
MySQL Replication Overview -- PHPTek 2016
MySQL 5.6 Replication Webinar
Using The Mysql Binary Log As A Change Stream
MySQL replication best practices 105-232-931
Consistency between Engine and Binlog under Reduced Durability
Best practices for MySQL High Availability
MySQL Replication Basics -Ohio Linux Fest 2016
ConFoo MySQL Replication Evolution : From Simple to Group Replication
MySQL Time Machine by replicating into HBase - Slides from Percona Live Amste...
The consequences of sync_binlog != 1
MySQL Replication Update -- Zendcon 2016
MySQL 5.5 Replication Enhancements – An Overview (FOSDEM 2011)
C_mysql-1.ppt
Pseudo GTID and Easy MySQL Replication Topology Management
Mysteries of the binary log
Ad

More from Jean-François Gagné (9)

PDF
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
PDF
Demystifying MySQL Replication Crash Safety
PDF
Autopsy of a MySQL Automation Disaster
PDF
MySQL Scalability and Reliability for Replicated Environment
PDF
MySQL Scalability and Reliability for Replicated Environment
PDF
Demystifying MySQL Replication Crash Safety
PDF
Demystifying MySQL Replication Crash Safety
PDF
The two little bugs that almost brought down Booking.com
PDF
Autopsy of an automation disaster
MySQL Parallel Replication: All the 5.7 and 8.0 Details (LOGICAL_CLOCK)
Demystifying MySQL Replication Crash Safety
Autopsy of a MySQL Automation Disaster
MySQL Scalability and Reliability for Replicated Environment
MySQL Scalability and Reliability for Replicated Environment
Demystifying MySQL Replication Crash Safety
Demystifying MySQL Replication Crash Safety
The two little bugs that almost brought down Booking.com
Autopsy of an automation disaster

Recently uploaded (20)

PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Architecture types and enterprise applications.pdf
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Developing a website for English-speaking practice to English as a foreign la...
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Tartificialntelligence_presentation.pptx
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Getting Started with Data Integration: FME Form 101
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
project resource management chapter-09.pdf
PPT
What is a Computer? Input Devices /output devices
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
WOOl fibre morphology and structure.pdf for textiles
Web App vs Mobile App What Should You Build First.pdf
Hindi spoken digit analysis for native and non-native speakers
Group 1 Presentation -Planning and Decision Making .pptx
Architecture types and enterprise applications.pdf
A contest of sentiment analysis: k-nearest neighbor versus neural network
Enhancing emotion recognition model for a student engagement use case through...
Developing a website for English-speaking practice to English as a foreign la...
Programs and apps: productivity, graphics, security and other tools
Tartificialntelligence_presentation.pptx
NewMind AI Weekly Chronicles – August ’25 Week III
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Getting Started with Data Integration: FME Form 101
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
project resource management chapter-09.pdf
What is a Computer? Input Devices /output devices
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...

Riding the Binlog: an in Deep Dissection of the Replication Stream

  • 1. Riding the Binlog: an in Deep Dissection of the Replication Stream Jean-François Gagné jeanfrancois DOT gagne AT booking.com Presented at Percona Live Amsterdam 2015
  • 3. Booking.com’ ● Based in Amsterdam since 1996 ● Online Hotel and Accommodation Agent: ● 170 offices worldwide ● +795.000 properties in 221 countries ● 42 languages (website and customer service) ● Part of the Priceline Group ● And we use MySQL: ● Thousands (1000s) of servers, ~85% replicating ● >110 masters: ~25 >50 slaves & ~8 >100 slaves 2
  • 4. Riding the Binlog: Replication ● One master / one or more slaves ● The master records all writes in a journal: the binary logs ● Each slave: ● Downloads the journal and saves it locally (IO thread): relay logs ● Executes the relay logs on the local database (SQL thread) ● Could produce binary logs to be itself a master (log-slave-updates) ● Understood replication features: ● Asynchronous ● Single threaded 3
  • 5. Riding the Binlog: Replication’ +---+ | A | +---+ | +------+------+---------------+ | | | | +---+ +---+ +---+ +---+ | B | | C | | D | | E | +---+ +---+ +---+ +---+ | +------+------+ | | | +---+ +---+ +---+ | F | | G | | H | +---+ +---+ +---+ 4
  • 6. Riding the Binlog: Replication’’ ● More understood binlog/replication features: ● Master side binary log filtering ● Binlog_Do_DB / Binlog_Ignore_DB (avoid those in favor of slave side filtering) ● sql_log_bin ● Slave side filtering: ● Replicate_Do_DB / Replicate_Ignore_DB ● Replicate_Do_Table / Replicate_Ignore_Table ● Replicate_Wild_Do_Table / Replicate_Wild_Ignore_Table ● Circular replication ● New innovations in replication land: ● Global Transaction Identifiers (GTIDs) ● Multi-Source and Multi-Threaded Replication (many types) ● Binlog Servers 5
  • 7. Riding: the Binary Logs (on master) > ls –l # Dots (.) in the file sizes are added for readability. [...] -rw-rw---- 1 mysql mysql 537.362.886 Sep 13 10:19 binlog.000878 -rw-rw---- 1 mysql mysql 537.341.120 Sep 13 10:22 binlog.000879 -rw-rw---- 1 mysql mysql 6431.760.382 Sep 13 11:13 binlog.000880 -rw-rw---- 1 mysql mysql 537.394.773 Sep 13 11:26 binlog.000881 -rw-rw---- 1 mysql mysql 537.288.989 Sep 13 11:29 binlog.000882 -rw-rw---- 1 mysql mysql 111.419.262 Sep 13 11:30 binlog.000883 -rw-rw---- 1 mysql mysql 10.411.193 Sep 13 11:30 binlog.000884 -rw-rw---- 1 mysql mysql 537.271.616 Sep 13 11:34 binlog.000885 -rw-rw---- 1 mysql mysql 537.290.232 Sep 13 11:38 binlog.000886 [...] ● Let’s use mysqlbinlog to see what is in those files. 6
  • 8. Riding: the Binary Logs’ mysql plams <<< "CREATE TABLE test1 ( my_pk BIGINT AUTO_INCREMENT, my_bigint BIGINT DEFAULT NULL, my_datetime DATETIME DEFAULT NULL, PRIMARY KEY(my_pk));" # at 217 #150919 12:04:27 server id 1 end_log_pos 428 CRC32 0xebef2e40 Query thread_id=3100 exec_time=0 error_code=0 use `plams` SET TIMESTAMP=1442657067 CREATE TABLE test1 ( my_pk BIGINT AUTO_INCREMENT, my_bigint BIGINT DEFAULT NULL, my_datetime DATETIME DEFAULT NULL, PRIMARY KEY(my_pk)) 7
  • 9. Riding: the Binary Logs’’ mysql plams <<< "INSERT INTO test1(my_pk) VALUES (1);" # (Omitting “SET TIMESTAMP=...”.) # at 428 #150919 12:04:30 server id 1 end_log_pos 509 ... Query ... BEGIN # at 509 #150919 12:04:30 server id 1 end_log_pos 620 ... Query ... INSERT INTO test1(my_pk) VALUES (1) # at 620 #150919 12:04:30 server id 1 end_log_pos 651 ... Xid = ... COMMIT 8
  • 10. Riding: the Binary Logs’’’ # PK (auto_increment) not specified. mysql plams <<< "INSERT INTO test1(my_bigint, my_datetime) VALUES (floor(1024*1024*rand()), now());" # (Omitting BEGIN/COMMIT.) # at 740 / # at 772 / # at 811 #150919 12:04:38 server id 1 end_log_pos 772 ... Intvar SET INSERT_ID=2 #150919 12:04:38 server id 1 end_log_pos 811 ... Rand SET @@RAND_SEED1=80977572, @@RAND_SEED2=154388004 #150919 12:04:38 server id 1 end_log_pos 976 ... Query ... SET TIMESTAMP=1442657078 INSERT INTO test1(my_bigint, my_datetime) VALUES (floor(1024*1024*rand()), now()) 9
  • 11. Riding: the Binary Logs’’’ ’ mysql plams <<< " BEGIN; INSERT INTO test1(my_datetime) VALUES (now()); SELECT sleep(5); INSERT INTO test1(my_datetime) VALUES (now()); COMMIT;" & mysql plams <<< " SELECT sleep(1); INSERT INTO test1(my_datetime) VALUES (now());" 10
  • 12. Riding: the Binary Logs’’’ ’’ # (Omitting BEGIN/COMMIT/“SET TIMESTAMP=...”.) # at 1096 / # at 1128 / SET INSERT_ID=4 #150919 12:05:00 server id 1 end_log_pos 1257 ... Query ... INSERT INTO test1(my_datetime) VALUES (now()) # at 1377 / # at 1409 / SET INSERT_ID=3 #150919 12:04:58 server id 1 end_log_pos 1538 ... Query ... INSERT INTO test1(my_datetime) VALUES (now()) # at 1538 / # at 1570 / SET INSERT_ID=5 #150919 12:05:03 server id 1 end_log_pos 1699 ... Query ... INSERT INTO test1(my_datetime) VALUES (now()) 11
  • 13. Riding: the Binary Logs’’’ ’’’ mysql plams <<< "SET binlog_format = ROW; INSERT INTO test1(my_datetime) VALUES (now());" # (Omitting BEGIN/COMMIT.) # at 1811 #... Table_map: `plams`.`test1` mapped to number 143 # at 1863 #... Write_rows: table id 143 flags: STMT_END_F BINLOG ' VTP9VRMBAAAANAAAAEcHAAAAAI8AAAAAAAEABXBsYW1zAAV0ZXN0MQADCAgSAQAGVr3KSw== VTP9VR4BAAAAMQAAAHgHAAAAAI8AAAAAAAEAAgAD//oGAAAAAAAAAJmXJsFJmHAAYw== 12
  • 14. Riding: the Binary Logs’’’ ’’’ # mysqlbinlog -v # (Omitting BEGIN/COMMIT.) # at 1811 #... Table_map: `plams`.`test1` mapped to number 143 # at 1863 #... Write_rows: table id 143 flags: STMT_END_F BINLOG ' VTP9VRMBAAAANAAAAEcHAAAAAI8AAAAAAAEABXBsYW1zAAV0ZXN0MQADCAgSAQAGVr3KSw== VTP9VR4BAAAAMQAAAHgHAAAAAI8AAAAAAAEAAgAD//oGAAAAAAAAAJmXJsFJmHAAYw== ### INSERT INTO `plams`.`test1` ### SET ### @1=6 ### @2=NULL ### @3='2015-09-19 12:05:09' 13
  • 15. Riding: the Binary Logs’’’ ’’’ # mysqlbinlog -vv # (Omitting BEGIN/COMMIT.) # at 1811 #... Table_map: `plams`.`test1` mapped to number 143 # at 1863 #... Write_rows: table id 143 flags: STMT_END_F BINLOG ' VTP9VRMBAAAANAAAAEcHAAAAAI8AAAAAAAEABXBsYW1zAAV0ZXN0MQADCAgSAQAGVr3KSw== VTP9VR4BAAAAMQAAAHgHAAAAAI8AAAAAAAEAAgAD//oGAAAAAAAAAJmXJsFJmHAAYw== ### INSERT INTO `plams`.`test1` ### SET ### @1=6 /* LONGINT meta=0 nullable=0 is_null=0 */ ### @2=NULL /* LONGINT meta=0 nullable=1 is_null=1 */ ### @3='2015-09-19 12:05:09' /* DATETIME(0) meta=0 nullable=1 is_null=0 */ 14
  • 16. Riding: the Binary Logs’’’ ’’’ ’ ● Binary Logs: Journal for MySQL Replication ● Files with a basename and 6 digit index ● Stream of transactions in commit order ● A transaction is never split in 2 binlog files ● But a transaction is split in many events ● Want to know more: ● Read the documentation ● Or source dive: sql/log_event.{h,cc} 15
  • 17. Riding: some Event Types sql/log_event.h enum Log_event_type { UNKNOWN_EVENT= 0, QUERY_EVENT= 2, STOP_EVENT= 3, ROTATE_EVENT= 4, INTVAR_EVENT= 5, LOAD_EVENT= 6, CREATE_FILE_EVENT= 8, APPEND_BLOCK_EVENT= 9, EXEC_LOAD_EVENT= 10, DELETE_FILE_EVENT= 11, NEW_LOAD_EVENT= 12, RAND_EVENT= 13, USER_VAR_EVENT= 14, 16 FORMAT_DESCRIPTION_EVENT= 15, XID_EVENT= 16, TABLE_MAP_EVENT = 19, INCIDENT_EVENT= 26, HEARTBEAT_LOG_EVENT= 27, IGNORABLE_LOG_EVENT= 28, ROWS_QUERY_LOG_EVENT= 29, WRITE_ROWS_EVENT = 30, UPDATE_ROWS_EVENT = 31, DELETE_ROWS_EVENT = 32, GTID_LOG_EVENT= 33, ANONYMOUS_GTID_LOG_EVENT= 34, PREVIOUS_GTIDS_LOG_EVENT= 35,
  • 18. Riding: the Binlogs on Slaves +---+ +---+ | M | --> | S | +---+ +---+ ● Depends on log-slave-updates (lsu): ● If lsu disabled: no trx from the master in the binlogs of the slave ● else: SQL Thread logs its transactions ● binlogs on a slave != binlogs on the master: ● FLUSH BINARY LOGS ● Restart of mysqld on the master or slave ● RESET MASTER on slave ● Different binlog filenames on master and slave ● … 17
  • 19. Riding: the Binlogs on Slaves’ ● Binlogs on the master: -rw-rw---- 1 mysql mysql 40720631 Sep 19 13:16 binlog.000001 -rw-rw---- 1 mysql mysql 16777476 Sep 19 13:17 binlog.000002 -rw-rw---- 1 mysql mysql 16777476 Sep 19 13:18 binlog.000003 -rw-rw---- 1 mysql mysql 10124412 Sep 19 13:18 binlog.000004 -rw-rw---- 1 mysql mysql 8388820 Sep 19 13:18 binlog.000005 -rw-rw---- 1 mysql mysql 8388820 Sep 19 13:19 binlog.000006 -rw-rw---- 1 mysql mysql 6964108 Sep 19 13:19 binlog.000007 [...] ● And on a slave: -rw-rw---- 1 mysql mysql 67109007 Sep 19 13:21 binlog.000001 -rw-rw---- 1 mysql mysql 67108948 Sep 19 13:22 binlog.000002 -rw-rw---- 1 mysql mysql 52518911 Sep 19 13:22 binlog.000003 -rw-rw---- 1 mysql mysql 45279097 Sep 19 13:30 binlog.000004  The content of the binary logs on slaves is (hopefully) the same as on the master, but the transport is different. 18
  • 20. Riding: the Binlogs on Slaves’’ ● Depends on slave-local transactions (and lsu): ● If lsu disabled: the slave behaves like a master ● The slave has its own transaction/binlog stream ● This stream is independent from the master stream (lsu disabled) ● else: local trx UNION master trx (multiplexing) ● The slave transaction stream merges with the master stream ● Those might be independent, or might depend on each other +---+ +---+ WRITES --> | M | --> | S | +---+ +---+ ^ | +--- WRITES 19
  • 21. Riding: the Binlogs on Slaves’’’ ● If lsu enabled, also depends on replication filters: ● If no filter: binlogs on slave contain local and master trx ● else: depends of MySQL 5.6 GTIDs: ● Without 5.6 GTIDs, filtered transaction are skipped (exclusion) ● With 5.6 GTIDs: an empty transaction is logged (mutation) (Transactions can be filtered fully or partially : also mutation) +---+ +---+ | M | --> | S | +---+ +---+ 20
  • 22. Riding: the Binlogs on Slaves’’’ ’ ● Circular-replication (needs log-slave-updates): ● Combination of slave local transactions and filters ● local trx UNION (master trx SUB “same server_id” trx) (multiplexing with exclusion) +---+ +---+ | M1| ----> | M2| +---+ +---+ ^ | | +---+ | +-- | M3| <-+ +---+ 21
  • 23. Riding: the Binlogs on Slaves’’’ ’’ ● Depends on Multi-Source Replication: ● If lsu disabled: only slave local transactions ● else: local trx UNION M1 trx UNION M2 trx … (multiplexing) (Identically configured slave might multiplex in different ways) (Filters can be added to multi-source  mutation) +---+ +---+ | M1| | M2| +---+ +---+ | | +---+-----+ +-----+---+ | | | | +---+ +-+------+ | +---+ | S1| | +----|-+-+ | S2| +---+ | | | | +---+ +---+ +---+ | X1| | X2| +---+ +---+ 22
  • 24. Riding: the Binlogs on Slaves’’’ ’’’ ● Depends on Multi-Threaded Replication (MySQL 5.6 schema based): ● If lsu disabled: only slave local transactions ● else: reordering of transactions (morphing) ● On the master, some transactions in 3 schemas (A, B, C): ● Order in the Binary Logs: A1, A2, B1, B2, C1, A3, C2, B3, C3 ● On the slave, transactions in different schema run in //: “A1,A2,A3” in // with “B1,B2,B3” in // with “C1,C2,C3” ● One possible order: A1, B1, C1, A2, B2, C2, A3, B3, C3 ● Another: A1, C1, A2, C2, A3, C3, B1, B2, B3 (if B1 is big) ● Many others… 23
  • 25. Riding: the Binlogs on Slaves’’’ ’’’ ’ ● Depends on MySQL 5.7 Logical Clock Parallel Replication: ● If lsu disabled: only slave local transactions ● else if slave_preserve_commit_order = OFF (default): reordering of transactions (morphing) ● else (slave_preserve_commit_order = ON) modification of parallelism information (still morphing) 24
  • 26. Riding: the Binlogs on Slaves’’’ ’’’ ’’ ● Four transactions on X and Y: +---+ | X | +---+ | V +---+ | Y | +---+  Transaction order in the binary logs of Y: (without slave_preserve_commit_order)  T3, T4, T2, T1 25 On Y: ----Time----> B-------C B-----C B---C B----C On X: ----Time----> T1 B-------C T2 B-----C T3 B---C T4 B----C On Y (with slave_preserve_commit_order): ----Time----> B-------C B-----. C B---. . C B---- . C
  • 27. Riding: the Binlogs on Slaves’’’ ’’’ ’’’ ● Four other transactions on X and Y: +---+ | X | +---+ | V +---+ | Y | +---+ | V +---+ | Z | +---+  IM (Y) might stall the parallel replication pipeline  Replicating with IM will slow down parallel replication 26 On Y: ----Time----> B---C B---C B-------C B-------C On Z: ----Time---------> B---C B---C B-------C B-------C On X: ----Time----> T1 B---C T2 B---C T3 B-------C T4 B-------C
  • 28. Riding: the Binlogs on Slaves’’’ ’’’ ’’’ ’ ● Let’s try to summarise: ● Multiplexing: ● Local transactions + log-slave-updates ● Circular Replication (needs log-slave-updates) ● Multi-Source + log-slave-updates ● Morphing: ● All types of Multi-Threaded replication + log-slave-updates ● Mutation: ● Filters + MySQL 5.6 GTIDs + log-slave-updates ● See the pattern… ● log-slave-updates 27
  • 29. Riding the Binlog: why lsu ? ● Lsu is needed for: ● master promotion with GTIDs ● fan-out ● circular replication ● external trigger ● converting SBR to RBR ● new version/feature testing ● multiplexing with a side effect 28
  • 30. Riding the Binlog: lsu with GTIDs ● After the failure of M, new master promotion needs levelling the remaining slaves +---+ | M | +---+ | bl_M +-------+-------+ | | | +---+ +---+ +---+ | S1| | S2| | S3| +---+ +---+ +---+ bl_S1 bl_S2 bl_S3 29 ● If S2 is the most up to date slave: ● bl_S2 will be used to level S1 and S3 ● Ok if bl_S2 is a different transport of bl_M ● Ok-ish if bl_S2 is a simple morphing of bl_M ● NOT-Ok if bl_S2 is a mutation of bl_M  If you must replicate using lsu put Intermediate Master between the master and mutation (filtering) slave (or you might loose those slave during promotion)  Or use Binlog Servers
  • 31. Riding the Binlog: lsu for Fan-Out ● Remote site or too many slaves: needs a fan-out solution +---+ | M | +---+ | +-- ... --+ | | +---+ +---+ | M1| | Mx| +---+ +---+ | | +-- ... +-- ... --+ | | | +---+ +---+ +---+ | S1| | Z1| | Zi| +---+ +---+ +---+ 30 ● Intermediate Masters slow down replication (including parallel replication) ● Their failure needs to be managed ● Rogue transactions need to be managed ● And we still have the risks/problems associated with morphing and mutations  IMs come with many drawbacks  Avoiding them might be better  Binlog Servers allow that
  • 32. Riding the Binlog: Circular Replication ● Circular replication is a form of multiplexing +---+ +---+ | M1| ----> | M2| +---+ +---+ ^ | | +---+ | +-- | M3| <-+ +---+ ● But Multi-Source replication is also multiplexing  Replace Circular replication by Multi-Source ● High Availability is tricky ● But it was not simple either with Circular Replication ● And it is very simple with Binlog Servers 31
  • 33. Riding the Binlog: Circular Replication’ 32 ● Replace the following: +---+ +---+ |S11| <---+ +---+ +---+ +---> |S21| +---+ +- | M1| ----> | M2| -+ +---+ +---+ | +-+-+ +-+-+ | +---+ |S12| <-+ ^ | +-> |S22| +---+ | | +---+ | | +---+ +---+ | +-- | M3| <-+ | +---+ |S13| <--+ +-+-+ +--> |S23| +---+ | +---+ /------+------ +---+ V +---+ |S31| +---+ |S33| +---+ |S32| +---+ +---+
  • 34. Riding the Binlog: Circular Replication’’ 33 ● By this: +---+ +---+ +---+ | M1| | M2| | M3| +---+ +---+ +---+ V^^ |^^ |^^ +------+----+||-----|+|-----|+|----+------+ | | || V | | | | | |+-----|+----+|-----+-|-----|-+----|+-----|+ || || | | V || || ||+----||+----+-------+-----+------||+----||+ VVV VVV VVV VVV +---+ +---+ +---+ +---+ | S1| | S2| ... |...| | Sn| +---+ +---+ +---+ +---+
  • 35. Riding the Binlog: Binlog Server ● Binlog Server (BLS): is a daemon that: ● Downloads the binary logs from the master ● Saves them identically as on the master ● Serves them to slaves ● A or X are the same for B and C: ● By design, the binary logs served by A and X are the same 34 +---+ / | A | ---> / X +---+ ----- | | +---+ +---+ | B | | C | +---+ +---+
  • 36. Riding the Binlog: BLS – Fan-out ● Replace Intermediate Master by Binlog Servers: +---+ | M | +---+ | +----------------+------ ... ------+ | | | / / / / I1 / I2 / Im ----- ----- ----- | | | +------+ ... +--- ... +--- ... ---+ | | | | | +---+ +---+ +---+ +---+ +---+ | S1| | S2| | Si| | Sj| | Sn| +---+ +---+ +---+ +---+ +---+ ● If BLS fails, repoint slaves to other BLSs (easy by design) 35
  • 37. Riding the Binlog: BLS – HA ● Distributed Binlog Serving Service (DBSS): +---+ | M | +---+ | +----+----------------------------------------------------+ | | +----+-------+-----------+-------+-----------+-------+----+ | | | | | | +---+ +---+ +---+ +---+ +---+ +---+ | S1|...| Sn| | T1|...| Tm| | U1|...| Uo| +---+ +---+ +---+ +---+ +---+ +---+ 36
  • 38. Riding the Binlog: BLS – HA’ ● Zoom in DBSS: | +----|---------------------------------------------------------+ | | | | +----------------------+---------------------+ | | | | | | | / / / | | / --->/ / --->/ / --->/ | | ----- / ----- / ----- / | | | ----- | ----- | ----- | +----|-------|--------------|-------|-------------|-------|----+ | | | | | | 37
  • 39. Riding the Binlog: BLS – HA’’ 38 --/- +---+ | X | | T1| -/-- +---+ | +------------------------+--------------------------------+ | | +----+-------+-----------+-------+-----------+-------+----+ | | | | | | +---+ +---+ +---+ +---+ +---+ +---+ | S1|...| Sn| | T2|...| Tm| | U1|...| Uo| +---+ +---+ +---+ +---+ +---+ +---+
  • 40. Riding the Binlog: why lsu ?’ ● Lsu is needed for: ● master promotion with GTIDs: use with care or Binlog Servers ● fan-out: Binlog Servers ● circular replication: replaced by Multi-Source + Binlog Servers ● external trigger ● converting SBR to RBR ● new version/feature testing ● multiplexing with a side effect 39
  • 41. Riding the Binlog: external trigger ● If we need to trigger an event after commit on a slave, log-slave-updates is a good solution +---+ | M | +---+ | bl_M | +---+ | S | +---+ bl_S | +-> Memcache 40 ● An example is cache invalidation ● But morphing and mutation is still there ● Remember above when tempted to use the slave binlogs for other use-cases (HA) ● Cache invalidation does not need full binlogs  A custom binary log format dedicated to that might be useful
  • 42. Riding the Binlog: SBR to RBR ● When a master is SBR and you need Row-Based Events ● log-slave-updates is currently your only solution ● But consuming Row-Based Events on a slave introduces morphing, mutation and a single point of failure ● Also, migrating from SBR to RBR is complex ● Wouldn’t it be great if: ● the master logs in both SBR and RBR format, ● And each slave chooses to follow the SBR or RBR stream.  I suggest a new binary log format: multiplexed ● (with the corresponding configuration on slaves) 41
  • 43. Riding the Binlog: why lsu ?’’ ● Lsu is needed for: ● master promotion with GTIDs: use with care or Binlog Servers ● fan-out: Binlog Server ● circular replication: replaced by Multi-Source + Binlog Servers ● external trigger (cache invalidation): OK ● converting SBR to RBR: new binary log format ● new version/feature testing ● multiplexing with a side effect 42
  • 44. Riding the Binlog: why lsu ?’’ ● Lsu is needed for: ● master promotion with GTIDs: use with care or Binlog Servers ● fan-out: Binlog Server ● circular replication: replaced by Multi-Source + Binlog Servers ● external trigger (cache invalidation): OK ● converting SBR to RBR: new binary log format ● new version/feature testing: ok, not really production ● multiplexing with a side effect 43
  • 45. Riding the Binlog: why lsu ?’’’ ● Lsu is needed for: ● master promotion with GTIDs: use with care or Binlog Servers ● fan-out: Binlog Server ● circular replication: replaced by Multi-Source + Binlog Servers ● external trigger (cache invalidation): OK ● converting SBR to RBR: new binary log format ● new version/feature testing: ok, not really production ● multiplexing with a side effect: very complex use-case, not covered in the talk 44
  • 46. Riding the Binlog: Conclusion ● The Binary logs are a stream of transactions ● Enabling log-slave-updates makes this stream evolves ● Those evolutions are complex ● Tips to manage those evolutions in combination with HA: ● A filtering slave should replicate through an intermediate master ● A slave with local transaction should also replicate through an IM ● Avoid using log-slave-updates for replication (use Binlog Servers) ● Learn more tomorrow: Binlog Server at Booking.com ● Wed. 23 September, 2:10PM - 3:00PM @ Matterhorn 1 ● https://www.percona.com/live/europe-amsterdam- 2015/sessions/binlog-servers-bookingcom 45
  • 47. Riding: the Binlog Function on Slaves 46 Relay Logs Binary Logs Configuration • filters (empty trx w GTID) • slave-parallel-workers • slave-preserve- commit-order • binlog_format Content of the Database Local Transactions Relay Logs2 Relay Logs3 Human • skipping transactions • modifying configuration • restarting MySQL • doing other mistakes Hardware • # and speed of CPU • amount of RAM • speed of storage (RAID rebuild ?) • network (congestion ?) Load on the system (virtualisation ?)State of the Buffer Pool log-slave-updates ??? Others ???
  • 48. Riding: the Binlog Function on Slaves 47 Binary Logs Local Transactions Without log-slave-updates
  • 49. Riding the Binlog: Links Binlog Servers: ● http://blog.booking.com/mysql_slave_scaling_and_more.html ● http://blog.booking.com/abstracting_binlog_servers_and_mysql_maste r_promotion_wo_reconfiguring_slaves.html IM Morphing Loosing Parallelism Information: ● http://blog.booking.com/better_parallel_replication_for_mysql.html ● (http://blog.booking.com/evaluating_mysql_parallel_replication_2- slave_group_commit.html) Others ● https://www.percona.com/blog/2009/05/14/why-mysqls-binlog-do-db- option-is-dangerous/ 48