質問

I am implementing a basic sync strategy for a multi-client application that needs to support offline data access. I am using @Chris' suggestion in his answer to this question (not required reading).

One detail I would like to add is the ability to resolve conflicts based on the last change saved, not the last change synced. In other words, if two clients update the same item, the client that saved the change last should win, even if the other client syncs later.

Clearly I need some way to timestamp each change on the client, so I can compare the stamps on the server at the time of sync. However, I can't guarantee much about each client's internal clock.

I would like to know if there is an established way to solve this? The simpler the better!

役に立ちましたか?

解決

If you're asking about client clock hijacking: a client should maintain it's own internal clock based on timestamp it gets from server and time span got from local clock.

So you just update 'client timestamps' relatively to server:

  • Client record has CT1 update time;
  • After connecting to server at the moment of CT2, you find out that server time is ST2;
  • So record update time is changed to ST1 = ST2 - CT2 + CT1.

The other way is maintaining the same transformation at server side. (Which is probably more correct and secure).

And sorry - just a note - odd part is that you call it 'conflict resolution', when it's more 'last update wins' and no actual resolution is performed.

他のヒント

I'd not be happy trying to get away with doing it based on just timestamps, I think you need to be looking at a proper versioning solution. I don't know what language you are using etc, but I have a complete library for doing this. Even if the library is not interesting you might find the documentation for it is useful in constructing your own solution... it's pretty fully explained...

The project is on GitHub.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top