automerge-classic icon indicating copy to clipboard operation
automerge-classic copied to clipboard

"Transaction" semantics

Open kpruden opened this issue 6 years ago • 0 comments

My understanding is that property conflicts are resolved individually and in isolation, regardless of other modifications in the same "change".

For properties which are modified simultaneously and are mutually dependent, this can produce results which are correct according to the guarantees of CRDT, but semantically incorrect to the application.

I'm working on a spreadsheet-like application that represents cells as an object containing the value and some metadata like type and formatting settings.

When a cell's type changes (say from number to string), several properties are modified simultaneously (value, type, format). If another client modifies the cell in a conflicting way, it's important that all of the changes from a specific client are preserved, or none of them are.

The easiest way to ensure this is to replace the entire cell payload with a new "map". This, however, is needlessly expensive for the common case: when only the value changes.

As an optimization, I'm adding logic at the application level to heuristically choose between direct property modification vs replacing the entire object.

It would be nice if Automerge somehow took care of this. From an API design perspective, I can see how this would be tricky, as this kind of transactional semantic is probably not desired in all cases. One possibility that comes to mind could be to make the object assignment semantics more sophisticated. Instead of allocating a brand new map and re-linking the parent property, you could instead "deep assign" the existing map, and annotate the resulting ops somehow to indicate that, if any of the relevant properties are involved in a conflict, either all of the ops in the "transaction" must "win" or none of them. This would have the additional benefit of reducing the size of the history when a map is replaced with a mostly identical value..

kpruden avatar Sep 05 '18 12:09 kpruden