Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 74E48100DF for ; Mon, 3 Feb 2014 10:13:06 +0000 (UTC) Received: (qmail 66386 invoked by uid 500); 3 Feb 2014 10:12:57 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 65945 invoked by uid 500); 3 Feb 2014 10:12:46 -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 65154 invoked by uid 99); 3 Feb 2014 10:12:27 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Feb 2014 10:12:27 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 34A0C8C199E; Mon, 3 Feb 2014 10:12:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: garren@apache.org To: commits@couchdb.apache.org Date: Mon, 03 Feb 2014 10:12:37 -0000 Message-Id: In-Reply-To: <351a8cd9632642e0ad52ac4bf1803e48@git.apache.org> References: <351a8cd9632642e0ad52ac4bf1803e48@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [13/22] couchdb commit: updated refs/heads/paginate-api-options to 5d2a6f9 Throw cleaner error on MD5 mismatch during compaction COUCHDB-2040 Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/e7fdc16a Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/e7fdc16a Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/e7fdc16a Branch: refs/heads/paginate-api-options Commit: e7fdc16a485ec9a9d3b6bb3555957e367ec55f11 Parents: 2d08044 Author: Robert Newson Authored: Wed Jan 29 21:47:58 2014 +0000 Committer: Robert Newson Committed: Thu Jan 30 11:39:07 2014 +0000 ---------------------------------------------------------------------- src/couchdb/couch_db_updater.erl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/e7fdc16a/src/couchdb/couch_db_updater.erl ---------------------------------------------------------------------- diff --git a/src/couchdb/couch_db_updater.erl b/src/couchdb/couch_db_updater.erl index af7578e..947669c 100644 --- a/src/couchdb/couch_db_updater.erl +++ b/src/couchdb/couch_db_updater.erl @@ -824,14 +824,16 @@ copy_doc_attachments(#db{updater_fd = SrcFd} = SrcDb, SrcSp, DestFd) -> end, % copy the bin values NewBinInfos = lists:map( - fun({Name, Type, BinSp, AttLen, RevPos, Md5}) -> + fun({Name, Type, BinSp, AttLen, RevPos, ExpectedMd5}) -> % 010 UPGRADE CODE - {NewBinSp, AttLen, AttLen, Md5, _IdentityMd5} = + {NewBinSp, AttLen, AttLen, ActualMd5, _IdentityMd5} = couch_stream:copy_to_new_stream(SrcFd, BinSp, DestFd), - {Name, Type, NewBinSp, AttLen, AttLen, RevPos, Md5, identity}; - ({Name, Type, BinSp, AttLen, DiskLen, RevPos, Md5, Enc1}) -> - {NewBinSp, AttLen, _, Md5, _IdentityMd5} = + check_md5(ExpectedMd5, ActualMd5), + {Name, Type, NewBinSp, AttLen, AttLen, RevPos, ExpectedMd5, identity}; + ({Name, Type, BinSp, AttLen, DiskLen, RevPos, ExpectedMd5, Enc1}) -> + {NewBinSp, AttLen, _, ActualMd5, _IdentityMd5} = couch_stream:copy_to_new_stream(SrcFd, BinSp, DestFd), + check_md5(ExpectedMd5, ActualMd5), Enc = case Enc1 of true -> % 0110 UPGRADE CODE @@ -842,10 +844,13 @@ copy_doc_attachments(#db{updater_fd = SrcFd} = SrcDb, SrcSp, DestFd) -> _ -> Enc1 end, - {Name, Type, NewBinSp, AttLen, DiskLen, RevPos, Md5, Enc} + {Name, Type, NewBinSp, AttLen, DiskLen, RevPos, ExpectedMd5, Enc} end, BinInfos), {BodyData, NewBinInfos}. +check_md5(Md5, Md5) -> ok; +check_md5(_, _) -> throw(md5_mismatch). + copy_docs(Db, #db{updater_fd = DestFd} = NewDb, InfoBySeq0, Retry) -> % COUCHDB-968, make sure we prune duplicates during compaction InfoBySeq = lists:usort(fun(#doc_info{id=A}, #doc_info{id=B}) -> A =< B end,