Syncing objects between two devices with different system times
Posted
by Mike Weller
on Stack Overflow
See other posts from Stack Overflow
or by Mike Weller
Published on 2010-05-07T10:04:09Z
Indexed on
2010/05/07
17:08 UTC
Read the original article
Hit count: 142
synchronization
|datetime
Hi there. I'm syncing objects between two devices. Objects have a lastModified
property. If both devices have modified an object, then during the next sync the version of the object with the most recent lastModified
is chosen on both devices. So we don't do fine-grained merging, only 'most recent version' merging.
The problem is this. When one device receives a list of changed objects it can't reliably compare the lastModified of received objects to its own because the system times on the two devices may be different.
I considered having each device send its current date/time during the sync. Then each calculates the difference between the remote time and the local time to compare the dates properly. But if there is lag between sending a date and the remote device receiving it, this causes incorrect comparisons with objects that were modified at the same time (or very close together in time). i.e. both devices think the remote object is newer and they end up with different objects.
I hope I have explained this clearly enough.
There must be a common solution to this kind of problem but my brain isn't coming up with anything. Any suggestions? Thanks in advance...
© Stack Overflow or respective owner