You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by fd...@apache.org on 2010/08/04 18:59:47 UTC

svn commit: r982328 - /couchdb/trunk/src/couchdb/couch_server.erl

Author: fdmanana
Date: Wed Aug  4 16:59:47 2010
New Revision: 982328

URL: http://svn.apache.org/viewvc?rev=982328&view=rev
Log:
Don't close an idle system DB to open a non-system DB. Doing so allowed us to open more than max_open_dbs non-system DBs.
This issue is revealed when there are more than 1 system DBs (_users and _replicator).


Modified:
    couchdb/trunk/src/couchdb/couch_server.erl

Modified: couchdb/trunk/src/couchdb/couch_server.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_server.erl?rev=982328&r1=982327&r2=982328&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_server.erl (original)
+++ couchdb/trunk/src/couchdb/couch_server.erl Wed Aug  4 16:59:47 2010
@@ -192,12 +192,7 @@ try_close_lru(StartTime) ->
         [{_, {opened, MainPid, LruTime}}] = ets:lookup(couch_dbs_by_name, DbName),
         case couch_db:is_idle(MainPid) of
         true ->
-            couch_util:shutdown_sync(MainPid),
-            true = ets:delete(couch_dbs_by_lru, LruTime),
-            true = ets:delete(couch_dbs_by_name, DbName),
-            true = ets:delete(couch_dbs_by_pid, MainPid),
-            true = ets:delete(couch_sys_dbs, DbName),
-            ok;
+            ok = shutdown_idle_db(DbName, MainPid, LruTime);
         false ->
             % this still has referrers. Go ahead and give it a current lru time
             % and try the next one in the table.
@@ -222,12 +217,22 @@ get_lru(LruTime) ->
         [{_, {opened, MainPid, _}}] = ets:lookup(couch_dbs_by_name, DbName),
         case couch_db:is_idle(MainPid) of
         true ->
-            LruTime;
+            NextLru = ets:next(couch_dbs_by_lru, LruTime),
+            ok = shutdown_idle_db(DbName, MainPid, LruTime),
+            get_lru(NextLru);
         false ->
             get_lru(ets:next(couch_dbs_by_lru, LruTime))
         end
     end.
 
+shutdown_idle_db(DbName, MainPid, LruTime) ->
+    couch_util:shutdown_sync(MainPid),
+    true = ets:delete(couch_dbs_by_lru, LruTime),
+    true = ets:delete(couch_dbs_by_name, DbName),
+    true = ets:delete(couch_dbs_by_pid, MainPid),
+    true = ets:delete(couch_sys_dbs, DbName),
+    ok.
+
 open_async(Server, From, DbName, Filepath, Options) ->
     Parent = self(),
     Opener = spawn_link(fun() ->