3-Binlog Network Stream

You are viewing an old version of this article. View the current version here.

The binary log events, stored into a binary log file can be sent over network in order
to replicate data changes from Master server (where data changes are written in binary logs) to
Slave servers which will apply data changes into their own databases.

The MariaDB Slave replication protocol consists in:

  • registration phase to master
  • events receiving (Master sending data when changes are available).

Note: This section is related to events sending only.

Binlog Network streams are requested with COM_BINLOG_DUMP and each Binlog Event is prepended with a status byte.
The data sent over network is then MariaDB network protocol (4 bytes) + 1 byte status flag + <n bytes> event data.

MariaDB network protocol 4 bytes are:

  • uint<3> packet length (The sent binlog event can be up to 2^24 - 1 - 1 data bytes)
  • uint<1> packet sequence byte<1>(0 to 255)

Replication protocol status byte:

  • uint<1> OK (0) or ERR (ff) or End of File, EOF, (fe)

Note: due to the 1 byte status flag the effective data paylod is event_size + 1
This means than an event of exact 16Mbytes (2 ^ 24 - 1) cannot be sent in one transmission: it requires 2 packets instead.

packet #n:   3 bytes length + sequence + status + [event_header + (event data - 1)]
packet #n+1: 3 bytes length + sequence + last byte of the event data.

Please note that the remaining bytes of a large event transmission are alway sent without status flag and binlog event header: just network packet header + data.

Example of an Event transmission HEARTBEAT_LOG_EVENT

T 127.0.0.1:8808 -> 127.0.0.1:57157 [AP]
  23 00 00 04 00 00 00 00    00 1b 67 2b 00 00 22 00    '.........g+..&.
  00 00 ed 01 00 00 20 00    66 6f 6f 2d 62 69 6e 2e    ...... .log-bin.
  31 30 30 30 31 33 39                                  1000139

Network Replication protocol, 5 bytes

  • packet size [3] = 23 00 00 => 00 00 23 => 35 (ok byte + event size)
  • pkt sequence [1] = 04
  • OK indicator [1] = 0 (OK)

Heartbeat event

  • Header, 19 bytes
  • Content, string<EOF>

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.