nickva commented on a change in pull request #539: Close idle dbs
URL: https://github.com/apache/couchdb/pull/539#discussion_r119715063
##########
File path: src/couch/src/couch_db_updater.erl
##########
@@ -314,30 +320,46 @@ handle_info({update_docs, Client, GroupedDocs,
NonRepDocs, MergeConflicts,
false ->
Db2
end,
- {noreply, Db3, hibernate}
+ {noreply, Db3, hibernate_if_no_idle_limit()}
catch
throw: retry ->
[catch(ClientPid ! {retry, self()}) || ClientPid <- Clients],
- {noreply, Db, hibernate}
+ {noreply, Db, hibernate_if_no_idle_limit()}
end;
handle_info(delayed_commit, #db{waiting_delayed_commit=nil}=Db) ->
%no outstanding delayed commits, ignore
- {noreply, Db};
+ {noreply, Db, idle_limit()};
handle_info(delayed_commit, Db) ->
case commit_data(Db) of
Db ->
- {noreply, Db};
+ {noreply, Db, idle_limit()};
Db2 ->
ok = gen_server:call(couch_server, {db_updated, Db2}, infinity),
- {noreply, Db2}
+ {noreply, Db2, idle_limit()}
end;
handle_info({'EXIT', _Pid, normal}, Db) ->
- {noreply, Db};
+ {noreply, Db, idle_limit()};
handle_info({'EXIT', _Pid, Reason}, Db) ->
{stop, Reason, Db};
handle_info({'DOWN', Ref, _, _, Reason}, #db{fd_monitor=Ref, name=Name} = Db)
->
couch_log:error("DB ~s shutting down - Fd ~p", [Name, Reason]),
- {stop, normal, Db#db{fd=undefined, fd_monitor=closed}}.
+ {stop, normal, Db#db{fd=undefined, fd_monitor=closed}};
+handle_info(timeout, #db{fd=Fd, name=DbName} = Db) ->
+ update_idle_limit_from_config(),
+ case couch_db:is_idle(Db) of
+ true ->
+ case couch_file:last_read(Fd) * 1000 > idle_limit() of
+ true ->
+ ok = couch_server:close_db_if_idle(DbName);
+ false ->
+ ok
+ end;
+ false ->
+ ok
+ end,
+ gen_server:cast(self(), wakeup),
Review comment:
Yes it's to do a forced garbage collection. I thought of calling gc there
instead but according to Paul hibernate is more thorough. I didn't measure the
effect of this though. Maybe since we are already closing idle dbs, it's not
worth doing the extra work and just stick with a simple gc.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services