couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r939009 - in /couchdb/trunk/src/couchdb: couch_db_updater.erl couch_ref_counter.erl
Date Wed, 28 Apr 2010 16:54:27 GMT
Author: damien
Date: Wed Apr 28 16:54:26 2010
New Revision: 939009

URL: http://svn.apache.org/viewvc?rev=939009&view=rev
Log:
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.

Modified:
    couchdb/trunk/src/couchdb/couch_db_updater.erl
    couchdb/trunk/src/couchdb/couch_ref_counter.erl

Modified: couchdb/trunk/src/couchdb/couch_db_updater.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_db_updater.erl?rev=939009&r1=939008&r2=939009&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_db_updater.erl (original)
+++ couchdb/trunk/src/couchdb/couch_db_updater.erl Wed Apr 28 16:54:26 2010
@@ -856,8 +856,8 @@ start_copy_compact(#db{name=Name,filepat
         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}).
 

Modified: couchdb/trunk/src/couchdb/couch_ref_counter.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_ref_counter.erl?rev=939009&r1=939008&r2=939009&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_ref_counter.erl (original)
+++ couchdb/trunk/src/couchdb/couch_ref_counter.erl Wed Apr 28 16:54:26 2010
@@ -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{refer
     {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=
     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.



Mime
View raw message