From 8446f0c3a69f7925d9104fd4487175c618b5a9dc Mon Sep 17 00:00:00 2001 From: Filipe David Borba Manana Date: Wed, 4 Aug 2010 16:59:47 +0000 Subject: 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). git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@982328 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_server.erl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/couchdb/couch_server.erl') diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl index 88bd6107..0f8f66f3 100644 --- a/src/couchdb/couch_server.erl +++ b/src/couchdb/couch_server.erl @@ -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() -> -- cgit v1.2.3