WL#6813: MTS: ordered commits (sequential consistency)

Affects: Server-5.7   —   Status: Complete

EXECUTIVE SUMMARY :
===================
This worklog will ensure that the commits by slave applier threads running in 
parallel will be done in the same order as on the master. This also means that 
the slave will never externalize a database state which was never externalized 
by the master. This is a requirement when the applications reading from the
slave MUST observe the same set of states that existed on the master due to some 
application enforced constraint. This has become a necessity after WL#6314 which 
enables multiple transactions to be executed in parallel by the slave threads, 
few of which may be modifying a single database.

Motivation
-----------

  1. Replication stream is easier to understand with MTS;
  2. Easier to troubleshoot and debug.This is a requirement or the applications 
that need to go through exact same execution history as the master
  3. Speculation: will not break consistency from the application
     point of view, the data is always consistent even without this feature.


FULL DESCRIPTION
=================
A slave server can be configured to execute transactions in parallel to improve 
performance. Transactions that execute in parallel can be committed out of 
order. Thus, when the replication thread is executing transactions, the slave 
database can be in a state that never existed on the master.

This does not pose problems when the slave is only used for redundancy/fail-
over,since in such cases application 'work' on final stage of the slave and are 
indifferent to the execution history followed by the slave to reach the point. 
However, if the slave is used for read scale-out, clients/applications may 
depend upon some intermediate state of the slave.

However, we have implemented WL#6314, where transactions that have same 
commit parent(commit parent=> last committed transaction)  can execute in 
parallel. Now the consistency is as follows:

- If clients C1 and C2 execute transactions T1 and T2 on master, and the server
  sends ACK for C1 before C2 sends COMMIT for T2, then C1 and C2 will be in
  order on slave.
- If, on the other hand, C1 and C2 both send COMMIT before any one of them
  receive an ACK, then T1 and T2 may be committed in any order on the slave.
  Moreover, T1 and T2 can then be externalized in different orders on master
  and slave. So if client C3 reads the database state on master, and client C4
  reads the database state on the slave, then C3 and C4 may see T1 and T2
  be committed in different orders.

This worklog adds an option to serialize commits for parallel transactions: 
transactions can begin to execute in parallel, but the executing thread will 
hang before the commit, until all previous transactions are committed. In case 
of any application level constraint requiring exactly the same states as the 
master, the slave can be configured for the same.   

This will solve the problem for transactional storage engines. For non-
transactional storage engines it makes no difference, but that's probably 
impossible to fix.