Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 8FF9A200C70 for ; Wed, 19 Apr 2017 15:56:00 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 8D88A160B86; Wed, 19 Apr 2017 13:56:00 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E1B1E160BB3 for ; Wed, 19 Apr 2017 15:55:59 +0200 (CEST) Received: (qmail 31778 invoked by uid 500); 19 Apr 2017 13:55:59 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 31661 invoked by uid 99); 19 Apr 2017 13:55:59 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Apr 2017 13:55:59 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 25F7D86583; Wed, 19 Apr 2017 13:55:57 +0000 (UTC) Date: Wed, 19 Apr 2017 13:56:05 +0000 To: "commits@couchdb.apache.org" Subject: [couchdb] 09/10: Ensure deterministic revisions for attachments MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: davisp@apache.org Reply-To: "commits@couchdb.apache.org" In-Reply-To: <149261015663.32516.13659437843658889935@gitbox.apache.org> References: <149261015663.32516.13659437843658889935@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: couchdb X-Git-Refname: refs/heads/COUCHDB-3287-pluggable-storage-engines X-Git-Reftype: branch X-Git-Rev: cb03e66bad2135bdac74cf10729fe4233f2de970 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.3.dev Auto-Submitted: auto-generated Message-Id: <20170419135557.25F7D86583@gitbox.apache.org> archived-at: Wed, 19 Apr 2017 13:56:00 -0000 This is an automated email from the ASF dual-hosted git repository. davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines in repository https://gitbox.apache.org/repos/asf/couchdb.git commit cb03e66bad2135bdac74cf10729fe4233f2de970 Author: Paul J. Davis AuthorDate: Wed Feb 8 07:25:37 2017 -0600 Ensure deterministic revisions for attachments This re-fixes a corner case when recreating a document with an attachment in a single multipart request. Since we don't detect that we need a new revision until after the document has been serialized we need to be able to deserialize the body so that we can generate the same revisions regardless of the contents of the database. If we don't do this then we end up including information from the position of the attachment on disk in the revision calculation which can introduce branches in the revision tree. I've left this as a separate commit from the pluggable storage engine work so that its called out clearly for us to revisit. COUCHDB-3255 --- src/couch/src/couch_bt_engine.erl | 10 +++++++++- src/couch/src/couch_db.erl | 12 +----------- src/couch/src/couch_db_updater.erl | 12 +++++++++++- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/couch/src/couch_bt_engine.erl b/src/couch/src/couch_bt_engine.erl index 374199f..0cd9d65 100644 --- a/src/couch/src/couch_bt_engine.erl +++ b/src/couch/src/couch_bt_engine.erl @@ -324,7 +324,15 @@ serialize_doc(#st{} = St, #doc{} = Doc) -> SummaryBin = ?term_to_bin({Body, Atts}), Md5 = couch_crypto:hash(md5, SummaryBin), Data = couch_file:assemble_file_chunk(SummaryBin, Md5), - Doc#doc{body = Data}. + % TODO: This is a terrible hack to get around the issues + % in COUCHDB-3255. We'll need to come back and figure + % out a better approach to handling the case when we + % need to generate a new revision id after the doc + % has been serialized. + Doc#doc{ + body = Data, + meta = [{comp_body, Body} | Doc#doc.meta] + }. write_doc_body(St, #doc{} = Doc) -> diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl index 7fc22b2..478bd2e 100644 --- a/src/couch/src/couch_db.erl +++ b/src/couch/src/couch_db.erl @@ -944,7 +944,7 @@ prep_and_validate_replicated_updates(Db, [Bucket|RestBuckets], [OldInfo|RestOldI -new_revid(#doc{body=Body0, revs={OldStart,OldRevs}, atts=Atts, deleted=Deleted}) -> +new_revid(#doc{body=Body, revs={OldStart,OldRevs}, atts=Atts, deleted=Deleted}) -> DigestedAtts = lists:foldl(fun(Att, Acc) -> [N, T, M] = couch_att:fetch([name, type, md5], Att), case M == <<>> of @@ -952,16 +952,6 @@ new_revid(#doc{body=Body0, revs={OldStart,OldRevs}, atts=Atts, deleted=Deleted}) false -> [{N, T, M} | Acc] end end, [], Atts), - Body = case Body0 of - {summary, [_Len, _Md5, BodyAtts], _SizeInfo, _AttsFd} -> - {CompBody, _CompAtts} = binary_to_term(BodyAtts), - couch_compress:decompress(CompBody); - {summary, [_Len, BodyAtts], _SizeInfo, _AttsFd} -> - {CompBody, _CompAtts} = binary_to_term(BodyAtts), - couch_compress:decompress(CompBody); - Else -> - Else - end, case DigestedAtts of Atts2 when length(Atts) =/= length(Atts2) -> % We must have old style non-md5 attachments diff --git a/src/couch/src/couch_db_updater.erl b/src/couch/src/couch_db_updater.erl index d765458..9121a71 100644 --- a/src/couch/src/couch_db_updater.erl +++ b/src/couch/src/couch_db_updater.erl @@ -520,7 +520,17 @@ merge_rev_tree(OldInfo, NewDoc, Client, Limit, false) % Update the new doc based on revisions in OldInfo #doc_info{revs=[WinningRev | _]} = couch_doc:to_doc_info(OldInfo), #rev_info{rev={OldPos, OldRev}} = WinningRev, - NewRevId = couch_db:new_revid(NewDoc#doc{revs={OldPos, [OldRev]}}), + Body = case couch_util:get_value(comp_body, NewDoc#doc.meta) of + CompBody when is_binary(CompBody) -> + couch_compress:decompress(CompBody); + _ -> + NewDoc#doc.body + end, + RevIdDoc = NewDoc#doc{ + revs = {OldPos, [OldRev]}, + body = Body + }, + NewRevId = couch_db:new_revid(RevIdDoc), NewDoc2 = NewDoc#doc{revs={OldPos + 1, [NewRevId, OldRev]}}, % Merge our modified new doc into the tree -- To stop receiving notification emails like this one, please contact "commits@couchdb.apache.org" .