Search code examples
javatomcatjmxsymmetricds

How to determine that the synchronization completed SymmetricDS


I need to write code, that uses SymmetricDS and synchronizes two DBs when one presses the button. I.e. I need to press the button, it shows that it is synching, then when there are no more changes it says 'Everything is ok' and lets me continue operations.

I've worked out all I need to do for that, except the way to determine that everything is synched.

The SymmetricDS engines are deployed in Tomcat 8, my application is deployed there too and I use JMX MBeans to connect to SymmetricDS to start/stop synchronization.


Solution

  • I found that these four queries

    String serv_outgoing = "select * from sym_outgoing_batch where node_id = '" + node_id + "' and channel_id != 'config' and status != 'OK';";
    String serv_data = "select d.* from sym_data d where d.data_id not in (select e.data_id from sym_data_event e);";
    
    String client_outgoing = "select * from sym_outgoing_batch where node_id = '000' and channel_id != 'config' and status != 'OK';";
    String client_data = "select d.* from sym_data d where d.data_id not in (select e.data_id from sym_data_event e);";
    

    should return empty results. First two are executed on server database, the second two on client.

    This doesn't look like a good solution, since the client has to have an access to the server database, but you can, for example, create a servlet on your server that listens to some HTTP request like "does server think that the sync is finished" and query it before checking client-side database

    Also, this is an old piece of code, you should not use plain queries to coonect over JDBC and use Hibernate, or other ORMs, so they escape your parameters correctly and you're not prone to SQL injections (here of course you probably are generating node_id internally, but who knows, maybe you let users input it in some way, like a login or something)