symmetricds

SymmetricDS lookup table router and delete replication


I've set up a lookup table router using an ancillary table to map a column in the routed table to node external_id.

Removing entries from the lookup table does not seem to have an effect on the replication. I may have been naive to expect that the routed rows were going to be removed from the client node, that does not happen. I can image why this does not happen because the link between row (column value) and target node no longer exists. To make things worse, deletes in the routed table are also no longer replicated to that node.

This is an edge case but it does happen in practice after inserting a wrong row in the lookup table. Data may have been routed before anyone notices the mistake. At the time the lookup row is deleted, the damage is already done.

So my question is: is it achievable to delete the relevant rows on the target node when a lookup entry is removed?

A related question was already asked here, unfortunately unanswered.


Solution

  • Create an interceptor that will, before deleting a lookup entry, resolve all data that was pushed to the destination node, generate delete statements, delete the lookup entry and at the end push generated delete statements to the destination node.

    Resolution of all data that was already pushed to the destination node has to be custom programmed.

    Pushing generated delete statements could be done in a trigger in the DB. It will have to resolve all tables and rows that have been already synced to the destination node that's about to be removed by deleting its lookup entry. Put the custom SQL in sym_data.row_data and set the event_type='S'. Use the node_list to target the node that's about to be deleted.

    There's still a risk that some rows will be synced or scheduled to be synced to the destination that are extracted for synchronisation by DB transactions executed in parallel.