You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ii...@apache.org on 2016/08/23 22:04:07 UTC
[1/3] couch-index commit: updated refs/heads/master to ee21d01
Repository: couchdb-couch-index
Updated Branches:
refs/heads/master 7d3d34f22 -> ee21d0181
Update handle_config_terminate API
COUCHDB-3102
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/commit/72dfb850
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/72dfb850
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/72dfb850
Branch: refs/heads/master
Commit: 72dfb8507f95a540bf4eb167605d63d0de77a172
Parents: 7d3d34f
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Wed Aug 17 11:50:54 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Aug 23 12:24:41 2016 -0700
----------------------------------------------------------------------
src/couch_index.erl | 34 ++++++++++++----------------------
src/couch_index_server.erl | 19 ++++++++++---------
2 files changed, 22 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/72dfb850/src/couch_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_index.erl b/src/couch_index.erl
index b6a6c99..fdc7246 100644
--- a/src/couch_index.erl
+++ b/src/couch_index.erl
@@ -12,9 +12,8 @@
-module(couch_index).
-behaviour(gen_server).
--behaviour(config_listener).
--vsn(1).
+-vsn(2).
%% API
-export([start_link/1, stop/1, get_state/2, get_info/1]).
@@ -26,15 +25,12 @@
-export([init/1, terminate/2, code_change/3]).
-export([handle_call/3, handle_cast/2, handle_info/2]).
-% config_listener api
--export([handle_config_change/5, handle_config_terminate/3]).
-
-include_lib("couch/include/couch_db.hrl").
-define(CHECK_INTERVAL, 600000). % 10 minutes
-
+-define(RELISTEN_DELAY, 5000).
-record(st, {
mod,
@@ -89,7 +85,7 @@ config_change("query_server_config", "commit_freq", NewValue) ->
init({Mod, IdxState}) ->
- ok = config:listen_for_changes(?MODULE, nil),
+ ok = config:subscribe_for_changes([{"query_server_config", "commit_freq"}]),
DbName = Mod:get(db_name, IdxState),
erlang:send_after(?CHECK_INTERVAL, self(), maybe_close),
Resp = couch_util:with_db(DbName, fun(Db) ->
@@ -344,25 +340,19 @@ handle_info({'DOWN', _, _, _Pid, _}, #st{mod=Mod, idx_state=IdxState}=State) ->
Args = [Mod:get(db_name, IdxState), Mod:get(idx_name, IdxState)],
couch_log:info("Index shutdown by monitor notice for db: ~s idx: ~s", Args),
catch send_all(State#st.waiters, shutdown),
- {stop, normal, State#st{waiters=[]}}.
-
+ {stop, normal, State#st{waiters=[]}};
+handle_info({config_change, "query_server_config", "commit_freq", NewDelay, _}, State) ->
+ handle_cast({config_change, NewDelay}, State);
+handle_info({gen_event_EXIT, _Handler, _Reason}, State) ->
+ erlang:send_after(?RELISTEN_DELAY, self(), restart_config_listener),
+ {noreply, State};
+handle_info(restart_config_listener, State) ->
+ ok = config:subscribe_for_changes([{"query_server_config", "commit_freq"}]),
+ {noreply, State}.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
-
-handle_config_change("query_server_config", "commit_freq", Val, _, _) ->
- {ok, gen_server:cast(?MODULE, {config_update, Val})};
-handle_config_change(_, _, _, _, _) ->
- {ok, nil}.
-
-handle_config_terminate(_Server, stop, _State) -> ok;
-handle_config_terminate(_Server, _Reason, _State) ->
- spawn(fun() ->
- timer:sleep(5000),
- config:listen_for_changes(?MODULE, nil)
- end).
-
maybe_restart_updater(#st{waiters=[]}) ->
ok;
maybe_restart_updater(#st{mod=Mod, idx_state=IdxState}=State) ->
http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/72dfb850/src/couch_index_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_server.erl b/src/couch_index_server.erl
index ac2c609..4e86f5e 100644
--- a/src/couch_index_server.erl
+++ b/src/couch_index_server.erl
@@ -14,7 +14,7 @@
-behaviour(gen_server).
-behaviour(config_listener).
--vsn(1).
+-vsn(2).
-export([start_link/0, validate/2, get_index/4, get_index/3, get_index/2]).
@@ -33,7 +33,7 @@
-define(BY_SIG, couchdb_indexes_by_sig).
-define(BY_PID, couchdb_indexes_by_pid).
-define(BY_DB, couchdb_indexes_by_db).
-
+-define(RELISTEN_DELAY, 5000).
-record(st, {root_dir}).
@@ -115,7 +115,7 @@ get_index(Module, IdxState) ->
init([]) ->
process_flag(trap_exit, true),
- ok = config:listen_for_changes(?MODULE, nil),
+ ok = config:listen_for_changes(?MODULE, couch_index_util:root_dir()),
ets:new(?BY_SIG, [protected, set, named_table]),
ets:new(?BY_PID, [private, set, named_table]),
ets:new(?BY_DB, [protected, bag, named_table]),
@@ -175,6 +175,9 @@ handle_info({'EXIT', Pid, Reason}, Server) ->
ok
end,
{noreply, Server};
+handle_info(restart_config_listener, State) ->
+ ok = config:listen_for_changes(?MODULE, couch_index_util:root_dir()),
+ {noreply, State};
handle_info(Msg, State) ->
couch_log:warning("~p did not expect ~p", [?MODULE, Msg]),
{noreply, State}.
@@ -197,13 +200,11 @@ handle_config_change("couchdb", "view_index_dir", _, _, _) ->
handle_config_change(_, _, _, _, RootDir) ->
{ok, RootDir}.
-handle_config_terminate(_Server, stop, _State) -> ok;
+handle_config_terminate(_, stop, _) ->
+ ok;
handle_config_terminate(_Server, _Reason, _State) ->
- State = couch_index_util:root_dir(),
- spawn(fun() ->
- timer:sleep(5000),
- config:listen_for_changes(?MODULE, State)
- end).
+ erlang:send_after(?RELISTEN_DELAY, whereis(?MODULE), restart_config_listener),
+ {ok, couch_index_util:root_dir()}.
new_index({Mod, IdxState, DbName, Sig}) ->
DDocId = Mod:get(idx_name, IdxState),
[3/3] couch-index commit: updated refs/heads/master to ee21d01
Posted by ii...@apache.org.
Merge remote branch 'cloudant:3102-fix-config_subscription'
This closes #18
Signed-off-by: ILYA Khlopotov <ii...@ca.ibm.com>
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/commit/ee21d018
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/ee21d018
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/ee21d018
Branch: refs/heads/master
Commit: ee21d0181f0879bf9ab2dc6d67cc5c26c7c76628
Parents: 7d3d34f 7b82753
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Aug 23 14:59:39 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Aug 23 14:59:39 2016 -0700
----------------------------------------------------------------------
src/couch_index.erl | 35 +++++++++++++----------------------
src/couch_index_server.erl | 19 ++++++++++---------
2 files changed, 23 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
[2/3] couch-index commit: updated refs/heads/master to ee21d01
Posted by ii...@apache.org.
Use `define` to avoid repeating yourself
COUCHDB-3102
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/commit/7b827534
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/7b827534
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/7b827534
Branch: refs/heads/master
Commit: 7b827534e8e5f7d1cb8dd2cebd0ec003165690b2
Parents: 72dfb85
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Aug 23 13:17:31 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Aug 23 13:17:31 2016 -0700
----------------------------------------------------------------------
src/couch_index.erl | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/7b827534/src/couch_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_index.erl b/src/couch_index.erl
index fdc7246..a5958b9 100644
--- a/src/couch_index.erl
+++ b/src/couch_index.erl
@@ -31,6 +31,7 @@
-define(CHECK_INTERVAL, 600000). % 10 minutes
-define(RELISTEN_DELAY, 5000).
+-define(CONFIG_SUBSCRIPTION, [{"query_server_config", "commit_freq"}]).
-record(st, {
mod,
@@ -85,7 +86,7 @@ config_change("query_server_config", "commit_freq", NewValue) ->
init({Mod, IdxState}) ->
- ok = config:subscribe_for_changes([{"query_server_config", "commit_freq"}]),
+ ok = config:subscribe_for_changes(?CONFIG_SUBSCRIPTION),
DbName = Mod:get(db_name, IdxState),
erlang:send_after(?CHECK_INTERVAL, self(), maybe_close),
Resp = couch_util:with_db(DbName, fun(Db) ->
@@ -347,7 +348,7 @@ handle_info({gen_event_EXIT, _Handler, _Reason}, State) ->
erlang:send_after(?RELISTEN_DELAY, self(), restart_config_listener),
{noreply, State};
handle_info(restart_config_listener, State) ->
- ok = config:subscribe_for_changes([{"query_server_config", "commit_freq"}]),
+ ok = config:subscribe_for_changes(?CONFIG_SUBSCRIPTION),
{noreply, State}.
code_change(_OldVsn, State, _Extra) ->