Tutorial
This tutorial describes how to run an example that demonstrates one possible use of the user-defined extensions for replication by providing detailed logging of the replication subsystem.
To exercise replication to monitor its behavior, compile ctrepluser.c
with #define REPLUSER_LOGGING
uncommented. This will enable code that calls a function to log a message to the file ctrepluser.log
each time one of the callback functions is called. The sample code also tracks the number of calls made to each callback function using the #define REPLUSER_LOGGING
logic discussed in replication logging.
Note
This is only one simple use of the callback extension. By reviewing the code in ctrepluser.c,
you will be able to explore many alternate uses for this technology.
To begin the tutorial, we will execute some scripts to build the data on the source server and target server. With data on both servers, we can insert data and delete data in the table we built. We will connect to the source and watch the Replication Agent replicating data to the target server.
Set the keyword in the
ctsrvr.cfg
file on the source server to tell the source server to replicate all its files:Note
This configuration only takes effect during server initialization.
REPLICATE *.*
Start/restart the source server.
Start the target server if it is not already running.
Note
Both servers must be running.
Execute the
ctreplagent
command to start replication.Note
Once the Replication Agent is started, you can now run the scripts to insert and delete data.
# ./ctreplagent
Ensure your screen appears like Figure 2, “Callback tutorial”, if not please check your compilation.
Figure 2. Callback tutorial
Run the following SQL command using FairCom DB SQL Explorer, or the ISQL command-line utility to create data on the source and target servers.
CREATE TABLE custmast (cm_custnumb CHAR(4), cm_custzipc CHAR(9), cm_custstat CHAR(2), cm_custrtng CHAR(1), cm_custname VARCHAR(47), cm_custaddr VARCHAR(47), cm_custcity VARCHAR(47)); COMMIT;
Observe the
Create.bat
batch file that uses ISQL to execute a script.Note
The
Create.bat
file uses ISQL to execute a script, create.sql, that contains the commands shown in Step 1.Figure 3.Create.bat
batch file
Insert some sample data into the database to be replicated.
INSERT INTO custmast VALUES ('1000','92867','CA','1','Bryan Williams','2999 Regency','Orange'); INSERT INTO custmast VALUES ('1001','61434','CT','1','Michael Jordan','13 Main','Harford'); INSERT INTO custmast VALUES ('1002','73677','GA','1','Joshua Brown','4356 Cambridge','Atlanta'); INSERT INTO custmast VALUES ('1003','10034','MO','1','Keyon Dooling','19771 Park Avenue','Columbia'); COMMIT;
Observe ISQL running a SQL script that executes the commands in Insert data.
Figure 4. ISQL running a SQL script
Delete the data to test replication.
DELETE FROM custmast; COMMIT;
Observe a
Delete.bat
file that deletes using ISQL by executing adelete.sql
script that contains the commands in Step 1.Figure 5.Delete.bat
file
Check the results of the executed callback functions.
Observe the sequence of events seen while inserting data.
Figure 6. Inserting data sequence