diff options
author | Damien F. Katz <damien@apache.org> | 2010-04-28 16:54:26 +0000 |
---|---|---|
committer | Damien F. Katz <damien@apache.org> | 2010-04-28 16:54:26 +0000 |
commit | 6b26fd1f09be1e50c7c17d6fcc8f61f1c1a4ba37 (patch) | |
tree | 38a7cb967c5f2a8ce90e70a94d8e2a4ea79743c5 /src | |
parent | 1f919c38279deeeae69baf01f801017f7de45f9f (diff) |
Fix to make dbclose synchronous, to prevent unnecessary slowdown caused by many already completed client requests having a single db open, and the vm waiting a long time to asynchronously process the close messages.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@939009 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/couchdb/couch_db_updater.erl | 6 | ||||
-rw-r--r-- | src/couchdb/couch_ref_counter.erl | 41 |
2 files changed, 25 insertions, 22 deletions
diff --git a/src/couchdb/couch_db_updater.erl b/src/couchdb/couch_db_updater.erl index b9945e3b..efa44895 100644 --- a/src/couchdb/couch_db_updater.erl +++ b/src/couchdb/couch_db_updater.erl @@ -856,8 +856,8 @@ start_copy_compact(#db{name=Name,filepath=Filepath}=Db) -> ok = couch_file:write_header(Fd, Header=#db_header{}) end, NewDb = init_db(Name, CompactFile, Fd, Header), + unlink(Fd), NewDb2 = copy_compact(Db, NewDb, Retry), - - gen_server:cast(Db#db.update_pid, {compact_done, CompactFile}), - close_db(NewDb2). + close_db(NewDb2), + gen_server:cast(Db#db.update_pid, {compact_done, CompactFile}). diff --git a/src/couchdb/couch_ref_counter.erl b/src/couchdb/couch_ref_counter.erl index 96d92333..5a111ab6 100644 --- a/src/couchdb/couch_ref_counter.erl +++ b/src/couchdb/couch_ref_counter.erl @@ -24,7 +24,7 @@ drop(RefCounterPid) -> drop(RefCounterPid, self()). drop(RefCounterPid, Pid) -> - gen_server:cast(RefCounterPid, {drop, Pid}). + gen_server:call(RefCounterPid, {drop, Pid}). add(RefCounterPid) -> @@ -66,10 +66,8 @@ handle_call({add, Pid},_From, #srv{referrers=Referrers}=Srv) -> {reply, ok, Srv#srv{referrers=Referrers2}}; handle_call(count, _From, Srv) -> {monitors, Monitors} = process_info(self(), monitors), - {reply, length(Monitors), Srv}. - - -handle_cast({drop, Pid}, #srv{referrers=Referrers}=Srv) -> + {reply, length(Monitors), Srv}; +handle_call({drop, Pid}, _From, #srv{referrers=Referrers}=Srv) -> Referrers2 = case dict:find(Pid, Referrers) of {ok, {MonRef, 1}} -> @@ -80,7 +78,16 @@ handle_cast({drop, Pid}, #srv{referrers=Referrers}=Srv) -> error -> Referrers end, - maybe_close_async(Srv#srv{referrers=Referrers2}). + Srv2 = Srv#srv{referrers=Referrers2}, + case should_close() of + true -> + {stop,normal,ok,Srv2}; + false -> + {reply, ok, Srv2} + end. + +handle_cast(Msg, _Srv)-> + exit({unknown_msg,Msg}). code_change(_OldVsn, State, _Extra) -> @@ -88,21 +95,17 @@ code_change(_OldVsn, State, _Extra) -> handle_info({'DOWN', MonRef, _, Pid, _}, #srv{referrers=Referrers}=Srv) -> {ok, {MonRef, _RefCount}} = dict:find(Pid, Referrers), - maybe_close_async(Srv#srv{referrers=dict:erase(Pid, Referrers)}). + Srv2 = Srv#srv{referrers=dict:erase(Pid, Referrers)}, + case should_close() of + true -> + {stop,normal,Srv2}; + false -> + {noreply,Srv2} + end. should_close() -> case process_info(self(), monitors) of - {monitors, []} -> - true; - _ -> - false - end. - -maybe_close_async(Srv) -> - case should_close() of - true -> - {stop,normal,Srv}; - false -> - {noreply,Srv} + {monitors, []} -> true; + _ -> false end. |