Further to this problem, I've just encountered it again.
When I look at the conflicts array from calling [doc
getConflictingRevisions:], this is what I see:
CBLSavedRevision[rec-..fb1b/1-4098dccaa969cdbab64825e687aaec68],
CBLSavedRevision[rec-..fb1b/4206-5128082a4eb2783ba5e60116f84f7e07]
But each time through the above loop, a new revision is being added, so
4206 becomes 4207, ... n. and so on.
Is there anything wrong in the above code which would prevent the
conflicted document from going away after the new revision apparently
resolved the conflict?
Basically my replication has been going on for a very long time but can
never get past this conflicted document.
Any suggestions are welcome.
Thanks,
Brendan
On Thursday, March 17, 2016 at 7:48:26 PM UTC-6, Brendan Duddridge wrote:
>
> Hi,
>
> I'm having a couple of conflicts in my documents and I thought I was
> handling it properly, but it seems like I'm not able to get rid of the
> conflicted documents. I've implemented the recommended code as follows. I'm
> wondering if I've done something wrong?
>
> - (BOOL)mergeConflictedDocument:(CBLDocument *)doc {
>
> NSError* error;
>
> NSArray* conflicts = [doc getConflictingRevisions: &error];
>
> if (conflicts.count > 1) {
>
> // There is more than one current revision, thus a
> conflict!
>
> [self.couchDatabase inTransaction: ^BOOL{
>
> // Come up with a merged/resolved document in
> some way that's
>
> // appropriate for the app. You could even just
> pick the body of
>
> // one of the revisions.
>
> NSDictionary* mergedProps = [self mergeRevisions:
> conflicts];
>
>
> // Delete the conflicting revisions to get rid of
> the conflict:
>
> CBLSavedRevision* current = doc.currentRevision;
>
> for (CBLSavedRevision* rev in conflicts) {
>
> CBLUnsavedRevision *newRev = [rev
> createRevision];
>
> if (rev == current) {
>
> // add the merged revision
>
> newRev.properties = [
> NSMutableDictionary dictionaryWithDictionary: mergedProps];
>
> for (CBLAttachment *attachment in
> rev.attachments) {
>
> [newRev setAttachmentNamed
> :attachment.name
>
> withContentType:
> attachment.contentType
>
> content:
> attachment.content];
>
> }
>
> } else {
>
> // mark other conflicts as deleted
>
> newRev.isDeletion = YES;
>
> }
>
> // saveAllowingConflict allows 'rev' to
> be updated even if it
>
> // is not the document's current revision.
>
> NSError *error = nil;
>
> if (![newRev saveAllowingConflict: &error
> ]) {
>
> TFFLog(@"Error saving conflicted
> document: %@", error);
>
> return NO;
>
> }
>
> }
>
> return YES;
>
> }];
>
> }
>
> return YES;
>
> }
>
>
> What's happening is even though the newRev.isDeletion is getting set and
> saveAllowingConflict is saving without an error, the conflict just doesn't
> seem to go away.
>
> Just wondering if there's something else I should be implementing here to
> solve this problem?
>
> Thanks!
>
> Brendan
>
--
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/582c466b-a800-48cf-91a8-40f3bf5966c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.