Fix merging of documents with attachment stubs During replicated updates, merging of documents with attachment stubs will fail if, after merging the received document's revision tree with the current on disk revision tree, produces a revision tree which doesn't contain the revision that immediately precedes the received document's revision.
This happens when the received document doesn't contain in its revision history any of the revisions in the revision tree of the currently on disk document. This is possible when the document had a number of updates higher than the value of revs limit defined for the target database. Issue found, and reproduced by, Marty Schoch. Thanks. Closes COUCHDB-1365. Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/65c39616 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/65c39616 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/65c39616 Branch: refs/heads/1.1.x Commit: 65c39616f866b1d0e4c323c982db4b42f05a8feb Parents: cd67a2c Author: Filipe David Borba Manana <fdman...@apache.org> Authored: Mon Dec 19 14:44:48 2011 +0000 Committer: Filipe David Borba Manana <fdman...@apache.org> Committed: Mon Dec 19 14:56:00 2011 +0000 ---------------------------------------------------------------------- src/couchdb/couch_doc.erl | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/65c39616/src/couchdb/couch_doc.erl ---------------------------------------------------------------------- diff --git a/src/couchdb/couch_doc.erl b/src/couchdb/couch_doc.erl index f55e951..b3312c9 100644 --- a/src/couchdb/couch_doc.erl +++ b/src/couchdb/couch_doc.erl @@ -391,6 +391,8 @@ has_stubs([#att{data=stub}|_]) -> has_stubs([_Att|Rest]) -> has_stubs(Rest). +merge_stubs(#doc{id = Id}, nil) -> + throw({missing_stub, <<"Previous revision missing for document ", Id/binary>>}); merge_stubs(#doc{id=Id,atts=MemBins}=StubsDoc, #doc{atts=DiskBins}) -> BinDict = dict:from_list([{Name, Att} || #att{name=Name}=Att <- DiskBins]), MergedBins = lists:map(