summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_server.erl
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2010-08-04 16:59:47 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2010-08-04 16:59:47 +0000
commit8446f0c3a69f7925d9104fd4487175c618b5a9dc (patch)
tree6a517f1d9fed824d5262eb5218021cdec3a08a07 /src/couchdb/couch_server.erl
parent9dc7b8387931ca604703f5e3142c4b02112ac6ad (diff)
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
Diffstat (limited to 'src/couchdb/couch_server.erl')
-rw-r--r--src/couchdb/couch_server.erl19
1 files changed, 12 insertions, 7 deletions
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() ->