When multiple database servers try to update the same row simultaneously (the time stamp for both updates is the same GMT time), a collision occurs. For more information, see Applying Replicated Data. Enterprise Replication must determine which new data to replicate. To solve conflict resolution, you must specify the following for each replicate:
Enterprise Replication supports the following conflict-resolution rules.
Conflict Resolution Rule | Effect | Reference |
---|---|---|
Ignore | Enterprise Replication does not attempt to resolve conflicts. | page Ignore Conflict-Resolution Rule |
Time stamp | The row or transaction with the most recent time stamp is applied. | page Time-Stamp Conflict-Resolution Rule |
SPL routine | Enterprise Replication uses a routine written in SPL (Stored Procedure Language) that you provide to determine which data should be applied. | page SPL Conflict-Resolution Rule |
Time stamp with SPL routine | If the time stamps are identical, Enterprise Replication invokes an SPL routine that you provide to resolve the conflict. | page Time-Stamp Conflict-Resolution
Rule,
page SPL Conflict-Resolution Rule |
Always-apply | Enterprise Replication does not attempt to resolve conflicts. | page Always-Apply Conflict-Resolution Rule |
For all conflict-resolution rules except ignore and always-apply, you must create shadow columns in the tables on both the source and target servers involved in replication. For more information, see Shadow Columns.
Enterprise Replication supports up to two conflict-resolution rules for each replicate: a primary rule and a secondary rule (if desired). Table 9 shows the valid combinations of Enterprise Replication conflict-resolution rules.
Primary Rule | Secondary Rule |
---|---|
Ignore | None |
Time stamp | None |
Time stamp | SPL routine |
SPL routine | None |
Always-apply | None |
The ignore conflict-resolution rule does not attempt to detect or resolve conflicts. A row or transaction either applies successfully or it fails. A row might fail to replicate because of standard database reasons, such as a deadlock situation, when an application locks rows.
The ignore conflict-resolution rule can only be used as a primary conflict- resolution rule and can have either a transaction or a row scope (as described in Scope). Table 10 describes the ignore conflict-resolution rule.
Row Exists in Target? | Database Operation | ||
---|---|---|---|
Insert | Update | Delete | |
No | Apply row | Discard row | Discard row |
Yes | Discard row | Apply row | Apply row |
When a replication message fails to apply to a target, you can spool the information to one or both of the following directories:
If selected, all buffers in a failed replication message that compose a transaction are written to this directory.
If selected, the replication message for a row that could not be applied to a target is written to this directory.
For more information, see Monitoring and Troubleshooting Enterprise Replication.
The time-stamp rule evaluates the latest time stamp of the replication against the target and determines how to resolve any conflict.
The time-stamp resolution rule behaves differently depending on which scope is in effect:
Enterprise Replication evaluates one row at a time. The row with the most recent time stamp wins the conflict and is applied to the target database servers. If an SPL routine is defined as a secondary conflict-resolution rule, the routine resolves the conflict when the row times are equal.
Enterprise Replication evaluates the most recent row-update time among all the rows in the replicated transaction. This time is compared to the time stamp of the appropriate target row. If the time stamp of the replicated row is more recent than the target, the entire replicated transaction is applied. If a routine is defined as a secondary conflict-resolution rule, it is used to resolve the conflict when the time stamps are equal.
For more information, see Scope.
A secondary routine is invoked only if Enterprise Replication evaluates rows and discovers equal time stamps.
If no secondary conflict-resolution rule is defined and the time stamps are equal, the transaction from the database server with the lower value in the cdrserver shadow column wins the conflict.
Table 11 shows how a conflict is resolved based on the latest time stamp with row scope. The time stamp Tlast_update (the time of the last update) represents the row on the target database server with the last (most recent) update. The time stamp Trepl (the time when replication occurs) represents the time stamp on the incoming row.
Enterprise Replication first checks to see if a row with the same primary key exists in either the target table or its corresponding delete table.
If the row exists, Enterprise Replication uses the latest time stamp to resolve the conflict.
The time-stamp conflict-resolution rule assumes time synchronization between cooperating Enterprise Replication servers. For more information, see Time Synchronization.
You can assign an SPL routine as the primary conflict-resolution rule. If you use an SPL routine as a secondary conflict-resolution rule, the time-stamp conflict-resolution rule must be the primary rule.
Routines for conflict-resolution must be in SPL. Enterprise Replication does not allow user-defined routines in C or in Java.
Enterprise Replication passes the following information to an SPL routine as arguments.
The routine must set the following arguments before the routine can be applied to the replication message.
Argument | Description |
---|---|
An indicator of the desired database operation to be performed [CHAR(1)] | Same as the replicate action codes with the following
additional codes
|
A non-zero integer value to request logging of the conflict resolution and the integer value in the spooling files (INTEGER) | Logging value takes effect only if logging is configured for this replicate. |
The columns of the row to be applied to the target table replicate action type in regular SQL format | This list of column values is not parsed if the replicate action type that the routine returns is S, O, or X. |
You can use the arguments to develop application-specific routines. For example, you can create a routine in which a database server always wins a conflict regardless of the time stamp.
The following list includes some items to consider when you use an SPL routine for conflict resolution:
In addition, you must determine when the SPL routine executes:
For information on specifying that the SPL routine is optimized, see Conflict Options.
The always-apply conflict-resolution rule does not attempt to detect or resolve conflicts. Unlike with the ignore conflict-resolution rule, replicated changes are applied even if the operations are not the same on the source and target servers. In the case of a conflict, the current row on the target is deleted and replaced with the replicated row from the source.
Table 12 describes the always-apply conflict-resolution rule.
Each conflict-resolution rule behaves differently depending on the scope. Enterprise Replication uses the following scopes:
When you choose a row scope, Enterprise Replication evaluates one row at a time. It only applies replicated rows that win the conflict resolution with the target row. If an entire replicated transaction receives row-by-row evaluation, some replicated rows are applied while other replicated rows might not be applied.
When you choose a transaction scope, Enterprise Replication applies the entire transaction if the replicated transaction wins the conflict resolution. If the target wins the conflict (or other database errors are present), the entire replicated transaction is not applied.
A transaction scope for conflict resolution guarantees transactional integrity.