couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r1060968 - in /couchdb/trunk/src/couchdb: couch_db_update_notifier_sup.erl couch_external_manager.erl couch_query_servers.erl couch_server_sup.erl
Date Wed, 19 Jan 2011 20:27:17 GMT
Author: kocolosk
Date: Wed Jan 19 20:27:17 2011
New Revision: 1060968

URL: http://svn.apache.org/viewvc?rev=1060968&view=rev
Log:
Fix multiple bugs in config change event handlers

* Use exported functions to allow hot upgrades w/o killing couch_config
* Register async in couch_query_servers to prevent restart deadlock
* Avoid couch_server_sup:stop() because it does nothing

See COUCHDB-1010

Modified:
    couchdb/trunk/src/couchdb/couch_db_update_notifier_sup.erl
    couchdb/trunk/src/couchdb/couch_external_manager.erl
    couchdb/trunk/src/couchdb/couch_query_servers.erl
    couchdb/trunk/src/couchdb/couch_server_sup.erl

Modified: couchdb/trunk/src/couchdb/couch_db_update_notifier_sup.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_db_update_notifier_sup.erl?rev=1060968&r1=1060967&r2=1060968&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_db_update_notifier_sup.erl (original)
+++ couchdb/trunk/src/couchdb/couch_db_update_notifier_sup.erl Wed Jan 19 20:27:17 2011
@@ -22,16 +22,14 @@
 
 -behaviour(supervisor).
 
--export([start_link/0,init/1]).
+-export([start_link/0, init/1, config_change/3]).
 
 start_link() ->
     supervisor:start_link({local, couch_db_update_notifier_sup},
         couch_db_update_notifier_sup, []).
 
 init([]) ->
-    ok = couch_config:register(
-        fun("update_notification", Key, Value) -> reload_config(Key, Value) end
-    ),
+    ok = couch_config:register(fun ?MODULE:config_change/3),
 
     UpdateNotifierExes = couch_config:get("update_notification"),
 
@@ -48,7 +46,7 @@ init([]) ->
 
 %% @doc when update_notification configuration changes, terminate the process
 %%      for that notifier and start a new one with the updated config
-reload_config(Id, Exe) ->
+config_change("update_notification", Id, Exe) ->
     ChildSpec = {
         Id,
         {couch_db_update_notifier, start_link, [Exe]},

Modified: couchdb/trunk/src/couchdb/couch_external_manager.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_external_manager.erl?rev=1060968&r1=1060967&r2=1060968&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_external_manager.erl (original)
+++ couchdb/trunk/src/couchdb/couch_external_manager.erl Wed Jan 19 20:27:17 2011
@@ -39,7 +39,7 @@ config_change("external", UrlName) ->
 init([]) ->
     process_flag(trap_exit, true),
     Handlers = ets:new(couch_external_manager_handlers, [set, private]),
-    couch_config:register(fun config_change/2),
+    couch_config:register(fun ?MODULE:config_change/2),
     {ok, Handlers}.
 
 terminate(_Reason, Handlers) ->

Modified: couchdb/trunk/src/couchdb/couch_query_servers.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_query_servers.erl?rev=1060968&r1=1060967&r2=1060968&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_query_servers.erl (original)
+++ couchdb/trunk/src/couchdb/couch_query_servers.erl Wed Jan 19 20:27:17 2011
@@ -13,7 +13,7 @@
 -module(couch_query_servers).
 -behaviour(gen_server).
 
--export([start_link/0]).
+-export([start_link/0, config_change/1]).
 
 -export([init/1, terminate/2, handle_call/3, handle_cast/2, handle_info/2,code_change/3]).
 -export([start_doc_map/3, map_docs/2, stop_doc_map/1]).
@@ -265,26 +265,9 @@ with_ddoc_proc(#doc{id=DDocId,revs={Star
     end.
 
 init([]) ->
-    % read config and register for configuration changes
-
-    % just stop if one of the config settings change. couch_server_sup
-    % will restart us and then we will pick up the new settings.
-
-    ok = couch_config:register(
-        fun("query_servers" ++ _, _) ->
-            supervisor:terminate_child(couch_secondary_services, query_servers),
-            supervisor:restart_child(couch_secondary_services, query_servers)
-        end),
-    ok = couch_config:register(
-        fun("native_query_servers" ++ _, _) ->
-            supervisor:terminate_child(couch_secondary_services, query_servers),
-            [supervisor:restart_child(couch_secondary_services, query_servers)]
-        end),
-    ok = couch_config:register(
-        fun("query_server_config" ++ _, _) ->
-            supervisor:terminate_child(couch_secondary_services, query_servers),
-            supervisor:restart_child(couch_secondary_services, query_servers)
-        end),
+    % register async to avoid deadlock on restart_child
+    Self = self(),
+    spawn(couch_config, register, [fun ?MODULE:config_change/1, Self]),
 
     Langs = ets:new(couch_query_server_langs, [set, private]),
     LangLimits = ets:new(couch_query_server_lang_limits, [set, private]),
@@ -394,6 +377,16 @@ handle_info({'EXIT', Pid, Status}, #qser
 code_change(_OldVsn, State, _Extra) ->
     {ok, State}.
 
+config_change("query_servers") ->
+    supervisor:terminate_child(couch_secondary_services, query_servers),
+    supervisor:restart_child(couch_secondary_services, query_servers);
+config_change("native_query_servers") ->
+    supervisor:terminate_child(couch_secondary_services, query_servers),
+    supervisor:restart_child(couch_secondary_services, query_servers);
+config_change("query_server_config") ->
+    supervisor:terminate_child(couch_secondary_services, query_servers),
+    supervisor:restart_child(couch_secondary_services, query_servers).
+
 % Private API
 
 add_to_waitlist(Info, From, #qserver{waitlist=Waitlist}=Server) ->

Modified: couchdb/trunk/src/couchdb/couch_server_sup.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_server_sup.erl?rev=1060968&r1=1060967&r2=1060968&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_server_sup.erl (original)
+++ couchdb/trunk/src/couchdb/couch_server_sup.erl Wed Jan 19 20:27:17 2011
@@ -16,7 +16,7 @@
 
 -export([start_link/1,stop/0, couch_config_start_link_wrapper/2,
         start_primary_services/0,start_secondary_services/0,
-        restart_core_server/0]).
+        restart_core_server/0, config_change/2]).
 
 -include("couch_db.hrl").
 
@@ -108,13 +108,7 @@ start_server(IniFiles) ->
 
     % launch the icu bridge
     % just restart if one of the config settings change.
-
-    couch_config:register(
-        fun("couchdb", "util_driver_dir") ->
-            ?MODULE:stop();
-        ("daemons", _) ->
-            ?MODULE:stop()
-        end, Pid),
+    couch_config:register(fun ?MODULE:config_change/2, Pid),
 
     unlink(ConfigPid),
 
@@ -189,5 +183,11 @@ start_secondary_services() ->
 stop() ->
     catch exit(whereis(couch_server_sup), normal).
 
+config_change("daemons", _) ->
+    supervisor:terminate_child(couch_server_sup, couch_secondary_services),
+    supervisor:restart_child(couch_server_sup, couch_secondary_services);
+config_change("couchdb", "util_driver_dir") ->
+    init:restart().
+
 init(ChildSpecs) ->
     {ok, ChildSpecs}.



Mime
View raw message