Author: kocolosk Date: Wed Jan 19 20:27:26 2011 New Revision: 1060969 URL: http://svn.apache.org/viewvc?rev=1060969&view=rev Log: Reorganize upper levels of supervision tree
* Primary and secondary supervisors get their own callback modules * Use a dedicated supervised process for ICU collation driver * Correct child specification for update notifier supervisor COUCHDB-1010 Added: couchdb/trunk/src/couchdb/couch_drv.erl couchdb/trunk/src/couchdb/couch_primary_sup.erl couchdb/trunk/src/couchdb/couch_secondary_sup.erl Modified: couchdb/trunk/etc/couchdb/default.ini.tpl.in couchdb/trunk/src/couchdb/Makefile.am couchdb/trunk/src/couchdb/couch_server_sup.erl couchdb/trunk/src/couchdb/couch_util.erl couchdb/trunk/test/etap/002-icu-driver.t (contents, props changed) Modified: couchdb/trunk/etc/couchdb/default.ini.tpl.in URL: http://svn.apache.org/viewvc/couchdb/trunk/etc/couchdb/default.ini.tpl.in?rev=1060969&r1=1060968&r2=1060969&view=diff ============================================================================== --- couchdb/trunk/etc/couchdb/default.ini.tpl.in (original) +++ couchdb/trunk/etc/couchdb/default.ini.tpl.in Wed Jan 19 20:27:26 2011 @@ -53,7 +53,6 @@ os_process_limit = 25 [daemons] view_manager={couch_view, start_link, []} external_manager={couch_external_manager, start_link, []} -db_update_notifier={couch_db_update_notifier_sup, start_link, []} query_servers={couch_query_servers, start_link, []} httpd={couch_httpd, start_link, []} stats_aggregator={couch_stats_aggregator, start, []} Modified: couchdb/trunk/src/couchdb/Makefile.am URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/Makefile.am?rev=1060969&r1=1060968&r2=1060969&view=diff ============================================================================== --- couchdb/trunk/src/couchdb/Makefile.am (original) +++ couchdb/trunk/src/couchdb/Makefile.am Wed Jan 19 20:27:26 2011 @@ -38,6 +38,7 @@ source_files = \ couch_db_update_notifier.erl \ couch_db_update_notifier_sup.erl \ couch_doc.erl \ + couch_drv.erl \ couch_event_sup.erl \ couch_external_manager.erl \ couch_external_server.erl \ @@ -59,6 +60,7 @@ source_files = \ couch_native_process.erl \ couch_os_daemons.erl \ couch_os_process.erl \ + couch_primary_sup.erl \ couch_query_servers.erl \ couch_ref_counter.erl \ couch_rep.erl \ @@ -70,6 +72,7 @@ source_files = \ couch_rep_sup.erl \ couch_rep_writer.erl \ couch_rep_db_listener.erl \ + couch_secondary_sup.erl \ couch_server.erl \ couch_server_sup.erl \ couch_stats_aggregator.erl \ @@ -100,6 +103,7 @@ compiled_files = \ couch_db_update_notifier.beam \ couch_db_update_notifier_sup.beam \ couch_doc.beam \ + couch_drv.beam \ couch_event_sup.beam \ couch_external_manager.beam \ couch_external_server.beam \ @@ -121,6 +125,7 @@ compiled_files = \ couch_native_process.beam \ couch_os_daemons.beam \ couch_os_process.beam \ + couch_primary_sup.beam \ couch_query_servers.beam \ couch_ref_counter.beam \ couch_rep.beam \ @@ -132,6 +137,7 @@ compiled_files = \ couch_rep_sup.beam \ couch_rep_writer.beam \ couch_rep_db_listener.beam \ + couch_secondary_sup.beam \ couch_server.beam \ couch_server_sup.beam \ couch_stats_aggregator.beam \ Added: couchdb/trunk/src/couchdb/couch_drv.erl URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_drv.erl?rev=1060969&view=auto ============================================================================== --- couchdb/trunk/src/couchdb/couch_drv.erl (added) +++ couchdb/trunk/src/couchdb/couch_drv.erl Wed Jan 19 20:27:26 2011 @@ -0,0 +1,62 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +-module(couch_drv). +-behaviour(gen_server). +-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, + code_change/3]). + +-export([start_link/0]). + +-include("couch_db.hrl"). + +start_link() -> + gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). + +init([]) -> + LibDir = util_driver_dir(), + case erl_ddll:load(LibDir, "couch_icu_driver") of + ok -> + {ok, nil}; + {error, already_loaded} -> + ?LOG_INFO("~p reloading couch_icu_driver", [?MODULE]), + ok = erl_ddll:reload(LibDir, "couch_icu_driver"), + {ok, nil}; + {error, Error} -> + {stop, erl_ddll:format_error(Error)} + end. + +handle_call(_Request, _From, State) -> + {reply, ok, State}. + +handle_cast(_Request, State) -> + {noreply, State}. + +handle_info(_Info, State) -> + {noreply, State}. + +terminate(_Reason, _State) -> + ok. + +code_change(_OldVsn, State, _Extra) -> + + {ok, State}. + + +% private API +util_driver_dir() -> + case couch_config:get("couchdb", "util_driver_dir", null) of + null -> + filename:join(couch_util:priv_dir(), "lib"); + LibDir0 -> + LibDir0 + end. Added: couchdb/trunk/src/couchdb/couch_primary_sup.erl URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_primary_sup.erl?rev=1060969&view=auto ============================================================================== --- couchdb/trunk/src/couchdb/couch_primary_sup.erl (added) +++ couchdb/trunk/src/couchdb/couch_primary_sup.erl Wed Jan 19 20:27:26 2011 @@ -0,0 +1,60 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +-module(couch_primary_sup). +-behaviour(supervisor). +-export([init/1, start_link/0]). + +start_link() -> + supervisor:start_link({local,couch_primary_services}, ?MODULE, []). + +init([]) -> + Children = [ + {collation_driver, + {couch_drv, start_link, []}, + permanent, + infinity, + supervisor, + [couch_drv]}, + {couch_task_status, + {couch_task_status, start_link, []}, + permanent, + brutal_kill, + worker, + [couch_task_status]}, + {couch_server, + {couch_server, sup_start_link, []}, + permanent, + brutal_kill, + worker, + [couch_server]}, + {couch_db_update_event, + {gen_event, start_link, [{local, couch_db_update}]}, + permanent, + brutal_kill, + worker, + dynamic}, + {couch_replication_supervisor, + {couch_rep_sup, start_link, []}, + permanent, + infinity, + supervisor, + [couch_rep_sup]}, + {couch_log, + {couch_log, start_link, []}, + permanent, + brutal_kill, + worker, + [couch_log]} + ], + {ok, {{one_for_one, 10, 3600}, Children}}. + Added: couchdb/trunk/src/couchdb/couch_secondary_sup.erl URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_secondary_sup.erl?rev=1060969&view=auto ============================================================================== --- couchdb/trunk/src/couchdb/couch_secondary_sup.erl (added) +++ couchdb/trunk/src/couchdb/couch_secondary_sup.erl Wed Jan 19 20:27:26 2011 @@ -0,0 +1,42 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +-module(couch_secondary_sup). +-behaviour(supervisor). +-export([init/1, start_link/0]). + +start_link() -> + supervisor:start_link({local,couch_secondary_services}, ?MODULE, []). + +init([]) -> + SecondarySupervisors = [ + {couch_db_update_notifier_sup, + {couch_db_update_notifier_sup, start_link, []}, + permanent, + infinity, + supervisor, + [couch_db_update_notifier_sup]} + ], + Children = SecondarySupervisors ++ [ + begin + {ok, {Module, Fun, Args}} = couch_util:parse_term(SpecStr), + + {list_to_atom(Name), + {Module, Fun, Args}, + permanent, + brutal_kill, + worker, + [Module]} + end + || {Name, SpecStr} + <- couch_config:get("daemons"), SpecStr /= ""], + {ok, {{one_for_one, 10, 3600}, Children}}. Modified: couchdb/trunk/src/couchdb/couch_server_sup.erl URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_server_sup.erl?rev=1060969&r1=1060968&r2=1060969&view=diff ============================================================================== --- couchdb/trunk/src/couchdb/couch_server_sup.erl (original) +++ couchdb/trunk/src/couchdb/couch_server_sup.erl Wed Jan 19 20:27:26 2011 @@ -15,7 +15,6 @@ -export([start_link/1,stop/0, couch_config_start_link_wrapper/2, - start_primary_services/0,start_secondary_services/0, restart_core_server/0, config_change/2]). -include("couch_db.hrl"). @@ -68,15 +67,6 @@ start_server(IniFiles) -> _ -> ok end, - LibDir = - case couch_config:get("couchdb", "util_driver_dir", null) of - null -> - filename:join(couch_util:priv_dir(), "lib"); - LibDir0 -> LibDir0 - end, - - ok = couch_util:start_driver(LibDir), - BaseChildSpecs = {{one_for_all, 10, 3600}, [{couch_config, @@ -86,17 +76,17 @@ start_server(IniFiles) -> worker, [couch_config]}, {couch_primary_services, - {couch_server_sup, start_primary_services, []}, + {couch_primary_sup, start_link, []}, permanent, infinity, supervisor, - [couch_server_sup]}, + [couch_primary_sup]}, {couch_secondary_services, - {couch_server_sup, start_secondary_services, []}, + {couch_secondary_sup, start_link, []}, permanent, infinity, supervisor, - [couch_server_sup]} + [couch_secondary_sup]} ]}, % ensure these applications are running @@ -126,60 +116,6 @@ start_server(IniFiles) -> {ok, Pid}. -start_primary_services() -> - supervisor:start_link({local, couch_primary_services}, couch_server_sup, - {{one_for_one, 10, 3600}, - [{couch_log, - {couch_log, start_link, []}, - permanent, - brutal_kill, - worker, - [couch_log]}, - {couch_replication_supervisor, - {couch_rep_sup, start_link, []}, - permanent, - infinity, - supervisor, - [couch_rep_sup]}, - {couch_task_status, - {couch_task_status, start_link, []}, - permanent, - brutal_kill, - worker, - [couch_task_status]}, - {couch_server, - {couch_server, sup_start_link, []}, - permanent, - 1000, - worker, - [couch_server]}, - {couch_db_update_event, - {gen_event, start_link, [{local, couch_db_update}]}, - permanent, - brutal_kill, - worker, - dynamic} - ] - }). - -start_secondary_services() -> - DaemonChildSpecs = [ - begin - {ok, {Module, Fun, Args}} = couch_util:parse_term(SpecStr), - - {list_to_atom(Name), - {Module, Fun, Args}, - permanent, - 1000, - worker, - [Module]} - end - || {Name, SpecStr} - <- couch_config:get("daemons"), SpecStr /= ""], - - supervisor:start_link({local, couch_secondary_services}, couch_server_sup, - {{one_for_one, 10, 3600}, DaemonChildSpecs}). - stop() -> catch exit(whereis(couch_server_sup), normal). Modified: couchdb/trunk/src/couchdb/couch_util.erl URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_util.erl?rev=1060969&r1=1060968&r2=1060969&view=diff ============================================================================== --- couchdb/trunk/src/couchdb/couch_util.erl (original) +++ couchdb/trunk/src/couchdb/couch_util.erl Wed Jan 19 20:27:26 2011 @@ -12,7 +12,7 @@ -module(couch_util). --export([priv_dir/0, start_driver/1, normpath/1]). +-export([priv_dir/0, normpath/1]). -export([should_flush/0, should_flush/1, to_existing_atom/1]). -export([rand32/0, implode/2, collate/2, collate/3]). -export([abs_pathname/1,abs_pathname/2, trim/1]). @@ -44,16 +44,6 @@ priv_dir() -> Dir -> Dir end. -start_driver(LibDir) -> - case erl_ddll:load_driver(LibDir, "couch_icu_driver") of - ok -> - ok; - {error, already_loaded} -> - ok = erl_ddll:reload_driver(LibDir, "couch_icu_driver"); - {error, Error} -> - exit(erl_ddll:format_error(Error)) - end. - % Normalize a pathname by removing .. and . components. normpath(Path) -> normparts(filename:split(Path), []). Modified: couchdb/trunk/test/etap/002-icu-driver.t URL: http://svn.apache.org/viewvc/couchdb/trunk/test/etap/002-icu-driver.t?rev=1060969&r1=1060968&r2=1060969&view=diff ============================================================================== --- couchdb/trunk/test/etap/002-icu-driver.t (original) +++ couchdb/trunk/test/etap/002-icu-driver.t Wed Jan 19 20:27:26 2011 @@ -11,12 +11,15 @@ % License for the specific language governing permissions and limitations under % the License. +default_config() -> + test_util:build_file("etc/couchdb/default_dev.ini"). main(_) -> test_util:init_code_path(), + couch_config:start_link([default_config()]), etap:plan(3), etap:is( - couch_util:start_driver("src/couchdb/priv/.libs"), + element(1, couch_drv:start_link()), ok, "Started couch_icu_driver." ), Propchange: couchdb/trunk/test/etap/002-icu-driver.t ------------------------------------------------------------------------------ svn:executable = *