Search code examples
databasedata-synchronizationsymmetricds

Database sharing using SymmetricDS among different stores


We are evaluating SymmetricDS for one of our applications.

We want to synchronize database among multiple stores. The data needs to flow from one store to the central database and then back to different stores.

In SymmetricDS, we are able to achieve the data flows as follows:

store -> central database // whenever we modify/insert/delete data in store, 

and also from

central database -> store // whenever we modify/insert/delete data in central db

but what we require is a bit back and forth

store -> central database -> stores

i.e. store inserts a data row in its database, it should go to central db and then back to selected stores

Edited the question as below to elaborate which table is not synced now

We have following heirarchy

Stores Chains of stores There is Central DB having information of all stores and chains

Each store must have a basic information like address of all the stores within its own chain. Store can add another store to its chain. Once that happens the added store must then get information through syncing of all the stores in this chain.

Tables are like below:

STORE_CHAINS (having mapping between STORE_ID, CHAIN_ID).

Example of STORE_CHAINS:

STORE_ID    CHAIN_ID
A           CHAIN1
B           CHAIN1
C           CHAIN1
Y           CHAIN2
Z           CHAIN2

There is a STORES table which has details about each store with STORE_ID being the primary key.

Example of STORES table:

STORE_ID    STORE_ADDRESS   ...
A           AddrA
B           AddrB
C           AddrC
D           AddrD
...         
X           AddrX
Y           AddrY
Z           AddrZ

Each store is synced a portion of the CENTRAL STORES table database with some basic information. Only those stores' details are synced which share the same chain.

For example here, if a new mapping (D, CHAIN1) is added to STORE_CHAINS table by Store C, the newly added store D should then receive through sync the mapping entry itself and details about the Stores A, B, C from the STORES table because they share the same chain CHAIN1. Also the Stores A, B will be sent STORE_CHAINS mapping entry and STORES entry for D.

Our problem is that the STORES entry for A,B,C is not getting sent to D. Only the newly created mapping (D, CHAIN1) gets synced to D.

The table STORE_CHAINS is the only one that has actually had a data changed, the STORES table has not changed. How do we ensure that the triggers of STORES table also get fired and its data is sent to all the relevant stores whenever a new (STORE_ID, CHAIN_ID) mapping is created.

We are using subselect for all cases to select which stores/store-group mapping entries should be sent. The selection logic works ok if we do an initial load for any store.

Thanks in advance.


Solution

  • Set the value for the column sync_on_incoming_batch to 1 as explained in the documentation http://www.symmetricds.org/doc/3.8/html/user-guide.html#_bi_directional_synchronization

    Use CUSTOM_BEFORE_UPDATE_TEXT or CUSTOM_BEFORE_INSERT_TEXT to trigger a sunny update on all dependency rows from other tables that need to get synced