Resolving Conflicts

43 views
Skip to first unread message

Julio Albuquerque

unread,
Apr 17, 2015, 5:21:37 PM4/17/15
to mobile-c...@googlegroups.com
Hello!
I use Couchbase Lite .Net, Xamarin Android and C #.
I am developing a routine to treat CONFLICTS, following tips from a presentation by Jeff (I do not know if the name is correct).

According to my need, I need to always save the newest possible revision, as I do this? Since the structure of my documents I do not have a type attribute: Created in.
The revisions do not have date and time?
I noticed that conflicts are IEnumerable <SavedRevision> therefore always the last line would be the youngest?

Can anyone help?
Part of the code I'm using is this:

private void myResolveConflict (Document doc, IEnumerable<SavedRevision> conflicts)
         
{
             
Dictionary<String,Object> mergeProps = myMergeRevisions (conflicts);
             
var current = doc.CurrentRevision;
             
foreach (var rev in conflicts) {
                 
var newRev = rev.CreateRevision ();
                 
if (rev == current) {
                     newRev
.SetProperties (mergeProps);
                 
} else {
                     newRev
.IsDeletion = true;
                 
}
                 newRev
.Save ();
             
}
         
}

Julio.

Jens Alfke

unread,
Apr 17, 2015, 8:11:18 PM4/17/15
to mobile-c...@googlegroups.com
On Apr 17, 2015, at 2:21 PM, Julio Albuquerque <jcezar.al...@gmail.com> wrote:

I am developing a routine to treat CONFLICTS, following tips from a presentation by Jeff (I do not know if the name is correct).

Might be me :)

According to my need, I need to always save the newest possible revision, as I do this? Since the structure of my documents I do not have a typeattribute: Created in.

The revisions do not have date and time?

Nope. Time isn’t very meaningful or useful in a fully distributed system. That’s for a number of reasons — you can’t guarantee that all devices have correct clocks; you can’t guarantee that devices report time truthfully; and if there are network partitions there can be a big delay between the time a revision is created and the time other devices see it.

If you feel that timestamps are good enough for your use case, you can add them to documents yourself, and then use them to help resolve conflicts.

I noticed that conflicts are IEnumerable <SavedRevision> therefore always the last line would be the youngest?

I don’t have the .NET code handy, but I believe the ordering is by priority. The revision that’s been arbitrarily selected as the default (or “winner”) comes first. For most purposes you can consider the ordering of the rest of the revisions to be arbitrary/random.

—Jens

Julio Albuquerque

unread,
Apr 17, 2015, 9:05:52 PM4/17/15
to mobile-c...@googlegroups.com
Sorry, the correct name is Jens Alfke, kkkkk

It could not be the sequence?
Its retrieve the sequence number of conflicts / reviews?
Thus I assume that the major sequence was the last.
It is possible?

I see no other way to solve my problem, I accept suggestions.
For example, I have a document with two conflicts:
id = "X" description = "home" type = "1"
id = "X" description = "home" type = "2"

So I have the same document but with two different information type.
How to know which version is the "true"?
So I want to "take over" the last record "theory" is true.

Julio.
 
Julio.

Jens Alfke

unread,
Apr 18, 2015, 1:21:26 PM4/18/15
to mobile-c...@googlegroups.com
On Apr 17, 2015, at 6:05 PM, Julio Albuquerque <jcezar.al...@gmail.com> wrote:

It could not be the sequence?
Its retrieve the sequence number of conflicts / reviews?
Thus I assume that the major sequence was the last.
It is possible?

Sequence numbers are local to each database. They just reflect the order in which the doc was added to that db. User A and user B won’t have the same sequence number for the same revision, and they can’t see each other’s sequence numbers anyway.

So I have the same document but with two different information type.
How to know which version is the "true”?

Both of them are “true” in some sense. Just because user A updated the document two seconds before user B doesn’t mean that user A’s update is better than user B’s. Especially if user A was offline on the subway at the time, so her update didn’t get pushed to the server for another half hour, by which time a thousand people had already received B’s update. At that point, overwriting B’s changes with A’s is totally the wrong thing to do!

Stop thinking about time and think about the content of the documents. You’ll probably need to look at individual properties and combine the values together — the details are very specific to your application’s data schema, which is why CBL doesn’t try to merge for you.

—Jens
Reply all
Reply to author
Forward
0 new messages