问题描述:

Of course, I don't ask to you post me code of client and server. I just never make it early. I want understand logic of this process.


Now, I have an Android app that has different data in the database of different users. (Data can be different on each device of user). And I need to write a server and update my app-client to support the data synchronization.


What problem I have at now? I cannot understand how to remove items from database if client cannot connect to server at this moment (to I can remove data on server I need to save all removed items until app-client hasn't connection to a server)


How to correct synchronize time and etc.


How to store transaction log on client? For example, user modifies a some item but client hasn't connection. How can server understand that this I item was modified?


I will very glad any help by my theme and any links and docs.


P.S. Sorry for my English. I'm really noobie in this and due to my bad English cannot find details docs.


P.S.S. If you need more details, please, write me I'll add.


ADDED


My current model. I took a simple table for example.


Client has local table with fields:

  • ID - local ID
  • SID - server ID (null before first synchronization of the row)
  • Revision - local revision of the row
  • Flag

    • m - has local modification
    • n - hasn't any modification
    • d - was removed
  • another fields


Server table has:

- ID - server ID

- Rev - revision of the row in the server database

Logic

  • If row in client database hasn't SID it's a new row: add it in server database and set revision 0, on client set revision 0 too and server ID for this row.
  • If row in client with SID not found in server database it will removed in client database.
  • If row in client database with SID like revision in the server

    database and flag 'm' then update row in the server database and

    increment revision in both databases. (So if some devices has all

    same revision and flag only first connected device write changes in

    the server database; all another clients just gets this update from

    the server and loses their).

  • If client row has flag 'd' and SID then

    it will remove everywhere.


I don't write all cases I think it's understandable. What's bad in my model. How can I improve it? I cannot use timestamp because clock on different devices can have a different time.

相关阅读:
Top