Causes and Solutions of Replication Conflicts#
Overview#
This document describes the causes of replication conflicts and how to resolve them.
Replication Conflict#
A replication conflict occurs when insert/update/delete is executed on the same key value at the same time.
note
In Altibase 6.1.1 or earlier, this is logged in altibase_rp.log.
In Altibase 6.3.1 or later, this is logged in altibase_rp_conflict.log.
1. Insert Conflict#
When an insert conflict occurs, the insert fails and a conflict error message is recorded in altibase_rp.log or altibase_rp_conflict.log.
For example,
1) After data with key=1 is inserted on server A, before the replication data is transmitted to server B,
2) if the same key=1 data is inserted on server B, a conflict occurs because the replication data received afterward on server B already has data with the same key=1.
You can use the REPLICATION_INSERT_REPLACE property to resolve insert conflicts.
-
REPLICATION_INSERT_REPLACE = 1: Deletes, then inserts.
-
REPLICATION_INSERT_REPLACE = 0: Records an error message without taking any additional action.
2. Update Conflict#
When an update conflict occurs, the update fails and a conflict error message is recorded in altibase_rp.log or altibase_rp_conflict.log.
This occurs when the previous image changes other data, or when attempting to change to a primary key that does not exist.
For example, this occurs when the current data is 10, but a replication transaction attempts to update it from 20 to 30.
You can use the REPLICATION_UPDATE_REPLACE property to resolve the conflict.
-
REPLICATION_UPDATE_REPLACE = 1: Updates with the replication transaction.
-
REPLICATION_UPDATE_REPLACE = 0: Does not update, and records an error message.
3. Delete Conflict#
When a delete conflict occurs, the delete fails and a conflict error message is recorded in altibase_rp.log or altibase_rp_conflict.log.
Conflict Resolution#
The best way is to avoid performing insert/update/delete with the same key value on both servers.
For example, if the sequence is the primary key for a specific table, and one server only inserts/updates/deletes data with odd numbers while the other server uses only even numbers, a replication conflict will never occur.
You should also be careful to avoid bulk insert/update/delete operations.
Altibase supports the following three replication conflict resolution schemes.
1. User - Oriented Scheme#
-
Insert Conflict: If you try to insert data with the same key, it is not reflected. (A Conflict Error Message is output to altibase_rp.log or altibase_rp_conflict.log.)
-
Delete Conflict: If you try to delete data with the same key, it is not reflected. (A Conflict Error Message is output to altibase_rp.log or altibase_rp_conflict.log.)
-
Update Conflict: If you try to update data with the same key, whether it is reflected is determined according to the property value below.
- REPLICATION_UPDATE_REPLACE = 1: Updates
- REPLICATION_UPDATE_REPLACE = 0: Does not update (A Conflict Error Message is output to altibase_rp.log or altibase_rp_conflict.log.)
- REPLICATION_UPDATE_REPLACE = 1: Updates
2. Master - Slave Scheme#
When creating a replication object, specifying AS MASTER or AS SLAVE in the statement handles replication conflicts as follows.
-
Master processing method: All insert/update/delete conflicts are not reflected.
-
Slave processing method
- Insert Conflict: Deletes the existing record and adds the replicated record.
- Update Conflict: Ignores the conflict and unconditionally reflects the change.
- Delete Conflict: Not reflected.
- Insert Conflict: Deletes the existing record and adds the replicated record.
3. Timestamp - based Scheme#
This method sets the REPLICATION_TIMESTAMP_RESOLUTION property to 1, and uses a timestamp column in the replicated table to reflect the latest value.
This method has the constraint that a timestamp column must be added to all replication target tables, and the time on both replicated servers must be set identically.
Conflict Error Message Types#
When a conflict occurs, the following log is recorded in $ALTIBASE_HOME/trc/altibase_rp.log or altibase_rp_conflict.log.
- Insert Conflict: Occurs when the same PK (Primary Key) already exists.
[2015/04/28 10:11:33] [Thread-489] [Level-2]
ERR-11058(errno=0) The row already exists in a unique index.
[2015/04/28 10:11:33] [Thread-489] [Level-3]
INSERT INTO TEST VALUES ( 14, 0, 0, , 0, 0, 0, 0 );
- Update Conflict: Occurs when the PK (Primary Key) is the same, but the pre-change value from the remote server differs from the current value.
[2015/04/27 18:49:32] [Thread-489] [Level-2]
ERR-61035(errno=62) [Receiver] An update conflict occurred.
[2015/04/27 18:49:32] [Thread-489] [Level-3]
UPDATE TEST SET C2 = 20150428 WHERE C1 =1231232 ;
- Delete Conflict: Occurs when data with the same PK (Primary Key) does not exist.
[2015/10/28 17:03:08] [Thread-140059163547392] [Level-2]
ERR-610f7(errno=16) [Receiver] Unable to find record in executeDelete() function
[2015/10/28 17:03:08] [Thread-140059163547392] [Level-3]
DELETE FROM TEST WHERE C1 = 21987744;