WL#7374: Performance schema tables to monitor replication lags and queue

Affects: Server-8.0   —   Status: Complete

MOTIVATION
----------

This worklog will add fields to the replication P_S tables to help inspect
internal execution of the server at runtime better.

OBJECTIVE
---------

The current concept of SECONDS BEHIND MASTER is buggy and not meeting the
present needs. This worklog introduces an alternative way to monitor
replication lags using a number of fields that will be added to the
replication P_S tables. These fields will help detect lags at various points
in the replication stream like lag owing to IO Thread, lag in the job of
scheduling by the coordinator thread and lag in execution by a worker thread.

GOALS
-----

The main objective of this task is to show replication stats in the form of P_S
tables.

Current approach of measuring replication delay, Seconds_Behind_Master(SBM)
field of SHOW SLAVE STATUS, is not matching the present needs and, in some
scenarios, is not working properly. This worklog aims at showing replication
delays in more reliable and well defined fields.

A new implementation to show replication delays will match the following
requirements:

  1. There should be a clear distinction between the server from which
     a transaction originates from and the path through it is received on
     slave.
     original master: server on which the transaction is created.
     immediate master (the one used on CHANGE MASTER): the connection
     through which transactions arrive, and it may or not be the
     originating master.

  2. For connectivity problems we only need to monitor how often transactions
     arrive to slave, monitor local delays between deliveries, and not
     rely on transactions' original timestamps.

  3. Complex stats like replication hop delay or replication topology
     finder should be provided by utilities.