If the Replication Agent process terminates abnormally, it is desirable for the agent to resume replicating transactions from where it left off in the source server transaction logs. A persistence state is needed to maintain this information. This persistence requires that the Replication Agent always knows the last transaction it has committed to the target FairCom Server.
To enable this persistent state, a special table is stored on the target server for this purpose, and for each transaction the Replication Agent commits it updates a replication state record on the target server in that same transaction. This way, the Replication Agent can always read its latest state from the target server, even if the Replication Agent process terminates, or should it lose its connection to the target server, or the target server terminates and restarts.
When multiple Replication Agents are connected to a single target server, it is necessary to maintain state information unique to each replication instance. To do this, a configurable unique ID can be assigned to each agent. The Replication Agent unique ID is a string (maximum 32 characters). The Replication Agent’s configuration file, ctreplagent.cfg, can specify the unique ID using the unique_id configuration option. For example:
unique_id myreplagent
If not specified, the unique ID defaults to REPLAGENT.
Target Server Files
Once the replication has started and successfully connected to both the source and target servers, it will create a set of files on the target server which contains information about the current state and position of replication within the source transaction logs. This allows the Replication Agent to pick up from a previous session should a network connection fail, or the agent is paused for administrative purposes. These files are:
REPLSTATEDT.FCS
REPLSTATEIX.FCS
REPLSTATEDT.FCS and is a variable-length data file that contains one record for each Replication Agent that has registered itself with the target server. The records are indexed by the Replication Agent unique ID.
When the Replication Agent starts, it reads its unique ID from the ctreplagent.cfg configuration file, connects to the target server, creates REPLSTATEDT.FCS if it does not exist, and then reads its Replication Agent state record.
The Replication Agent opens the file ctreplagent.ini if it exists and reads the saved replication state (log read position and last commit log position). The state from ctreplagent.ini is used if that file exists; otherwise the state from the Replication Agent state record is used. If neither exists, the Replication Agent commences its scan from log 1 position 0.
Note: If log 1 no longer exists (for example, if the transaction files were not removed along with the removal of the REPLAGENT.FCS file), then error 96 (LOPN_ERR, Log file/Start file open error) is possible. In this case, existing transaction logs will need to be removed, or a ctreplagent.ini file needs to be created with correct log and position information.
When committing a transaction on the target server, the Replication Agent writes its current state to the replication state record before it commits the transaction. Note that the Replication Agent reads its replication state record when it connects to the target server, and the Replication Agent keeps that record locked until it disconnects from the target server.
For more, see Starting Replication from a Known Log Position in the replication documentation.