开发者

Syncing objects between two devices with different system times

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 on开发者_开发知识库e 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...


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.


the below solution works only in symmetrical systems as client and server should have the same time on air for their messages and this is not always the case..for example in moving objects..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜