locked
Dynamic filtered sync RRS feed

  • Question

  • Hi, I am doing a DB synchronization app.

    I want to accomplish a sort of dynamic filtered sync. The case is: I don't know from the beginning the scope of items from the respective table that a user needs to sync (for example, in the MSDN examples,  the scope was created specifically to sync only WA = Washington stuff). Is it possible to implement this behavior?

    I tried :
    - each time a sync occurs, create the SelectIncrementalChangesCommand to get only the rows that user selected (i.e. add a WHERE clause)
    - each client has an unique scope => this means on the server a different scope for each client
    - at first client gets from server k rows => all ok
    - if the same client wants to get other rows afterwards, the provider at the server side doesn't select them

    Thank you, please help it's urgent
    Thursday, February 4, 2010 7:23 AM

Answers

  • The complete 'dynamic' nature of what you are trying to achieve is not possible. What I mean is:
    client A thinks that it is interested in state=WA data, but no scope is created yet
    So client A syncs with state=WA and gets relevant data - this step creates a scope for state=WA
    Another client B does not know what data it wants and hence no scope again
    When it syncs, it says it is interested in state=CA - and expects to get a scope created on the fly and get data for state=CA

    What will work though is on the server if there are scopes created for state=WA and state=CA,
    client A comes and specifies that it is interested in state=WA, syncs and gets its data
    client B comes and specifies that it is interested in state=CA, syncs and gets its data

    Now if Client A, after 4 syncs say, now wants data for state=OR (assume that this scope is also previously created), so it syncs this time with state=OR
    This sync will not remove state=WA data and add state=OR data.
    Client A will need to reinitialize itself (delete its database) and start afresh and sync with state=OR.

    We are looking at making this process easier with the next release of Sync Framework.
    This posting is provided AS IS with no warranties, and confers no rights
    Thursday, February 4, 2010 8:02 AM
  • it may be  because SyncFx metadata keeps track of the changes it sent/received and the new rows in the new scope has timestamps that are less than the last sync timestamp.

    Also, SyncFx docs states :

    "After a scope has been synchronized for the first time, metadata associated with existing scopes should be dropped and re-created if a scope needs to be changed."

    Thursday, February 4, 2010 3:42 PM

All replies

  • The complete 'dynamic' nature of what you are trying to achieve is not possible. What I mean is:
    client A thinks that it is interested in state=WA data, but no scope is created yet
    So client A syncs with state=WA and gets relevant data - this step creates a scope for state=WA
    Another client B does not know what data it wants and hence no scope again
    When it syncs, it says it is interested in state=CA - and expects to get a scope created on the fly and get data for state=CA

    What will work though is on the server if there are scopes created for state=WA and state=CA,
    client A comes and specifies that it is interested in state=WA, syncs and gets its data
    client B comes and specifies that it is interested in state=CA, syncs and gets its data

    Now if Client A, after 4 syncs say, now wants data for state=OR (assume that this scope is also previously created), so it syncs this time with state=OR
    This sync will not remove state=WA data and add state=OR data.
    Client A will need to reinitialize itself (delete its database) and start afresh and sync with state=OR.

    We are looking at making this process easier with the next release of Sync Framework.
    This posting is provided AS IS with no warranties, and confers no rights
    Thursday, February 4, 2010 8:02 AM
  • Thanks very much for the fast reply!

    My approach was like this:
    - I need two scopes on each client DB( SCOPE1_CLI1, SCOPE2_CLI1).
    - The server side will have 2 scopes for each client (SCOPE1_CLI1, SCOPE2_CLI1, SCOPE1_CLI2, etc)
    - If I sync 3 rows in SCOPE1, and then I want to download from the server another 4 rows in SCOPE1, what is the reason that this is not working? Is it because the SCOPE1_CLI1 at the server side only has knowledge about those 3 rows synchronized earlier?

    The filtering part is ok? I mean the way I filter, with the WHERE clause? I ask this because for the process of selecting of incremental changes and the selecting of a row are not based on stored procedures(to make the process dynamic), but the DB commands are created for each sync.

    I thought of a change that might work:
    - each client will know in advance what he will synchronize (let's say client 1 will always sync state=WA and state=OR, client 2 will always sync state=CA).
    - but I have many tables involved in a condition like state=WA (I will have to get rows from several linked tables). Also, if at start the client downloads all the tables and rows included in the condition state=WA, afterwards could he sync only certain rows, based on an additional WHERE condition in SelectIncrementalChangesCommand ?

    This new approach is it ok? Could work?

    Thanks again




    Thursday, February 4, 2010 8:56 AM
  • it may be  because SyncFx metadata keeps track of the changes it sent/received and the new rows in the new scope has timestamps that are less than the last sync timestamp.

    Also, SyncFx docs states :

    "After a scope has been synchronized for the first time, metadata associated with existing scopes should be dropped and re-created if a scope needs to be changed."

    Thursday, February 4, 2010 3:42 PM
  • Thanks, that was my guess as well. I created another way to accomplish my goals.
    Thursday, February 11, 2010 7:31 AM
  • Phazzy, what was your "other" way :)
    This posting is provided AS IS with no warranties, and confers no rights
    Thursday, February 11, 2010 8:56 PM
  • My "other" :) way it think it's working, I didn't yet tested it with multiple clients.

    The scenario is :
    The client has a local DB and wants to sync with the server DB. The server exposes an web application in wich a client can select the rows he wants to get from the server DB. After he selects them for download, a local sync application starts at the client side, and, with the help of WCF the synchronization process is achieved. The client is always the source of the sync, so at first he downloads the rows he selected. For each download from the server, a new scope is created for the respective rows. The rows that the client downloaded are blocked from anybody else to download. Just the client that downloaded the rows can upload them back.
    When the client wants to upload certain rows to the server, first I determine wich scope was used to download them from the server. I group the rows into the scopes that were used to download them and for each scope I do a different sync. So, for the upload don't create any new scopes, I use exactly the ones that were used to download the changes. After the client uploads the changes, the respective rows from the client DB are deleted along with their metadata. The rows are uploaded to the server and they are un-blocked, in order  for some other client(or the same one) to download.

    The only problem I have now is with overlapping PK's. Because they get their values from sequences, I have to develop a way to keep ID's(PK's) consistent. I am confident that I can achieve this.

    Thanks
    Friday, February 12, 2010 8:24 AM
  • The complete 'dynamic' nature of what you are trying to achieve is not possible. What I mean is:
    client A thinks that it is interested in state=WA data, but no scope is created yet
    So client A syncs with state=WA and gets relevant data - this step creates a scope for state=WA
    Another client B does not know what data it wants and hence no scope again
    When it syncs, it says it is interested in state=CA - and expects to get a scope created on the fly and get data for state=CA

    What will work though is on the server if there are scopes created for state=WA and state=CA,
    client A comes and specifies that it is interested in state=WA, syncs and gets its data
    client B comes and specifies that it is interested in state=CA, syncs and gets its data

    Now if Client A, after 4 syncs say, now wants data for state=OR (assume that this scope is also previously created), so it syncs this time with state=OR
    This sync will not remove state=WA data and add state=OR data.
    Client A will need to reinitialize itself (delete its database) and start afresh and sync with state=OR.

    We are looking at making this process easier with the next release of Sync Framework.
    This posting is provided AS IS with no warranties, and confers no rights


    OK in the above, if the server side record change from WA to CA i.e. the customer moves does that record get download when a client sync's on CA?

     

    Tuesday, December 14, 2010 5:55 PM