The Capture program uses some of the replication control tables
to indicate what changes have been made to the source database, and the Apply
program uses these control-table values to detect what needs to be copied
to the target database.
The Capture program does not capture any information until
the Apply program signals it to do so, and the Apply program does not signal
the Capture program to start capturing changes until you define a replication
source and associated subscription sets.
The following lists describe how the Apply and Capture programs communicate
in a typical replication scenario to ensure data integrity:
- Capturing data from a source database
- The Capture program reads the IBMSNAP_REGISTER table during startup to
identify those registered replication sources for which it must capture changes.
Having done so, it holds their registration information in memory.
- The Capture program reads the DB2® log or journal continuously to detect
change records (INSERT, UPDATE, and DELETE) for registered source tables or
views. It also detects inserts to the IBMSNAP_SIGNAL table in order to pick
up signal actions that have been initialized by the Apply program or a user.
When the Apply program inserts a CAPSTART signal in the IBMSNAP_SIGNAL table
and the Capture program detects the committed signal, the Capture program
initializes the registration and starts capturing changes for the associated
source.
- Once the Capture program has started capturing changes for a registered
source, the program writes one row (or two rows if you specified that updates
should be saved as DELETE and INSERT statements) to the CD table for each
committed change that it finds in the DB2 log or journal. The Capture program
keeps uncommitted changes in memory until the changes are committed or aborted.
Each registered replication source that is not an external CCD table has an
associated CD table.
- At each commit interval, the Capture program commits the data that it
has written to the CD and UOW tables, and also updates the IBMSNAP_REGISTER
table to flag which CD tables have new committed changes.
- Applying data to a target database
- For all newly defined subscription sets, the Apply program first signals
the Capture program to start capturing changes. Then, a full refresh is performed
for each member of the set (unless it is not a complete target table).
- When any subscription set is eligible for replication, the Apply program
checks the IBMSNAP_REGISTER table to determine whether there are changes that
need to be replicated.
- The Apply program copies any changes from the CD table to the target table.
- The Apply program updates the IBMSNAP_SUBS_SET table to record how much
data the Apply program copied for each subscription set.
- The Apply program updates the IBMSNAP_PRUNE_SET table with a value that
indicates the point to which it has read changes from the CD table.
- Pruning the CD tables
- When the Capture program prunes the CD tables, it uses the information
located in the IBMSNAP_PRUNE_SET table to determine which changes were applied,
and deletes those changes already replicated from the CD table.