I'm having difficulty resolving conflicts on a document with a large number of existing conflicts (100+) on iOS.
Currently, my conflict resolution method is based on the Objective-C example here:http://developer.couchbase.com/mobile/develop/guides/couchbase-lite/native-api/document/index.html#Understanding%20Conflicts I've simplified our resolution method to simply use the "winning" properties set for the current document. - (void)resolveConflictsForDocument:(CBLDocument*)doc { NSError *error; NSArray *conflicts = [doc getConflictingRevisions: &error]; if (conflicts.count > 1) { NSLog(@%lu total Conflicts for: %@", (unsigned long)conflicts.count, doc.documentID); [self.database inTransaction:^BOOL{ // For now, pick the current properties for the document NSMutableDictionary* mergedProps =[doc.properties mutableCopy]; // Delete the conflicting revisions to get rid of the conflict: CBLSavedRevision* current = doc.currentRevision; int revisionNumber = 0; for (CBLSavedRevision* rev in conflicts) { BOOL wasCurrent = NO; CBLUnsavedRevision *newRev = [current createRevision]; if (rev == current) { newRev.properties = mergedProps; // add the merged revision wasCurrent = YES; } else { newRev.isDeletion = YES; // mark other conflicts as deleted } NSError *error; [newRev save: &error]; NSLog(@"Saved %@ revsion number %d of documment: %@ error:%@", wasCurrent ? @"current" : @"non-current", revisionNumber, doc.documentID, error.localizedDescription ); revisionNumber++; } return YES; }]; } } This seems to work correctly on documents with a small number of conflicts, but saves return 409 conflict errors on two specific documents with six and 107 conflicts. Here's an example output from the six conflict document. 6 total Conflicts for: f8ee7974-9558-4ba4-ba94-6a7ce98c58b4 Saved current revsion number 0 of documment: f8ee7974-9558-4ba4-ba94-6a7ce98c58b4 error:(null) Saved non-current revsion number 1 of documment: f8ee7974-9558-4ba4-ba94-6a7ce98c58b4 error:409 conflict Saved non-current revsion number 2 of documment: f8ee7974-9558-4ba4-ba94-6a7ce98c58b4 error:409 conflict Saved non-current revsion number 3 of documment: f8ee7974-9558-4ba4-ba94-6a7ce98c58b4 error:409 conflict Saved non-current revsion number 4 of documment: f8ee7974-9558-4ba4-ba94-6a7ce98c58b4 error:409 conflict Saved non-current revsion number 5 of documment: f8ee7974-9558-4ba4-ba94-6a7ce98c58b4 error:409 conflict "non-current" revisions are tombstoned. I've also included a run with logging enabled for sync and database enabled for both normal and verbose variants which also includes output from compacting the entire database. The output can be found here: https://gist.github.com/lightandshadow68/c7dd2ebacef2d00adff9 Is there something special we need to do with documents that have more that two conflict revisions? Also, does getConflictingRevisions: return just the conflicting revisions or all revisions in the tree? That is, when attempting to resolve multiple conflicts, are some revisions returned here part of the tree that leads to the current revision and therefore cannot be tombstoned? Thanks, - Scott -- You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/fee4fdbb-a404-49ca-889d-4e1b725900fe%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
