Jeffail / leaps

A pair programming service using operational transforms
MIT License
750 stars 55 forks source link

offline use case #28

Closed joeblew99 closed 8 years ago

joeblew99 commented 8 years ago

Some users will want to edit a document when offline, and then when they go online resync. OT's allow this to work, since they are not dependent on time / vector clocks. Like CRDT they are commutative ?

It seems that the code is here: https://github.com/Jeffail/leaps/blob/master/lib/binder/model_text.go#L57

If the OT can be saved to disk then this should work. When i user is back on line, the OT's can be transformed abck into the doc to reconstruct it.

In terms of conflicts some sort of basic last in wins rule can be used, but its pretty much the lowest common denominator way to do it.

Here is a good explanation. http://basho.com/posts/technical/clocks-are-bad-or-welcome-to-distributed-systems/

But there are 2 other ways i know of:

MVCC

CRDTS

In summary, This would add offline editing and sync, and i would be interested in helping on this. But i am offering up the idea here, to see if others are into this. ??

Jeffail commented 8 years ago

Hey @joeblew99, the leaps service already has to support this behaviour, as each client interface is written to be non-blocking (i.e. the edits you make locally are instantly applied to your local copy before being verified by the server). Leaps does this by buffering a short history of operational transforms for adjusting incoming changes that are out of date, the client subsequently then has to retroactively adjust incoming operational transforms such that when applied to the local document they end up with the same result, even though the transforms come in the wrong order with respect to the local changes.

If you were to run leaps such that a user could disconnect and then resync later then you would need to ensure the operational transform history on the leaps server is retained for the maximum duration of an offline session. This is a configurable value (found in the binder type config https://github.com/Jeffail/leaps/blob/master/lib/binder/binder.go#L40). If you decided that clients could work offline for up to 24 hours before re-syncing then you could set the retention period to 24 * 60 * 60 seconds.

The leaps clients are currently written to block IO and flag errors when the connection to the host is lost (to prevent a user unknowingly continuing work that will be lost). If your intention is to have an offline editor then you will need to remove those features, but it should be possible with only minor changes.

joeblew99 commented 8 years ago

thanks for the feedback @Jeffail . great feedback

i will extend this for persistence aspects as discussed and PR it back when ready. Not sure how much will change.