couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [1/4] couch commit: updated refs/heads/master to aa36a18
Date Wed, 04 Feb 2015 15:49:38 GMT
Repository: couchdb-couch
Updated Branches:
  refs/heads/master ad867d4ad -> aa36a185e


Update config_listener behaviuor

COUCHDB-2561


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/eee30441
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/eee30441
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/eee30441

Branch: refs/heads/master
Commit: eee30441bcb10bc40f3a5d2978c4e8518fe970d4
Parents: 8e473e1
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Thu Jan 29 12:39:47 2015 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Wed Feb 4 05:54:39 2015 -0800

----------------------------------------------------------------------
 src/couch_auth_cache.erl        | 16 +++++++---------
 src/couch_compaction_daemon.erl | 13 ++++++-------
 src/couch_external_manager.erl  | 21 +++++++++------------
 src/couch_external_server.erl   | 15 +++++++--------
 src/couch_httpd_vhost.erl       | 13 ++++++-------
 src/couch_os_daemons.erl        | 13 ++++++-------
 src/couch_proc_manager.erl      | 23 +++++++++++------------
 src/couch_server.erl            | 11 +++++++++--
 src/couch_sup.erl               |  8 +++++++-
 src/couch_uuids.erl             | 19 +++++++++++--------
 10 files changed, 79 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/eee30441/src/couch_auth_cache.erl
----------------------------------------------------------------------
diff --git a/src/couch_auth_cache.erl b/src/couch_auth_cache.erl
index e55ee17..e95d209 100644
--- a/src/couch_auth_cache.erl
+++ b/src/couch_auth_cache.erl
@@ -12,7 +12,7 @@
 
 -module(couch_auth_cache).
 -behaviour(gen_server).
--vsn(1).
+-vsn(2).
 -behaviour(config_listener).
 
 % public API
@@ -23,7 +23,7 @@
 -export([start_link/0, init/1, handle_call/3, handle_info/2, handle_cast/2]).
 -export([code_change/3, terminate/2]).
 
--export([handle_config_change/5]).
+-export([handle_config_change/5, handle_config_terminate/3]).
 -export([handle_db_event/3]).
 
 -include_lib("couch/include/couch_db.hrl").
@@ -231,16 +231,9 @@ handle_info(restart_event_listener, State) ->
             ?MODULE, handle_db_event, nil, [{dbname, AuthDbName}]
         ),
     {noreply, State#state{event_listener=NewListener}};
-handle_info({gen_event_EXIT, {config_listener, ?MODULE}, _Reason}, State) ->
-    erlang:send_after(5000, self(), restart_config_listener),
-    {noreply, State};
-handle_info(restart_config_listener, State) ->
-    ok = config:listen_for_changes(?MODULE, nil),
-    {noreply, State};
 handle_info({'DOWN', Ref, _, _, _Reason}, #state{db_mon_ref = Ref} = State) ->
     {noreply, reinit_cache(State)}.
 
-
 terminate(_Reason, #state{event_listener = Listener}) ->
     couch_event:stop_listener(Listener),
     exec_if_auth_db(fun(AuthDb) -> catch couch_db:close(AuthDb) end),
@@ -261,6 +254,11 @@ handle_config_change("couch_httpd_auth", "authentication_db", _DbName,
_, _) ->
 handle_config_change(_, _, _, _, _) ->
     {ok, nil}.
 
+handle_config_terminate(_, _, _) ->
+    spawn(fun() ->
+        timer:sleep(5000),
+        config:listen_for_changes(?MODULE, nil)
+    end).
 
 clear_cache(State) ->
     exec_if_auth_db(fun(AuthDb) -> catch couch_db:close(AuthDb) end),

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/eee30441/src/couch_compaction_daemon.erl
----------------------------------------------------------------------
diff --git a/src/couch_compaction_daemon.erl b/src/couch_compaction_daemon.erl
index 49c26f4..543db9f 100644
--- a/src/couch_compaction_daemon.erl
+++ b/src/couch_compaction_daemon.erl
@@ -22,7 +22,7 @@
 -export([code_change/3, terminate/2]).
 
 % config_listener api
--export([handle_config_change/5]).
+-export([handle_config_change/5, handle_config_terminate/3]).
 
 -include_lib("couch/include/couch_db.hrl").
 -include_lib("kernel/include/file.hrl").
@@ -86,12 +86,6 @@ handle_call(Msg, _From, State) ->
     {stop, {unexpected_call, Msg}, State}.
 
 
-handle_info({gen_event_EXIT, {config_listener, ?MODULE}, _Reason}, State) ->
-    erlang:send_after(5000, self(), restart_config_listener),
-    {noreply, State};
-handle_info(restart_config_listener, State) ->
-    ok = config:listen_for_changes(?MODULE, nil),
-    {noreply, State};
 handle_info({'EXIT', Pid, Reason}, #state{loop_pid = Pid} = State) ->
     {stop, {compaction_loop_died, Reason}, State}.
 
@@ -109,6 +103,11 @@ handle_config_change("compactions", DbName, Value, _, _) ->
 handle_config_change(_, _, _, _, _) ->
     {ok, nil}.
 
+handle_config_terminate(_, _, _) ->
+    spawn(fun() ->
+        timer:sleep(5000),
+        config:listen_for_changes(?MODULE, nil)
+    end).
 
 compact_loop(Parent) ->
     {ok, _} = couch_server:all_databases(

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/eee30441/src/couch_external_manager.erl
----------------------------------------------------------------------
diff --git a/src/couch_external_manager.erl b/src/couch_external_manager.erl
index 51c6125..a2eedbb 100644
--- a/src/couch_external_manager.erl
+++ b/src/couch_external_manager.erl
@@ -12,14 +12,14 @@
 
 -module(couch_external_manager).
 -behaviour(gen_server).
--vsn(1).
+-vsn(2).
 -behaviour(config_listener).
 
 -export([start_link/0, execute/2]).
 -export([init/1, terminate/2, code_change/3, handle_call/3, handle_cast/2, handle_info/2]).
 
 % config_listener api
--export([handle_config_change/5]).
+-export([handle_config_change/5, handle_config_terminate/3]).
 
 -include_lib("couch/include/couch_db.hrl").
 
@@ -41,6 +41,12 @@ handle_config_change("external", UrlName, _, _, _) ->
 handle_config_change(_, _, _, _, _) ->
     {ok, nil}.
 
+handle_config_terminate(_, _, _) ->
+    spawn(fun() ->
+        timer:sleep(5000),
+        config:listen_for_changes(?MODULE, nil)
+    end).
+
 % gen_server API
 
 init([]) ->
@@ -101,16 +107,7 @@ handle_info({'EXIT', Pid, Reason}, Handlers) ->
     % Remove Pid from the handlers table so we don't try closing
     % it a second time in terminate/2.
     ets:match_delete(Handlers, {'_', Pid}),
-    {stop, normal, Handlers};
-
-handle_info({gen_event_EXIT, {config_listener, ?MODULE}, _Reason}, State) ->
-    erlang:send_after(5000, self(), restart_config_listener),
-    {noreply, State};
-
-handle_info(restart_config_listener, State) ->
-    ok = config:listen_for_changes(?MODULE, nil),
-    {noreply, State}.
+    {stop, normal, Handlers}.
 
 code_change(_OldVsn, State, _Extra) ->
     {ok, State}.
-

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/eee30441/src/couch_external_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_external_server.erl b/src/couch_external_server.erl
index d5560b0..339e36f 100644
--- a/src/couch_external_server.erl
+++ b/src/couch_external_server.erl
@@ -12,14 +12,14 @@
 
 -module(couch_external_server).
 -behaviour(gen_server).
--vsn(1).
+-vsn(2).
 -behaviour(config_listener).
 
 -export([start_link/2, stop/1, execute/2]).
 -export([init/1, terminate/2, handle_call/3, handle_cast/2, handle_info/2, code_change/3]).
 
 % config_listener api
--export([handle_config_change/5]).
+-export([handle_config_change/5, handle_config_terminate/3]).
 
 -include_lib("couch/include/couch_db.hrl").
 
@@ -54,12 +54,6 @@ terminate(_Reason, {_Name, _Command, Pid}) ->
 handle_call({execute, JsonReq}, _From, {Name, Command, Pid}) ->
     {reply, couch_os_process:prompt(Pid, JsonReq), {Name, Command, Pid}}.
 
-handle_info({gen_event_EXIT, {config_listener, ?MODULE}, _Reason}, State) ->
-    erlang:send_after(5000, self(), restart_config_listener),
-    {noreply, State};
-handle_info(restart_config_listener, State) ->
-    ok = config:listen_for_changes(?MODULE, State),
-    {noreply, State};
 handle_info({'EXIT', _Pid, normal}, State) ->
     {noreply, State};
 handle_info({'EXIT', Pid, Reason}, {Name, Command, Pid}) ->
@@ -84,3 +78,8 @@ handle_config_change("couchdb", "os_process_timeout", NewTimeout, _, Pid)
->
 handle_config_change(_, _, _, _, Pid) ->
     {ok, Pid}.
 
+handle_config_terminate(_, _, _) ->
+    spawn(fun() ->
+        timer:sleep(5000),
+        config:listen_for_changes(?MODULE, nil)
+    end).

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/eee30441/src/couch_httpd_vhost.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_vhost.erl b/src/couch_httpd_vhost.erl
index 0f01294..67cfd03 100644
--- a/src/couch_httpd_vhost.erl
+++ b/src/couch_httpd_vhost.erl
@@ -21,7 +21,7 @@
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
 
 % config_listener api
--export([handle_config_change/5]).
+-export([handle_config_change/5, handle_config_terminate/3]).
 
 -include_lib("couch/include/couch_db.hrl").
 
@@ -355,12 +355,6 @@ handle_call(_Msg, _From, State) ->
 handle_cast(_Msg, State) ->
     {noreply, State}.
 
-handle_info({gen_event_EXIT, {config_listener, ?MODULE}, _Reason}, State) ->
-    erlang:send_after(5000, self(), restart_config_listener),
-    {noreply, State};
-handle_info(restart_config_listener, State) ->
-    ok = config:listen_for_changes(?MODULE, nil),
-    {noreply, State};
 handle_info(_Info, State) ->
     {noreply, State}.
 
@@ -380,6 +374,11 @@ handle_config_change("vhosts", _, _, _, _) ->
 handle_config_change(_, _, _, _, _) ->
     {ok, nil}.
 
+handle_config_terminate(_, _, _) ->
+    spawn(fun() ->
+        timer:sleep(5000),
+        config:listen_for_changes(?MODULE, nil)
+    end).
 
 load_conf() ->
     %% get vhost globals

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/eee30441/src/couch_os_daemons.erl
----------------------------------------------------------------------
diff --git a/src/couch_os_daemons.erl b/src/couch_os_daemons.erl
index 606d147..60dbcc3 100644
--- a/src/couch_os_daemons.erl
+++ b/src/couch_os_daemons.erl
@@ -19,7 +19,7 @@
 -export([handle_call/3, handle_cast/2, handle_info/2]).
 
 % config_listener api
--export([handle_config_change/5]).
+-export([handle_config_change/5, handle_config_terminate/3]).
 
 -include_lib("couch/include/couch_db.hrl").
 
@@ -82,12 +82,6 @@ handle_cast(Msg, Table) ->
     couch_log:error("Unknown cast message to ~p: ~p", [?MODULE, Msg]),
     {stop, error, Table}.
 
-handle_info({gen_event_EXIT, {config_listener, ?MODULE}, _Reason}, State) ->
-    erlang:send_after(5000, self(), restart_config_listener),
-    {noreply, State};
-handle_info(restart_config_listener, State) ->
-    ok = config:listen_for_changes(?MODULE, nil),
-    {noreply, State};
 handle_info({'EXIT', Port, Reason}, Table) ->
     case ets:lookup(Table, Port) of
         [] ->
@@ -201,6 +195,11 @@ handle_config_change(Section, Key, _, _, _) ->
     gen_server:cast(?MODULE, {config_change, Section, Key}),
     {ok, nil}.
 
+handle_config_terminate(_, _, _) ->
+    spawn(fun() ->
+        timer:sleep(5000),
+        config:listen_for_changes(?MODULE, nil)
+    end).
 
 % Internal API
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/eee30441/src/couch_proc_manager.erl
----------------------------------------------------------------------
diff --git a/src/couch_proc_manager.erl b/src/couch_proc_manager.erl
index 5bb154e..675b649 100644
--- a/src/couch_proc_manager.erl
+++ b/src/couch_proc_manager.erl
@@ -13,7 +13,7 @@
 -module(couch_proc_manager).
 -behaviour(gen_server).
 -behaviour(config_listener).
--vsn(1).
+-vsn(2).
 
 -export([
     start_link/0,
@@ -34,7 +34,8 @@
 ]).
 
 -export([
-    handle_config_change/5
+    handle_config_change/5,
+    handle_config_terminate/3
 ]).
 
 -include_lib("couch/include/couch_db.hrl").
@@ -262,16 +263,6 @@ handle_info({'DOWN', Ref, _, _, _Reason}, State0) ->
             {noreply, State0}
     end;
 
-handle_info({gen_event_EXIT, {config_listener, ?MODULE}, _Reason}, State) ->
-    erlang:send_after(5000, self(), restart_config_listener),
-    {noreply, State};
-
-handle_info(restart_config_listener, State) ->
-    ok = config:listen_for_changes(?MODULE, undefined),
-    % Reload our config in case it changed in the last
-    % five seconds.
-    handle_cast(reload, State);
-
 handle_info(_Msg, State) ->
     {noreply, State}.
 
@@ -279,6 +270,14 @@ handle_info(_Msg, State) ->
 code_change(_OldVsn, #state{}=State, _Extra) ->
     {ok, State}.
 
+handle_config_terminate(_, _, _) ->
+    spawn(fun() ->
+        timer:sleep(5000),
+        config:listen_for_changes(?MODULE, undefined),
+        % Reload our config in case it changed in the last
+        % five seconds.
+        gen_server:cast(?MODULE, reload_config)
+    end).
 
 handle_config_change("query_server_config", _, _, _, _) ->
     gen_server:cast(?MODULE, reload_config),

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/eee30441/src/couch_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_server.erl b/src/couch_server.erl
index 8f9696b..598df6a 100644
--- a/src/couch_server.erl
+++ b/src/couch_server.erl
@@ -13,7 +13,7 @@
 -module(couch_server).
 -behaviour(gen_server).
 -behaviour(config_listener).
--vsn(1).
+-vsn(2).
 
 -export([open/2,create/2,delete/2,get_version/0,get_version/1,get_uuid/0]).
 -export([all_databases/0, all_databases/2]).
@@ -23,7 +23,7 @@
 -export([close_lru/0]).
 
 % config_listener api
--export([handle_config_change/5]).
+-export([handle_config_change/5, handle_config_terminate/3]).
 
 -include_lib("couch/include/couch_db.hrl").
 
@@ -249,6 +249,13 @@ handle_config_change("httpd_db_handlers", _, _, _, _) ->
 handle_config_change(_, _, _, _, _) ->
     {ok, nil}.
 
+handle_config_terminate(_, _, _) ->
+    spawn(fun() ->
+        timer:sleep(5000),
+        config:listen_for_changes(?MODULE, nil)
+    end).
+
+
 
 all_databases() ->
     {ok, DbList} = all_databases(

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/eee30441/src/couch_sup.erl
----------------------------------------------------------------------
diff --git a/src/couch_sup.erl b/src/couch_sup.erl
index 467a1f5..c941a60 100644
--- a/src/couch_sup.erl
+++ b/src/couch_sup.erl
@@ -18,7 +18,8 @@
 -export([
     start_link/0,
     init/1,
-    handle_config_change/5
+    handle_config_change/5,
+    handle_config_terminate/3
 ]).
 
 
@@ -75,6 +76,11 @@ handle_config_change("couchdb", "util_driver_dir", _, _, _) ->
 handle_config_change(_, _, _, _, _) ->
     {ok, nil}.
 
+handle_config_terminate(_, _, _) ->
+    spawn(fun() ->
+        timer:sleep(5000),
+        config:listen_for_changes(?MODULE, undefined)
+    end).
 
 notify_starting() ->
     io:format("Apache CouchDB ~s is starting.~n", [

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/eee30441/src/couch_uuids.erl
----------------------------------------------------------------------
diff --git a/src/couch_uuids.erl b/src/couch_uuids.erl
index 2cee58b..36fa095 100644
--- a/src/couch_uuids.erl
+++ b/src/couch_uuids.erl
@@ -13,7 +13,7 @@
 -include_lib("couch/include/couch_db.hrl").
 
 -behaviour(gen_server).
--vsn(1).
+-vsn(2).
 -behaviour(config_listener).
 
 -export([start/0, stop/0]).
@@ -23,7 +23,7 @@
 -export([handle_call/3, handle_cast/2, handle_info/2]).
 
 % config_listener api
--export([handle_config_change/5]).
+-export([handle_config_change/5, handle_config_terminate/3]).
 
 start() ->
     gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
@@ -77,12 +77,6 @@ handle_cast(stop, State) ->
 handle_cast(_Msg, State) ->
     {noreply, State}.
 
-handle_info({gen_event_EXIT, {config_listener, ?MODULE}, _Reason}, State) ->
-    erlang:send_after(5000, self(), restart_config_listener),
-    {noreply, State};
-handle_info(restart_config_listener, State) ->
-    ok = config:listen_for_changes(?MODULE, nil),
-    {noreply, State};
 handle_info(_Info, State) ->
     {noreply, State}.
 
@@ -94,6 +88,15 @@ handle_config_change("uuids", _, _, _, _) ->
 handle_config_change(_, _, _, _, _) ->
     {ok, nil}.
 
+handle_config_terminate(Pid, _, _) ->
+    spawn(fun() ->
+        timer:sleep(5000),
+        config:listen_for_changes(?MODULE, undefined),
+        % Reload our config in case it changed in the last
+        % five seconds.
+        gen_server:cast(?MODULE, change)
+    end).
+
 new_prefix() ->
     couch_util:to_hex((crypto:rand_bytes(13))).
 


Mime
View raw message