summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Newson <rnewson@users.noreply.github.com>2015-07-16 15:39:13 +0100
committerRobert Newson <rnewson@users.noreply.github.com>2015-07-16 15:39:13 +0100
commite3e1bfc4d0f2bd2a1fe25267b6b6b25540054402 (patch)
tree4c363ab6c2d0745f1afc4d5344991c1c7380c8c4
parente7e89bf9c58fb56e25ab2d13e8c9c37765d628ca (diff)
parentc3fe9357bc332ad0f8a9eb5f1f8e320c2189077c (diff)
downloadcouchdb-e3e1bfc4d0f2bd2a1fe25267b6b6b25540054402.tar.gz
Merge pull request #19 from cloudant/45855-dbnext
45855 dbnext
-rw-r--r--src/custodian/src/custodian.app.src2
-rw-r--r--src/custodian/src/custodian_db_checker.erl6
-rw-r--r--src/custodian/src/custodian_server.erl29
-rw-r--r--src/custodian/src/custodian_util.erl6
4 files changed, 21 insertions, 22 deletions
diff --git a/src/custodian/src/custodian.app.src b/src/custodian/src/custodian.app.src
index ff35a99c7..c5b4f6986 100644
--- a/src/custodian/src/custodian.app.src
+++ b/src/custodian/src/custodian.app.src
@@ -8,10 +8,10 @@
{applications, [
kernel,
stdlib,
+ couch_log,
config,
couch_event,
couch,
- twig,
mem3
]},
{mod, { custodian_app, []}},
diff --git a/src/custodian/src/custodian_db_checker.erl b/src/custodian/src/custodian_db_checker.erl
index 57487916b..5f1bbe7d5 100644
--- a/src/custodian/src/custodian_db_checker.erl
+++ b/src/custodian/src/custodian_db_checker.erl
@@ -63,7 +63,7 @@ handle_info({'EXIT', Pid, normal}, #st{checker=Pid}=St) ->
{noreply, St#st{checker=undefined}};
handle_info({'EXIT', Pid, Reason}, #st{checker=Pid}=St) ->
- twig:log(notice, "custodian db checker died ~p", [Reason]),
+ couch_log:notice("custodian db checker died ~p", [Reason]),
{noreply, restart_checker(St#st{checker=undefined})};
handle_info(Msg, St) ->
@@ -138,7 +138,7 @@ get_stats_db() ->
send_missing_db_alert(DbName) ->
- twig:log(notice, "Missing system database ~s", [DbName]),
+ couch_log:notice("Missing system database ~s", [DbName]),
Command = [
"send-sensu-event --standalone --critical",
" --output=\"Missing system database ",
@@ -147,7 +147,7 @@ send_missing_db_alert(DbName) ->
os:cmd(lists:concat(Command)).
clear_missing_dbs_alert() ->
- twig:log(notice, "All system databases exist.", []),
+ couch_log:notice("All system databases exist.", []),
Command = [
"send-sensu-event --standalone --ok",
" --output=\"All system databases exist\"",
diff --git a/src/custodian/src/custodian_server.erl b/src/custodian/src/custodian_server.erl
index b9dabe774..85095d12b 100644
--- a/src/custodian/src/custodian_server.erl
+++ b/src/custodian/src/custodian_server.erl
@@ -2,7 +2,7 @@
-module(custodian_server).
-behaviour(gen_server).
--vsn(1).
+-vsn(2).
-behaviour(config_listener).
% public api.
@@ -19,7 +19,7 @@
]).
% config_listener callback
--export([handle_config_change/5]).
+-export([handle_config_change/5, handle_config_terminate/3]).
% private records.
-record(state, {
@@ -35,12 +35,19 @@
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
-handle_config_change("cloudant", "maintenance_mode", _, _, S) ->
+handle_config_change("couchdb", "maintenance_mode", _, _, S) ->
ok = gen_server:cast(S, refresh),
{ok, S};
handle_config_change(_, _, _, _, S) ->
{ok, S}.
+handle_config_terminate(_, _, _) -> ok;
+handle_config_terminate(Self, _, _) ->
+ spawn(fun() ->
+ timer:sleep(5000),
+ config:listen_for_changes(?MODULE, Self)
+ end).
+
% gen_server functions.
init(_) ->
process_flag(trap_exit, true),
@@ -57,14 +64,6 @@ handle_call(_Msg, _From, State) ->
handle_cast(refresh, State) ->
{noreply, start_shard_checker(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, self()),
- {noreply, State};
-
handle_info({nodeup, _}, State) ->
{noreply, start_shard_checker(State)};
@@ -81,12 +80,12 @@ handle_info({'EXIT', Pid, normal}, #state{shard_checker=Pid}=State) ->
end;
handle_info({'EXIT', Pid, Reason}, #state{shard_checker=Pid}=State) ->
- twig:log(notice, "custodian shard checker died ~p", [Reason]),
+ couch_log:notice("custodian shard checker died ~p", [Reason]),
NewState = State#state{shard_checker=undefined},
{noreply, start_shard_checker(NewState)};
handle_info({'EXIT', Pid, Reason}, #state{event_listener=Pid}=State) ->
- twig:log(notice, "custodian update notifier died ~p", [Reason]),
+ couch_log:notice("custodian update notifier died ~p", [Reason]),
{ok, Pid1} = start_event_listener(),
{noreply, State#state{event_listener=Pid1}}.
@@ -132,10 +131,10 @@ send_sensu_event({_, Count} = Item) ->
0 ->
"--ok";
1 ->
- twig:log(crit, "~s", [describe(Item)]),
+ couch_log:critical("~s", [describe(Item)]),
"--critical";
_ ->
- twig:log(warn, "~s", [describe(Item)]),
+ couch_log:warning("~s", [describe(Item)]),
"--warning"
end,
Cmd = lists:concat([
diff --git a/src/custodian/src/custodian_util.erl b/src/custodian/src/custodian_util.erl
index 90f2cc2e3..0fe38c467 100644
--- a/src/custodian/src/custodian_util.erl
+++ b/src/custodian/src/custodian_util.erl
@@ -96,11 +96,11 @@ cluster_n() ->
list_to_integer(config:get("cluster", "n", "3")).
maintenance_nodes(Nodes) ->
- {Modes, _} = rpc:multicall(Nodes, config, get, ["cloudant", "maintenance_mode"]),
+ {Modes, _} = rpc:multicall(Nodes, config, get, ["couchdb", "maintenance_mode"]),
[N || {N, Mode} <- lists:zip(Nodes, Modes), Mode =:= "true"].
load_shards(Db, #full_doc_info{id = Id} = FDI) ->
- case couch_db:open_doc(Db, FDI, []) of
+ case couch_db:open_doc(Db, FDI, [ejson_body]) of
{ok, #doc{body = {Props}}} ->
mem3_util:build_shards(Id, Props);
{not_found, _} ->
@@ -125,7 +125,7 @@ count_conflicts(#full_doc_info{rev_tree = T}) ->
length(Leafs) - 1.
ensure_custodian_ddoc_exists(Db) ->
- case couch_db:open_doc(Db, ?CUSTODIAN_ID) of
+ case couch_db:open_doc(Db, ?CUSTODIAN_ID, [ejson_body]) of
{not_found, _Reason} ->
try couch_db:update_doc(Db, custodian_ddoc(), []) of
{ok, _} ->