Bidirectional Snapshot Replicaton Setup tutorial
Publishing a table Defining conflict resolvers

## Preliminaries

Because every table can have only one publisher conflicts can occur only on publisher (when modifications from subscriber are applied).

Every table on publisher can have a number of conflict resolvers which are used for conflict resolution. Each conflict resolver has a type ('I', 'U', or 'D') and an order. Conflict resolvers are applied in ascending order.

Conflict resolver is a Virtuoso/PL procedure which receives conflicting row (row from subscriber) and some other arguments. Conflict resolver signatures are described in Virtuoso documentation. Conflict resolver can modify the row which is passed in as 'inout' arguments. Conflict resolver should return an integer value which will be used for conflict resolution. Possible return values and their meaning are described in Virtuoso documentation.

Conflict resolution occurs differently for each kind of DML operation. Details can be found in Virtuoso documentation.

There is a possibility to automatically generate some types of conflict resolvers. Automatically generated conflict resolver classes are:

- max -

  row with maximum value of specified column wins

- min -

  row with minumum value of specified column wins

- ave -

  new value of specified column is calculated as:

  current_val = (current_val + new_val) / 2

- pub_wins -

  publisher always wins

- sub_wins -

  subscriber always wins

## Example defining a conflict resolver

1. Login to the Conductor UI using the dba account.
2. Go to the "Replication" tab and then go to the "Bidirectional Snapshot" tab.
3. Click "Conflict Resolvers" for the desired published table ("Demo.demo.Orders").
4. Press "New Resolver" button.
5. Enter conflict resolver name suffix (enter "max_OrderDate"), select conflict resolver type (select "U"), select conflict resolver class (select "max"), select a column (select "OrderDate"). You can optionally specify conflict resolver order (default is 100).
6. Press "Add" button. A conflict resolver will be added. You can view and edit conflict resolver code by selecting a link with its name from the list of conflict resolvers.

## Equivalent SQL commands to above

1. Connect to the Virtuoso server via ISQL utility as DBA user.
2. Create 'U' conflict resolver for table "Demo.demo.Orders" that will choose a row with latest OrderDate.

       SQL> REPL_ADD_SNAPSHOT_CR ('Demo.demo.Orders', 'max_OrderDate', 'U', 100, 'max', 'OrderDate');