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 replica servers which apply data changes to their own databases.

The MariaDB replica replication protocol consists of:

  • A registration phase to master;

  • Events receiving (the master sending data when changes are available).

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 + 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).

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.

The remaining bytes of a large event transmission are always sent without a status flag and binlog event header, but rather just as 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).

  • Header, 19 bytes.

  • Content, string.

This page is licensed: CC BY-SA / Gnu FDL

Last updated

Was this helpful?