diff options
author | Filipe David Borba Manana <fdmanana@apache.org> | 2010-12-10 10:54:13 +0000 |
---|---|---|
committer | Filipe David Borba Manana <fdmanana@apache.org> | 2010-12-10 10:54:13 +0000 |
commit | 62f20a3cbd2f7507d48a0fae7ff3acc39a1b6cc2 (patch) | |
tree | 99eb910ffdfb5d50656f800f9f917215c991a4c2 /src | |
parent | fcc00849b1a223f5550b9d044461ca8bef45f864 (diff) |
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
git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1044283 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/couchdb/couch_file.erl | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl index 9d2c42ca..56ebc4f2 100644 --- a/src/couchdb/couch_file.erl +++ b/src/couchdb/couch_file.erl @@ -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. @@ -296,15 +308,10 @@ handle_call({pread_iolist, Pos}, _From, File) -> 1 -> {Md5, IoList} = extract_md5( maybe_read_more_iolist(RestRawData, 16 + Len, NextPos, File)), - 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 -> IoList = maybe_read_more_iolist(RestRawData, Len, NextPos, File), - {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), |