swarm icon indicating copy to clipboard operation
swarm copied to clipboard

How to implement conflict resolution (ie: manual merge conflicts)

Open coodoo opened this issue 11 years ago • 8 comments

Through my quick prototype it seemed the merge strategy here is "last write wins", I was wondering is it possible to implement a more refined conflict resolution, ie: let the user to manually merge two copies of data and resolve the conflict.

Thoughts?

coodoo avatar Oct 26 '14 10:10 coodoo

Something more refined is used in Text and Vector (Causal Trees, very much like 3-way merge for linear structures). Manual resolution also is possible to implement. The type will have to explicitly declare state of conflict. Absolutely no problem. May you tell more about your use case?

gritzko avatar Oct 26 '14 11:10 gritzko

Take TodoMVC app for example, say I'm working with a couple of colleagues on the same list, then I jump on a plane and for the next 18 hours I will be offline but still making changes to the same list, next time when I'm back online, the todo list on my laptop should be synced with the server, but, if there's any conflict (two people edited the same todo item), I would like one of these to happen:

  1. The app is smart enough to try auto merging my copy and the one on server
  2. If auto merge failed, present me with a 3-way merge-alike UI, so I could chose which copy to use, or manually merge the two then mark the conflict resolved

In the mixin for react, I saw something like this this.sync.on( function (spec,val,source) {...} ) which seems to be a good entry point to do just that, it would be great if I get a chance to see the old and new content first, and if there's a conflict, I can do the merge myself, or prepare a nice UI for user to decide how to resolve.

coodoo avatar Oct 26 '14 12:10 coodoo

I'm a total noob to this project but it seems like the whole point of this project is to eliminate the need for manual merges via the CRDT approach, no? What role does manual merge really have in the vision of what swarm.js is trying to do?

andrewluetgers avatar Oct 29 '14 05:10 andrewluetgers

Well, my point is that manual merge is still possible to implement, in case there are some reasons to do so.

On 29 October 2014 09:56, Andrew Luetgers [email protected] wrote:

I'm a total noob to this project but it seems like the whole point of this project is to eliminate the need for manual merges via the CRDT approach, no? What role does manual merge really have in the vision of what swarm.js is trying to do?

— Reply to this email directly or view it on GitHub https://github.com/gritzko/swarm/issues/35#issuecomment-60877706.

Victor

gritzko avatar Oct 29 '14 08:10 gritzko

Agreed, crdt is perfect for the job, but how do you guys normally handle conflict? A simple use case where two people modified same text field, do you just let last write wins?

@gritzko quick question, is there any way to listen to rm events from Host or Set/Vector? Here's the code I got now but it only works on set event, help?

Swarm.env.localhost.onObjectEvent( function( spec, val, src ){
    // only set event will be triggered, but not rm event
})

coodoo avatar Oct 29 '14 09:10 coodoo

In linear structures, concurrency is handled by Causal trees. The result is like per-letter 3-way merge. http://www.pds.ewi.tudelft.nl/~victor/#ct In the TodoMVC demo, the text is actually LWW, while the collection is linear (Vector).

Regarding set/rm, LWW objects have set and no rm (see Model). Vectors have in and rm.

On 29 October 2014 13:07, Jeremy Lu [email protected] wrote:

Agreed, crdt is perfect for the job, but how do you guys normally handle conflict? A simple use case where two people modified same text field, do you just let last write wins?

@gritzko https://github.com/gritzko quick question, is there any way to listen to rm events from Host or Set/Vector? Here's the code I got now but it only works on set event, help?

Swarm.env.localhost.onObjectEvent( function( spec, val, src ){ // only set event will be triggered, but not rm event})

— Reply to this email directly or view it on GitHub https://github.com/gritzko/swarm/issues/35#issuecomment-60892123.

Victor

gritzko avatar Oct 29 '14 09:10 gritzko

How do I listen to the event whenever any TodoItem of a TodoList was removed?

Here's the code I'm using now, but it works on when TodoItems was created or updated, not removed.

In short, I'm looking for a way to globally listen to any set and rm events of any objects (be it Model/Set/Vector), originally I thought this could be done via Host but obviously not, need guidance here, thanks!

myTodoList.onObjectEvent( function( spec, val, src ){
    console.log( '\n', spec, val, src );
})

coodoo avatar Oct 29 '14 09:10 coodoo

Ended up this seems to be the correct way to do it:

myTodoList.on( 'rm', function( spec, val, src ){
    console.log( 'TodoList > RM', arguments );
})

myTodoList.on( 'in', function( spec, val, src ){
    console.log( 'TodoList > IN', arguments );
})

How many events like this are there in the whole lib, is there any document I could read? Thanks.

coodoo avatar Oct 29 '14 09:10 coodoo