Simple Replication Agent tutorial

Simple tutorial to replicate data between two FairCom servers running on the same computer

This tutorial sets up an unmanaged replication agent (for FairCom DB V12 (released in 2020) or newer) with both the Source and Target FairCom DB instances residing on the same machine. This example highlights a common use case in which the Replication Agent runs within the Target instance to pull transaction changes from the Source instance. This places the more time-consuming insert operations on the Target instance, where they are most efficient. Note that this tutorial also works for FairCom RTG V4 or newer. It is safe to replace FairCom DB references with FairCom RTG. 

  1. Install a Source (primary) server environment. This is the <faircom>\server directory of your installed FairCom software.
  2. Create a secondary server environment called Target. Create a <faircom>\target directory and copy the following folders and their contents from the source <faircom> directory into the <faircom>\target directory you just created.
    1. config
    2. data
    3. server
    4. tranlogs
  3. Configure the Source server by adding the following keyword to the Source server <faircom>\config\ctsrvr.cfg file:
    REPL_NODEID 10.0.0.1

REPL_NODEID is not the IP address of the running machine. It is just an ID that the connecting replication agents will use to uniquely identify the server. Leave it unchanged for this tutorial.

  1. Configure the Target server to make the FairCom ISAM and SQL server communication ports unique (this is needed so we can execute both the Source and Target server instances on the same computer) and enable the replication agent. 
  • In <faircom>\target\config\ctsrvr.cfg, change SERVER_NAME FAIRCOMS to SERVER_NAME FAIRCOMT
  • In <faircom>\target\config\ctsrvr.cfg, change ;SQL_PORT 6597 to SQL_PORT 6598
  • Add this line to <faircom>\target\config\ctsrvr.cfg (this is needed for replication): REPL_NODEID 10.0.0.2
  • In <faircom>\target\config\services.json, change
"serviceName": "https8443",
"description": "Port 8443 using TLS-secured HTTPS protocol for REST …	
"port": 8443,

To: 

"serviceName": "https8444",
"description": "Port 8444 using TLS-secured HTTPS protocol for REST …	
"port": 8444,
  • Set the Target ctagent in <faircom>\target\config\services.json to true (this is needed for replication):
"serviceName": "ctagent",
"serviceLibrary": "./agent/ctagent.dll",
"enabled": false

To: 

"serviceName": "ctagent",
"serviceLibrary": "./agent/ctagent.dll",
"enabled": true
  • Copy the contents of the config/replication/ctagent.cfg file (a prebuilt example file that enables manual replication mode) and paste it over the config/ctagent.cfg file to enable manual replication quickly. This is currently the only replication mode supported. Make sure to remove the lines containing agent2 and agent3 from the config/replication/ctagent.json file.
  • In <faircom>\target\config\replication\ctreplagent1.cfg, change Target:
target_server FAIRCOMS@localhost
source_server FAIRCOMS@SourceIP

To:

target_server FAIRCOMT@localhost
target_nodeid 10.0.0.2
source_server FAIRCOMS@localhost
source_nodeid 10.0.0.1

Note: the target_nodeid and source_nodeid are needed for parallel apply support, which is on by default. 

  1. In <faircom>\target\config\replication\filter1.xml, configure Target to be sure you have selected files to replicate. For example set to: 

       <file status="include">.\ctreeSQL.dbs\admin*.dat</file> 

To get all admin*.dat files in data\ctreeSQL.dbs folder

Note: If using synchronous replication, add the option syncagent yes to the ctreplagent.cfg replication agent configuration file.

  1. If you have changed the “ADMIN” user ID password, or if authentication information has changed, you will need to generate new .set files (see ctcmdset - Configuration File Encoding Utility).
  1. Start the Source server.
  2. Start the Target server. 
  3. Check for the Plugin start message in the Target <faircom>\target\data\CTSTATUS.FCS log file:
     Plugin ctagent successfully started. Time to start=2.1 sec
  4. Check the replication log, which is referenced in the following keyword in <faircom>\target\config\replication\ctreplagent1.cfg 

It should present messages saying the replication agent was started and was able to connect to both source and target servers.

REPLAGENT1: Main: INFO: ** Starting replication agent logging for process 15436
Logread: INFO: Connected to data target 'FAIRCOMT@localhost'.
Logread: INFO: Connected to data source 'FAIRCOMT'.
  1. You are now ready to connect an application to the Source server and create some files and data. One quick way to do this is use the SQL Scripts tab in the Data Explorer app to load the <faircom>\drivers\sql.cli\tutorials\iSQL_Tutorial4.sql Script as shown here. Type https/localhost:8443 in a browser (we recommend the Chrome browser):

  1. Scroll the script down to the bottom and delete the DROP TABLE statements as shown here: 
DROP TABLE ordritem;
DROP TABLE custordr;
DROP TABLE itemmast;
DROP	TABLE custmast;
COMMIT WORK;

  1. Now press the Run All button. This will create 4 tables and will insert 4 records. You can see the tables by pressing the refresh button. 

 

  1. Highlight the custmast table and go to the Table Records tab as shown below: 

If replication is working as expected, the file create operation on the Source server will be replicated on the Target server. You can confirm this happened by listing the <faircom>\target\data\ctreeSQL.dbs folder. You should see something like the following:

If the file create operation was not replicated on the Target server, you can open CTSTATUS.FCS to troubleshoot the issue. Once the issue has been resolved, you can restart the replication agent by calling ctadmn or by using the manageService action.