You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by Benoit Chesneau <bc...@gmail.com> on 2013/02/22 22:49:01 UTC
Re: git commit: init:restart() is evil, /_restart is evil, kill -9 is awesome
actually shouldn't it be kill -QUIT rather ? kill -9 isn't catchable
by the vm and may leak from time to time.
On Fri, Feb 22, 2013 at 9:25 PM, <ja...@apache.org> wrote:
> Updated Branches:
> refs/heads/replace-init-restart-with-kill-dash-nine-booyah [created] 1c2031314
>
>
> init:restart() is evil, /_restart is evil, kill -9 is awesome
>
>
> Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
> Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/1c203131
> Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/1c203131
> Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/1c203131
>
> Branch: refs/heads/replace-init-restart-with-kill-dash-nine-booyah
> Commit: 1c2031314e19ce9099bf8dedd8f4a071021e261e
> Parents: e14a2e5
> Author: Jan Lehnardt <ja...@apache.org>
> Authored: Fri Feb 22 21:24:20 2013 +0100
> Committer: Jan Lehnardt <ja...@apache.org>
> Committed: Fri Feb 22 21:24:20 2013 +0100
>
> ----------------------------------------------------------------------
> etc/couchdb/default.ini.tpl.in | 1 -
> share/www/script/couch_test_runner.js | 22 +++++++++++++++-------
> src/couchdb/couch_httpd_misc_handlers.erl | 4 +---
> src/couchdb/couch_server_sup.erl | 3 ---
> 4 files changed, 16 insertions(+), 14 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/couchdb/blob/1c203131/etc/couchdb/default.ini.tpl.in
> ----------------------------------------------------------------------
> diff --git a/etc/couchdb/default.ini.tpl.in b/etc/couchdb/default.ini.tpl.in
> index 94bf2fe..5d68994 100644
> --- a/etc/couchdb/default.ini.tpl.in
> +++ b/etc/couchdb/default.ini.tpl.in
> @@ -152,7 +152,6 @@ _active_tasks = {couch_httpd_misc_handlers, handle_task_status_req}
> _config = {couch_httpd_misc_handlers, handle_config_req}
> _replicate = {couch_replicator_httpd, handle_req}
> _uuids = {couch_httpd_misc_handlers, handle_uuids_req}
> -_restart = {couch_httpd_misc_handlers, handle_restart_req}
> _stats = {couch_httpd_stats_handlers, handle_stats_req}
> _log = {couch_httpd_misc_handlers, handle_log_req}
> _session = {couch_httpd_auth, handle_session_req}
>
> http://git-wip-us.apache.org/repos/asf/couchdb/blob/1c203131/share/www/script/couch_test_runner.js
> ----------------------------------------------------------------------
> diff --git a/share/www/script/couch_test_runner.js b/share/www/script/couch_test_runner.js
> index c04e6b1..7920930 100644
> --- a/share/www/script/couch_test_runner.js
> +++ b/share/www/script/couch_test_runner.js
> @@ -444,13 +444,21 @@ function waitForRestart() {
> };
>
> function restartServer() {
> - var xhr;
> - try {
> - CouchDB.request("POST", "/_restart");
> - } catch(e) {
> - // this request may sometimes fail
> - }
> - waitForRestart();
> + var restart_fun = function() {
> + var xhr;
> + try {
> + CouchDB.request("POST", "/_restart");
> + } catch(e) {
> + // this request may sometimes fail
> + }
> + waitForRestart();
> + };
> + run_on_modified_server([
> + {
> + section: "httpd_global_handlers",
> + key: "_restart",
> + value: "{couch_httpd_misc_handlers, handle_restart_req}"
> + }], restart_fun);
> }
>
> // legacy functions for CouchDB < 1.2.0
>
> http://git-wip-us.apache.org/repos/asf/couchdb/blob/1c203131/src/couchdb/couch_httpd_misc_handlers.erl
> ----------------------------------------------------------------------
> diff --git a/src/couchdb/couch_httpd_misc_handlers.erl b/src/couchdb/couch_httpd_misc_handlers.erl
> index d1f947d..680086e 100644
> --- a/src/couchdb/couch_httpd_misc_handlers.erl
> +++ b/src/couchdb/couch_httpd_misc_handlers.erl
> @@ -97,9 +97,7 @@ handle_task_status_req(Req) ->
> handle_restart_req(#httpd{method='POST'}=Req) ->
> couch_httpd:validate_ctype(Req, "application/json"),
> ok = couch_httpd:verify_is_server_admin(Req),
> - Result = send_json(Req, 202, {[{ok, true}]}),
> - couch_server_sup:restart_core_server(),
> - Result;
> + os:cmd("kill -9 " ++ os:getpid());
> handle_restart_req(Req) ->
> send_method_not_allowed(Req, "POST").
>
>
> http://git-wip-us.apache.org/repos/asf/couchdb/blob/1c203131/src/couchdb/couch_server_sup.erl
> ----------------------------------------------------------------------
> diff --git a/src/couchdb/couch_server_sup.erl b/src/couchdb/couch_server_sup.erl
> index be3c3a3..f28f9d4 100644
> --- a/src/couchdb/couch_server_sup.erl
> +++ b/src/couchdb/couch_server_sup.erl
> @@ -30,9 +30,6 @@ start_link(IniFiles) ->
> {error, already_started}
> end.
>
> -restart_core_server() ->
> - init:restart().
> -
> couch_config_start_link_wrapper(IniFiles, FirstConfigPid) ->
> case is_process_alive(FirstConfigPid) of
> true ->
>
Re: git commit: init:restart() is evil, /_restart is evil, kill -9 is awesome
Posted by Jan Lehnardt <ja...@apache.org>.
On Feb 22, 2013, at 22:49 , Benoit Chesneau <bc...@gmail.com> wrote:
> actually shouldn't it be kill -QUIT rather ? kill -9 isn't catchable
> by the vm and may leak from time to time.
Good point about -9 being a bit too hard here. -QUIT didn’t actually
terminate the VM, so I tried -TERM. Seems to do the job :)
Also, I kept _restart, injecting a run_on_modified_server there didn’t
really work out.
>
> On Fri, Feb 22, 2013 at 9:25 PM, <ja...@apache.org> wrote:
>> Updated Branches:
>> refs/heads/replace-init-restart-with-kill-dash-nine-booyah [created] 1c2031314
>>
>>
>> init:restart() is evil, /_restart is evil, kill -9 is awesome
>>
>>
>> Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/1c203131
>> Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/1c203131
>> Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/1c203131
>>
>> Branch: refs/heads/replace-init-restart-with-kill-dash-nine-booyah
>> Commit: 1c2031314e19ce9099bf8dedd8f4a071021e261e
>> Parents: e14a2e5
>> Author: Jan Lehnardt <ja...@apache.org>
>> Authored: Fri Feb 22 21:24:20 2013 +0100
>> Committer: Jan Lehnardt <ja...@apache.org>
>> Committed: Fri Feb 22 21:24:20 2013 +0100
>>
>> ----------------------------------------------------------------------
>> etc/couchdb/default.ini.tpl.in | 1 -
>> share/www/script/couch_test_runner.js | 22 +++++++++++++++-------
>> src/couchdb/couch_httpd_misc_handlers.erl | 4 +---
>> src/couchdb/couch_server_sup.erl | 3 ---
>> 4 files changed, 16 insertions(+), 14 deletions(-)
>> ----------------------------------------------------------------------
>>
>>
>> http://git-wip-us.apache.org/repos/asf/couchdb/blob/1c203131/etc/couchdb/default.ini.tpl.in
>> ----------------------------------------------------------------------
>> diff --git a/etc/couchdb/default.ini.tpl.in b/etc/couchdb/default.ini.tpl.in
>> index 94bf2fe..5d68994 100644
>> --- a/etc/couchdb/default.ini.tpl.in
>> +++ b/etc/couchdb/default.ini.tpl.in
>> @@ -152,7 +152,6 @@ _active_tasks = {couch_httpd_misc_handlers, handle_task_status_req}
>> _config = {couch_httpd_misc_handlers, handle_config_req}
>> _replicate = {couch_replicator_httpd, handle_req}
>> _uuids = {couch_httpd_misc_handlers, handle_uuids_req}
>> -_restart = {couch_httpd_misc_handlers, handle_restart_req}
>> _stats = {couch_httpd_stats_handlers, handle_stats_req}
>> _log = {couch_httpd_misc_handlers, handle_log_req}
>> _session = {couch_httpd_auth, handle_session_req}
>>
>> http://git-wip-us.apache.org/repos/asf/couchdb/blob/1c203131/share/www/script/couch_test_runner.js
>> ----------------------------------------------------------------------
>> diff --git a/share/www/script/couch_test_runner.js b/share/www/script/couch_test_runner.js
>> index c04e6b1..7920930 100644
>> --- a/share/www/script/couch_test_runner.js
>> +++ b/share/www/script/couch_test_runner.js
>> @@ -444,13 +444,21 @@ function waitForRestart() {
>> };
>>
>> function restartServer() {
>> - var xhr;
>> - try {
>> - CouchDB.request("POST", "/_restart");
>> - } catch(e) {
>> - // this request may sometimes fail
>> - }
>> - waitForRestart();
>> + var restart_fun = function() {
>> + var xhr;
>> + try {
>> + CouchDB.request("POST", "/_restart");
>> + } catch(e) {
>> + // this request may sometimes fail
>> + }
>> + waitForRestart();
>> + };
>> + run_on_modified_server([
>> + {
>> + section: "httpd_global_handlers",
>> + key: "_restart",
>> + value: "{couch_httpd_misc_handlers, handle_restart_req}"
>> + }], restart_fun);
>> }
>>
>> // legacy functions for CouchDB < 1.2.0
>>
>> http://git-wip-us.apache.org/repos/asf/couchdb/blob/1c203131/src/couchdb/couch_httpd_misc_handlers.erl
>> ----------------------------------------------------------------------
>> diff --git a/src/couchdb/couch_httpd_misc_handlers.erl b/src/couchdb/couch_httpd_misc_handlers.erl
>> index d1f947d..680086e 100644
>> --- a/src/couchdb/couch_httpd_misc_handlers.erl
>> +++ b/src/couchdb/couch_httpd_misc_handlers.erl
>> @@ -97,9 +97,7 @@ handle_task_status_req(Req) ->
>> handle_restart_req(#httpd{method='POST'}=Req) ->
>> couch_httpd:validate_ctype(Req, "application/json"),
>> ok = couch_httpd:verify_is_server_admin(Req),
>> - Result = send_json(Req, 202, {[{ok, true}]}),
>> - couch_server_sup:restart_core_server(),
>> - Result;
>> + os:cmd("kill -9 " ++ os:getpid());
>> handle_restart_req(Req) ->
>> send_method_not_allowed(Req, "POST").
>>
>>
>> http://git-wip-us.apache.org/repos/asf/couchdb/blob/1c203131/src/couchdb/couch_server_sup.erl
>> ----------------------------------------------------------------------
>> diff --git a/src/couchdb/couch_server_sup.erl b/src/couchdb/couch_server_sup.erl
>> index be3c3a3..f28f9d4 100644
>> --- a/src/couchdb/couch_server_sup.erl
>> +++ b/src/couchdb/couch_server_sup.erl
>> @@ -30,9 +30,6 @@ start_link(IniFiles) ->
>> {error, already_started}
>> end.
>>
>> -restart_core_server() ->
>> - init:restart().
>> -
>> couch_config_start_link_wrapper(IniFiles, FirstConfigPid) ->
>> case is_process_alive(FirstConfigPid) of
>> true ->
>>