diff options
author | Adam Kocoloski <adam.kocoloski@gmail.com> | 2011-01-20 12:43:37 -0500 |
---|---|---|
committer | Adam Kocoloski <adam.kocoloski@gmail.com> | 2011-01-20 13:05:41 -0500 |
commit | f79d0a666a5fb9541a0925db5111208a94631065 (patch) | |
tree | 392d85a8a9887ddc8f6268a48a65537b21734a7d /apps/couch/src/couch_db.erl | |
parent | 2ea18bdaa19ea7f2da1a5dccce65d50cf0efc64d (diff) | |
parent | 94286611038e661487382ed834103853e88fdf69 (diff) |
Merge CouchDB 1.0.2 release candidate
Conflicts:
Makefile.am
acinclude.m4.in
apps/couch/src/couch_db.erl
apps/couch/src/couch_db_updater.erl
apps/couch/src/couch_rep.erl
apps/couch/src/couch_rep_reader.erl
apps/couch/src/couch_view.erl
apps/couch/src/couch_view_group.erl
rel/overlay/etc/default.ini
share/Makefile.am
src/couchdb/couch_query_servers.erl
src/ibrowse/Makefile.am
src/ibrowse/ibrowse.app.in
src/ibrowse/ibrowse.erl
src/ibrowse/ibrowse_app.erl
src/ibrowse/ibrowse_http_client.erl
src/ibrowse/ibrowse_lb.erl
src/ibrowse/ibrowse_lib.erl
src/ibrowse/ibrowse_sup.erl
src/ibrowse/ibrowse_test.erl
src/mochiweb/mochijson2.erl
test/etap/112-replication-missing-revs.t
test/etap/113-replication-attachment-comp.t
test/etap/140-attachment-comp.t
Diffstat (limited to 'apps/couch/src/couch_db.erl')
-rw-r--r-- | apps/couch/src/couch_db.erl | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/apps/couch/src/couch_db.erl b/apps/couch/src/couch_db.erl index 0e42980e..7293b9bb 100644 --- a/apps/couch/src/couch_db.erl +++ b/apps/couch/src/couch_db.erl @@ -25,6 +25,7 @@ -export([set_security/2,get_security/1]). -export([changes_since/5,changes_since/6,read_doc/2,new_revid/1]). -export([check_is_admin/1, check_is_reader/1, get_doc_count/1, load_validation_funs/1]). +-export([reopen/1]). -include("couch_db.hrl"). @@ -84,6 +85,17 @@ open(DbName, Options) -> Else -> Else end. +reopen(#db{main_pid = Pid, fd = Fd, fd_monitor = OldRef, user_ctx = UserCtx}) -> + {ok, #db{fd = NewFd} = NewDb} = gen_server:call(Pid, get_db, infinity), + case NewFd =:= Fd of + true -> + {ok, NewDb#db{user_ctx = UserCtx}}; + false -> + erlang:demonitor(OldRef), + NewRef = erlang:monitor(process, NewFd), + {ok, NewDb#db{user_ctx = UserCtx, fd_monitor = NewRef}} + end. + ensure_full_commit(#db{main_pid=Pid, instance_start_time=StartTime}) -> ok = gen_server:call(Pid, full_commit, infinity), {ok, StartTime}. @@ -584,7 +596,8 @@ prep_and_validate_replicated_updates(Db, [Bucket|RestBuckets], [OldInfo|RestOldI {ok, #full_doc_info{rev_tree=OldTree}} -> NewRevTree = lists:foldl( fun(NewDoc, AccTree) -> - {NewTree, _} = couch_key_tree:merge(AccTree, [couch_db:doc_to_tree(NewDoc)]), + {NewTree, _} = couch_key_tree:merge(AccTree, + couch_db:doc_to_tree(NewDoc), Db#db.revs_limit), NewTree end, OldTree, Bucket), @@ -845,11 +858,12 @@ flush_att(Fd, #att{data={Fd0, _}}=Att) when Fd0 == Fd -> % already written to our file, nothing to write Att; -flush_att(Fd, #att{data={OtherFd,StreamPointer}, md5=InMd5}=Att) -> +flush_att(Fd, #att{data={OtherFd,StreamPointer}, md5=InMd5, + disk_len=InDiskLen} = Att) -> {NewStreamData, Len, _IdentityLen, Md5, IdentityMd5} = couch_stream:copy_to_new_stream(OtherFd, StreamPointer, Fd), check_md5(IdentityMd5, InMd5), - Att#att{data={Fd, NewStreamData}, md5=Md5, att_len=Len, disk_len=Len}; + Att#att{data={Fd, NewStreamData}, md5=Md5, att_len=Len, disk_len=InDiskLen}; flush_att(Fd, #att{data=Data}=Att) when is_binary(Data) -> with_stream(Fd, Att, fun(OutputStream) -> @@ -947,7 +961,7 @@ with_stream(Fd, #att{md5=InMd5,type=Type,encoding=Enc}=Att, Fun) -> write_streamed_attachment(_Stream, _F, 0) -> ok; -write_streamed_attachment(Stream, F, LenLeft) -> +write_streamed_attachment(Stream, F, LenLeft) when LenLeft > 0 -> Bin = F(), ok = couch_stream:write(Stream, Bin), write_streamed_attachment(Stream, F, LenLeft - size(Bin)). |