Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 40717 invoked from network); 10 Dec 2010 11:04:15 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 10 Dec 2010 11:04:15 -0000 Received: (qmail 19029 invoked by uid 500); 10 Dec 2010 11:04:15 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 18904 invoked by uid 500); 10 Dec 2010 11:04:12 -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 18897 invoked by uid 99); 10 Dec 2010 11:04:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Dec 2010 11:04:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Dec 2010 11:04:09 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7932B2388994; Fri, 10 Dec 2010 11:03:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1044284 - /couchdb/branches/1.0.x/src/couchdb/couch_file.erl Date: Fri, 10 Dec 2010 11:03:48 -0000 To: commits@couchdb.apache.org From: fdmanana@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101210110348.7932B2388994@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: fdmanana Date: Fri Dec 10 11:03:48 2010 New Revision: 1044284 URL: http://svn.apache.org/viewvc?rev=1044284&view=rev Log: Merged revision 1043524 from trunk Calculate and verify MD5 digests outside of a couch_file server This has a significant positive impact on the performance, both for readers and writers, when there are several requests in parallel acessing the same database or view index file. $ node tests/compare_write_and_read.js --wclients 100 --rclients 200 \ -name1 md5_out -name2 trunk \ -url1 http://localhost:5984/ -url2 http://localhost:5985/ \ --duration 120 run 1) http://graphs.mikeal.couchone.com/#/graph/5c859b3e7d1b9bd0488cfe271105130c run 2) http://graphs.mikeal.couchone.com/#/graph/5c859b3e7d1b9bd0488cfe2711051bba Closes COUCHDB-980 Modified: couchdb/branches/1.0.x/src/couchdb/couch_file.erl Modified: couchdb/branches/1.0.x/src/couchdb/couch_file.erl URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/src/couchdb/couch_file.erl?rev=1044284&r1=1044283&r2=1044284&view=diff ============================================================================== --- couchdb/branches/1.0.x/src/couchdb/couch_file.erl (original) +++ couchdb/branches/1.0.x/src/couchdb/couch_file.erl Fri Dec 10 11:03:48 2010 @@ -120,7 +120,19 @@ pread_binary(Fd, Pos) -> pread_iolist(Fd, Pos) -> - gen_server:call(Fd, {pread_iolist, Pos}, infinity). + case gen_server:call(Fd, {pread_iolist, Pos}, infinity) of + {ok, IoList, <<>>} -> + {ok, IoList}; + {ok, IoList, Md5} -> + case couch_util:md5(IoList) of + Md5 -> + {ok, IoList}; + _ -> + exit({file_corruption, <<"file corruption">>}) + end; + Error -> + Error + end. %%---------------------------------------------------------------------- %% Purpose: The length of a file, in bytes. @@ -298,15 +310,10 @@ handle_call({pread_iolist, Pos}, _From, <<1:1/integer,Len:31/integer>> -> % an MD5-prefixed term {Md5AndIoList, _} = read_raw_iolist_int(File, NextPos, Len+16), {Md5, IoList} = extract_md5(Md5AndIoList), - case couch_util:md5(IoList) of - Md5 -> - {reply, {ok, IoList}, File}; - _ -> - {stop, file_corruption, {error,file_corruption}, File} - end; + {reply, {ok, IoList, Md5}, File}; <<0:1/integer,Len:31/integer>> -> {Iolist, _} = read_raw_iolist_int(File, NextPos, Len), - {reply, {ok, Iolist}, File} + {reply, {ok, Iolist, <<>>}, File} end; handle_call({pread, Pos, Bytes}, _From, #file{fd=Fd,tail_append_begin=TailAppendBegin}=File) -> {ok, Bin} = file:pread(Fd, Pos, Bytes),