                ===========================================
                         MySQL Replication Servers
                     Lars Thalmann and Johan Andersson
                              2003 MySQL AB
                ===========================================
 
-------------------------------------------------------------------------------

                PRIMARY SYSTEM               STANDBY SYSTEM 
              REPLICATION SERVER           REPLICATION SERVER
             (PS or SOURCE SYSTEM)     (SS or DESTINATION SYSTEM)
             +------------------+     +-------------------------+
             |     RepMain      |     |    RepMain [Requests]   |
             |                  |     +-------------------------+
             |                  |     |   Requestor [Executes]  |
             +------------------+     +-------------------------+
      PS --- | ExtNDB | TransPS | --- |   TransSS  |  AppNDB    | --- SS
             +------------------+     +-------------------------+
                (GCIContainer)               (GCIContainer)
                                               (RepState)

                      Figure 1: Replication Server Threads 

Component List
--------------
RepMain
  Main thread that runs command-line interpreter [Requests]

Requestor
  Thread that runs RepState::execute [Executes]

ExtNDB
  Extracts transaction epochs from NDB Cluster

TransPS, TransSS
  Transfers information (control and epoch buffers) between 
  Replication Servers.

AppNDB
  Applies transaction epochs to NDB Cluster

-------------------------------------------------------------------------------

               RepState Control
                    Object
             +------------------+    
             |     RepState     |    
             |    [Requests]    |    
             |    [Executes]    |    
             +------------------+    
             |  RepStateRequest | --- ExtSender
             +------------------+ 

                      Figure 2: RepState Object


The RepState object is shared by all components.


-------------------------------------------------------------------------------

Dependent Directories
---------------------
rep/adapters    Appliers and Extractors
  All code dependent on the database system

rep/transfer
  Depends on NDB transporters

rep/state
  Shared resources for all components

Independent Directories
-----------------------
rep/storage     Storage of epochs 
  Should not depend on any transporters/NDB specific

rep/repstate
  Should only have a reference to an ExtSender for the external PS REP node


-------------------------------------------------------------------------------

Replication Teminology
----------------------
GLOBAL CHECKPOINT <global checkpoint id - gci>
A global checkpoint is a point in time when all database server
are synchronized.

NODE
A database server with information.

NODE GROUP <node group id>
A set of database servers, all storing the same information.

SUBSCRIPTION <subscription id>.
A "subscription" is a collection of services that a source system 
provides.  The main to services belonging to a subscription are 
"log" and "scan".  Log provides the replication servers with 
log entries (epochs) and scan provides the replication servers
with scanned data (also stored in epochs).

EPOCH <subscription id, gci>
An "epoch" is a log of all database changes between two time points.
(An epoch can have redundant log entries.)  An epoch is named by the
number of the time slice between the two time points.

EPOCH BUFFER <subscription id, gci, node group id>
An "epoch buffer" is a part of the log belonging to an epoch.  An
epoch buffer does not contain any redundancy.  

Two epoch buffers with the same subscription id and gci can be
"complements" or "duplicates" to each other.  If they are complements,
they store different information, if they are duplicates then they
store equivalent information (the information need not be identical,
but it is equivalent for the purpose of restoring the original
information).  If they are duplicates then they have the same name,
i.e. same subscription id, gci, and node group id.

CHANNEL <subscription id>
A "channel" is a collection of epoch buffers belonging to
a specific subscription.  (The channel can exist before it is 
assigned to a subscription.)

SUBSCRIPTION CONSISTENT
A database is "subscription consistent" or "consistent with respect
to a subscription" if ...

Architectural Terminology
-------------------------
ADAPTER
An "adapter" is either an applier or an extractor.

APPLIER 
An "applier" is a a collection of threads in the replication server
that applies epochs to a destination database system.

EXTRACTOR
An "extractor" is a collection of theads in the replication server
that receives epochs from a source database system.

TRANSFER COMPONENT 
A "transfer component" is a thread in the replication server that is
responsible for the connection with another replication server.

REQUESTOR 
A thread in the replication server that controls replication.
