views:

17

answers:

1

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...

A: 

I've come up with a solution that should work.

The client sends its date to the server. The server calculates a delta which it uses to normalize the client's dates to its own time. The server sends that delta back to the client, and the client uses that same delta (negated) to do the same with the desktop's times. Now any conversions are consistent between the two devices. There can still be the situation where an older object is chosen between two that are modified within <LAG> seconds of one another, but at least that is consistent now.

Mike Weller