From 6b26fd1f09be1e50c7c17d6fcc8f61f1c1a4ba37 Mon Sep 17 00:00:00 2001 From: "Damien F. Katz" Date: Wed, 28 Apr 2010 16:54:26 +0000 Subject: 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 --- src/couchdb/couch_ref_counter.erl | 41 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'src/couchdb/couch_ref_counter.erl') 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. -- cgit v1.2.3