binary_and_relay_logs.txt (2030B)
What are the key differences between MariaDB's binlog and relay log? The master writes all transactions into its binary log. This is usually a sequential and very lightweight activity. The replica server reads the transactions from masters binary log and writes them to its relay log. Only after that the replica executes the statements from its relay log. From the POV of Master: Whenever a replica server connects to a master, the master creates a new thread for the connection (similar to any other server client) and then it does whatever the replica user asks. Most of that is going to be a request a feed of events from the master's binary log and to get notified about newly written events to the master's binary log. Replica servers that are up to date will mostly be reading events that are still cached in OS cache on the master server, so usually, there shouldn't be too much physical disk reads on the master server in order to feed binary log events to the replica.. The most common exception is when reconnecting a replica server that may have been down for a couple of hours for one reason or another as it will start with reading binary logs that were written hours ago, which the master may no longer have cached. From the POV of the Replica: The I/O thread process connects to the designated master, reads its binary log events as they come in and just copies them over to a local log file called relay log. This leads us to seeing a second process, the The second process, the SQL thread, which reads events from the relay log stored locally on the replication slave (the file that was written by I/O thread) and then applies them as fast as possible. Basically, the relay log is just a local file buffering the master's binlog contents. Separately, the SQL thread reads the relay log and executes the events to replay the master's changes. This two-step model (I/O thread + SQL thread) decouples network transfer from SQL execution, helping replicas survive short disconnects from the master server.