3-Binlog Network Stream
The binary log events stored in a binary log file can be sent over the network in order to replicate data changes from the 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 of:
- 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:
Replication protocol status byte:
Note: due to the 1 byte status flag the effective data payload 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 always sent without a status flag and binlog event header: just network packet header + data.
Example of an Event Transmission HEARTBEAT_LOG_EVENT
Network Replication Protocol, 5 Bytes
- packet size  = 23 00 00 => 00 00 23 => 35 (ok byte + event size)
- pkt sequence  = 04
- OK indicator  = 0 (OK)
- Header, 19 bytes
- Content, string<EOF>