WL#6972: Collect GTIDs to include in the protocol's OK packet

Affects: Server-5.7   —   Status: Complete

EXECUTIVE SUMMARY
=================

This worklog implements a mechanism to collect the necessary set of
GTIDs to be sent over the wire in the response packet. 

DETAILS
=======

This worklog is a stepping stone towards implementing session consistency
throughout a MySQL based replicated system.  It is built on top of the
GTIDs infrastructure.

There are three levels :

  L1. SESSION_CONSISTENCY_BEST_EFFORT

      No session consistency guarantees. The current situation. No
      changes required.

  L2. SESSION_CONSISTENCY_READ_OWN_WRITES

      If an application, A, issues T1 on S1 (master) and then issues a
      read only or read write transaction T2 on S2 (slave), then T2
      will be executed only after S2 has replayed T1 (i.e., through 
      replication).

      As such, it is said that the application will always read its
      own writes, regardless of the server where these reads are
      issued.

  L3. SESSION_CONSISTENCY_READ_ALL_WRITES

      Assume an application, A, that issues the read-write transaction 
      T1 on S1 (master) and then commits. Later, A issues another 
      read-write transaction T2 on S1 and commits it also. Again, 
      later, through a different connection, A issues a read only 
      transaction T3.

      If A later goes to S2 (slave) and issues a read only transaction,
      T4, then the connector will ensure that T4 will only be set to
      executed after T1, T2 have been replicated and applied on S2.

The decision on when and for which transactions to wait, will be done
by leveraging the GTID information available and that will be exposed
by this worklog. The connector will make the decision whether to wait
or not. The server will provide the connector with sufficient knowledge
(gtid set) for the it to make the decision.

CONSISTENCY LEVELS CONFIGURATION
--------------------------------

Three levels of consistency:

  - SESSION_CONSISTENCY_BEST_EFFORT
  - SESSION_CONSISTENCY_READ_OWN_WRITES
  - SESSION_CONSISTENCY_READ_ALL_WRITES

These require that the server provides different information on
the set of GTIDs that have been seen and/or introduced by the
most recently executed statement.

The server exports an interface to control which GTIDs to track. This
interface builds on the session track GTIDs and is further detailed
later in the Low-Level Description section. The new GTID tracker is
controlled by the dynamic variable @@SESSION_TRACK_GTIDS, which can be
set to one of the following values:

 - OFF
 - OWN_GTID
 - ALL_GTIDS

The mapping to the consistency levels is the following:

 SESSION_CONSISTENCY_BEST_EFFORT     -> SESSION_TRACK_GTIDS= OFF
 SESSION_CONSISTENCY_READ_OWN_WRITES -> SESSION_TRACK_GTIDS= OWN_GTID
 SESSION_CONSISTENCY_READ_ALL_WRITES -> SESSION_TRACK_GTIDS= ALL_GTIDS

Finally the specs mandate that the following information is returned
in the OK packet:

 |---------------------+-------+---------------+---------------------|
 | session_track_gtids | OFF   | OWN_GTID      | ALL_GTIDS           |
 |          vs         |       |               |                     |
 |       scenario      |       |               |                     |
 |---------------------+-------+---------------+---------------------|
 | Single RW trx       | Empty | Its own GTID  | All GTIDs or delta* |
 | Single RO trx       | Empty | Empty         | All GTIDs or delta* |
 | Multiple RW trx     | Empty | Its own GTIDs | All GTIDs or delta* |
 | Multiple RO trx     | Empty | Empty         | All GTIDs or delta* |
 | RW and RO trx       | Empty | Its own GTIDs | All GTIDs or delta* |
 |---------------------+-------+---------------+---------------------|
 (* We go with "all gtids" to begin with. Later we can optimize.)